stimeo-ui 0.1.0-beta.3 → 0.2.1

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 (174) hide show
  1. package/CHANGELOG.md +149 -0
  2. package/README.md +6 -6
  3. package/dist/controllers/accordion_controller.d.ts +3 -2
  4. package/dist/controllers/accordion_controller.js.map +1 -1
  5. package/dist/controllers/alert_dialog_controller.d.ts +64 -0
  6. package/dist/controllers/alert_dialog_controller.js +318 -0
  7. package/dist/controllers/alert_dialog_controller.js.map +1 -0
  8. package/dist/controllers/auto_submit_controller.js +56 -21
  9. package/dist/controllers/auto_submit_controller.js.map +1 -1
  10. package/dist/controllers/carousel_controller.d.ts +100 -0
  11. package/dist/controllers/carousel_controller.js +272 -0
  12. package/dist/controllers/carousel_controller.js.map +1 -0
  13. package/dist/controllers/character_counter_controller.js +52 -15
  14. package/dist/controllers/character_counter_controller.js.map +1 -1
  15. package/dist/controllers/clipboard_controller.d.ts +72 -0
  16. package/dist/controllers/clipboard_controller.js +144 -0
  17. package/dist/controllers/clipboard_controller.js.map +1 -0
  18. package/dist/controllers/collapsible_controller.d.ts +70 -0
  19. package/dist/controllers/collapsible_controller.js +327 -0
  20. package/dist/controllers/collapsible_controller.js.map +1 -0
  21. package/dist/controllers/color_picker_controller.d.ts +76 -0
  22. package/dist/controllers/color_picker_controller.js +213 -0
  23. package/dist/controllers/color_picker_controller.js.map +1 -0
  24. package/dist/controllers/combobox_controller.d.ts +6 -2
  25. package/dist/controllers/combobox_controller.js +64 -3
  26. package/dist/controllers/combobox_controller.js.map +1 -1
  27. package/dist/controllers/command_palette_controller.d.ts +13 -6
  28. package/dist/controllers/command_palette_controller.js +243 -39
  29. package/dist/controllers/command_palette_controller.js.map +1 -1
  30. package/dist/controllers/confirm_controller.js +94 -8
  31. package/dist/controllers/confirm_controller.js.map +1 -1
  32. package/dist/controllers/context_menu_controller.d.ts +11 -6
  33. package/dist/controllers/context_menu_controller.js +191 -13
  34. package/dist/controllers/context_menu_controller.js.map +1 -1
  35. package/dist/controllers/count_up_controller.js +8 -1
  36. package/dist/controllers/count_up_controller.js.map +1 -1
  37. package/dist/controllers/countdown_controller.d.ts +2 -2
  38. package/dist/controllers/countdown_controller.js +2 -2
  39. package/dist/controllers/countdown_controller.js.map +1 -1
  40. package/dist/controllers/currency_input_controller.d.ts +72 -0
  41. package/dist/controllers/currency_input_controller.js +147 -0
  42. package/dist/controllers/currency_input_controller.js.map +1 -0
  43. package/dist/controllers/data_grid_controller.d.ts +71 -0
  44. package/dist/controllers/data_grid_controller.js +168 -0
  45. package/dist/controllers/data_grid_controller.js.map +1 -0
  46. package/dist/controllers/date_range_picker_controller.d.ts +87 -0
  47. package/dist/controllers/date_range_picker_controller.js +417 -0
  48. package/dist/controllers/date_range_picker_controller.js.map +1 -0
  49. package/dist/controllers/dialog_controller.js +94 -8
  50. package/dist/controllers/dialog_controller.js.map +1 -1
  51. package/dist/controllers/dismissible_controller.d.ts +57 -0
  52. package/dist/controllers/dismissible_controller.js +117 -0
  53. package/dist/controllers/dismissible_controller.js.map +1 -0
  54. package/dist/controllers/drawer_controller.d.ts +96 -0
  55. package/dist/controllers/drawer_controller.js +630 -0
  56. package/dist/controllers/drawer_controller.js.map +1 -0
  57. package/dist/controllers/dropdown_controller.d.ts +9 -6
  58. package/dist/controllers/dropdown_controller.js +139 -16
  59. package/dist/controllers/dropdown_controller.js.map +1 -1
  60. package/dist/controllers/editable_controller.d.ts +73 -0
  61. package/dist/controllers/editable_controller.js +168 -0
  62. package/dist/controllers/editable_controller.js.map +1 -0
  63. package/dist/controllers/file_dropzone_controller.d.ts +92 -0
  64. package/dist/controllers/file_dropzone_controller.js +165 -0
  65. package/dist/controllers/file_dropzone_controller.js.map +1 -0
  66. package/dist/controllers/filter_controller.d.ts +60 -0
  67. package/dist/controllers/filter_controller.js +86 -0
  68. package/dist/controllers/filter_controller.js.map +1 -0
  69. package/dist/controllers/flash_controller.js +36 -5
  70. package/dist/controllers/flash_controller.js.map +1 -1
  71. package/dist/controllers/focus_controller.js +94 -8
  72. package/dist/controllers/focus_controller.js.map +1 -1
  73. package/dist/controllers/form_validation_controller.js +2 -2
  74. package/dist/controllers/form_validation_controller.js.map +1 -1
  75. package/dist/controllers/highlight_controller.js +6 -4
  76. package/dist/controllers/highlight_controller.js.map +1 -1
  77. package/dist/controllers/hover_card_controller.d.ts +15 -12
  78. package/dist/controllers/hover_card_controller.js +103 -27
  79. package/dist/controllers/hover_card_controller.js.map +1 -1
  80. package/dist/controllers/intersection_controller.js +41 -18
  81. package/dist/controllers/intersection_controller.js.map +1 -1
  82. package/dist/controllers/lazy_frame_controller.js +33 -11
  83. package/dist/controllers/lazy_frame_controller.js.map +1 -1
  84. package/dist/controllers/listbox_controller.js +1 -0
  85. package/dist/controllers/listbox_controller.js.map +1 -1
  86. package/dist/controllers/masonry_controller.d.ts +54 -0
  87. package/dist/controllers/masonry_controller.js +142 -0
  88. package/dist/controllers/masonry_controller.js.map +1 -0
  89. package/dist/controllers/menu_controller.d.ts +18 -11
  90. package/dist/controllers/menu_controller.js +181 -8
  91. package/dist/controllers/menu_controller.js.map +1 -1
  92. package/dist/controllers/menubar_controller.d.ts +62 -0
  93. package/dist/controllers/menubar_controller.js +433 -0
  94. package/dist/controllers/menubar_controller.js.map +1 -0
  95. package/dist/controllers/multi_select_controller.d.ts +115 -0
  96. package/dist/controllers/multi_select_controller.js +472 -0
  97. package/dist/controllers/multi_select_controller.js.map +1 -0
  98. package/dist/controllers/navigation_menu_controller.d.ts +99 -0
  99. package/dist/controllers/navigation_menu_controller.js +384 -0
  100. package/dist/controllers/navigation_menu_controller.js.map +1 -0
  101. package/dist/controllers/otp_controller.js +62 -22
  102. package/dist/controllers/otp_controller.js.map +1 -1
  103. package/dist/controllers/overflow_indicator_controller.d.ts +12 -4
  104. package/dist/controllers/overflow_indicator_controller.js +178 -27
  105. package/dist/controllers/overflow_indicator_controller.js.map +1 -1
  106. package/dist/controllers/overflow_menu_controller.d.ts +3 -2
  107. package/dist/controllers/overflow_menu_controller.js.map +1 -1
  108. package/dist/controllers/password_reveal_controller.d.ts +49 -0
  109. package/dist/controllers/password_reveal_controller.js +117 -0
  110. package/dist/controllers/password_reveal_controller.js.map +1 -0
  111. package/dist/controllers/pointer_drag_controller.js +3 -3
  112. package/dist/controllers/pointer_drag_controller.js.map +1 -1
  113. package/dist/controllers/popover_controller.d.ts +18 -10
  114. package/dist/controllers/popover_controller.js +118 -27
  115. package/dist/controllers/popover_controller.js.map +1 -1
  116. package/dist/controllers/range_slider_controller.d.ts +87 -0
  117. package/dist/controllers/range_slider_controller.js +166 -0
  118. package/dist/controllers/range_slider_controller.js.map +1 -0
  119. package/dist/controllers/read_more_controller.d.ts +52 -0
  120. package/dist/controllers/read_more_controller.js +194 -0
  121. package/dist/controllers/read_more_controller.js.map +1 -0
  122. package/dist/controllers/scroll_area_controller.js +15 -2
  123. package/dist/controllers/scroll_area_controller.js.map +1 -1
  124. package/dist/controllers/scroll_restore_controller.d.ts +54 -0
  125. package/dist/controllers/scroll_restore_controller.js +93 -0
  126. package/dist/controllers/scroll_restore_controller.js.map +1 -0
  127. package/dist/controllers/scroll_visibility_controller.js +8 -4
  128. package/dist/controllers/scroll_visibility_controller.js.map +1 -1
  129. package/dist/controllers/scrollspy_controller.js +33 -11
  130. package/dist/controllers/scrollspy_controller.js.map +1 -1
  131. package/dist/controllers/separator_controller.d.ts +54 -0
  132. package/dist/controllers/separator_controller.js +87 -0
  133. package/dist/controllers/separator_controller.js.map +1 -0
  134. package/dist/controllers/sidebar_controller.d.ts +107 -0
  135. package/dist/controllers/sidebar_controller.js +761 -0
  136. package/dist/controllers/sidebar_controller.js.map +1 -0
  137. package/dist/controllers/stepper_controller.d.ts +4 -0
  138. package/dist/controllers/stepper_controller.js +28 -12
  139. package/dist/controllers/stepper_controller.js.map +1 -1
  140. package/dist/controllers/stick_to_bottom_controller.js +8 -4
  141. package/dist/controllers/stick_to_bottom_controller.js.map +1 -1
  142. package/dist/controllers/sticky_observer_controller.d.ts +17 -4
  143. package/dist/controllers/sticky_observer_controller.js +88 -20
  144. package/dist/controllers/sticky_observer_controller.js.map +1 -1
  145. package/dist/controllers/tabs_controller.d.ts +3 -3
  146. package/dist/controllers/tabs_controller.js.map +1 -1
  147. package/dist/controllers/tags_input_controller.d.ts +91 -0
  148. package/dist/controllers/tags_input_controller.js +275 -0
  149. package/dist/controllers/tags_input_controller.js.map +1 -0
  150. package/dist/controllers/theme_controller.js +20 -10
  151. package/dist/controllers/theme_controller.js.map +1 -1
  152. package/dist/controllers/time_picker_controller.d.ts +67 -0
  153. package/dist/controllers/time_picker_controller.js +212 -0
  154. package/dist/controllers/time_picker_controller.js.map +1 -0
  155. package/dist/controllers/toast_controller.d.ts +8 -18
  156. package/dist/controllers/toast_controller.js +144 -38
  157. package/dist/controllers/toast_controller.js.map +1 -1
  158. package/dist/controllers/tooltip_controller.d.ts +15 -18
  159. package/dist/controllers/tooltip_controller.js +148 -42
  160. package/dist/controllers/tooltip_controller.js.map +1 -1
  161. package/dist/controllers/transition_controller.d.ts +14 -8
  162. package/dist/controllers/transition_controller.js +153 -38
  163. package/dist/controllers/transition_controller.js.map +1 -1
  164. package/dist/controllers/tree_view_controller.d.ts +54 -0
  165. package/dist/controllers/tree_view_controller.js +275 -0
  166. package/dist/controllers/tree_view_controller.js.map +1 -0
  167. package/dist/index.d.ts +27 -1788
  168. package/dist/index.js +1644 -643
  169. package/dist/index.js.map +1 -1
  170. package/dist/inspector/cli.js.map +1 -1
  171. package/dist/inspector/cli_bin.js.map +1 -1
  172. package/dist/inspector/examples.json +8 -8
  173. package/dist/inspector/manifest.json +30 -5
  174. package/package.json +7 -7
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/escape_layer.ts","../../src/utils/focus_trap.ts","../../src/controllers/alert_dialog_controller.ts"],"names":[],"mappings":";;;;;AAuEO,IAAM,WAAA,GAAN,MAAM,YAAA,CAAY;AAAA,EACvB,OAAg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IAAmB,CAAC,IAAA,CAAK,YAAA,CAAa,MAAA;AAAA,EACpD;AACF","file":"alert_dialog_controller.js","sourcesContent":["/**\n * Single resolver for layered Escape dismissal.\n *\n * Every Escape-dismissable overlay layer (modal focus traps, disclosure\n * overlays like dropdown/popover/menu, and hover-triggered transient layers)\n * registers here while it is open. One document-level listener per document\n * resolves each press to exactly one owner and invokes that layer's\n * {@link EscapeLayerOptions.onDismiss} — controllers never listen for a\n * dismissing Escape themselves.\n *\n * @remarks\n * Each document owns an activation-ordered stack. The owner of a press is the\n * **topmost layer whose {@link EscapeLayerOptions.claims} passes**; a layer\n * that declines is transparent, so a background overlay opened behind a modal\n * never blocks it. Because a layer opened from within another is necessarily\n * activated later, LIFO order is also inner-first for nested layers — no DOM\n * inspection is needed.\n *\n * The shared listener runs in the document bubble phase and honors\n * `event.defaultPrevented`, so an element-level widget handler that consumes\n * Escape first (an editor cancelling its edit, a combobox closing its list)\n * always wins over every registered layer — the deepest-first half of the\n * shared layered-Escape contract. A keydown that is part of an IME composition\n * (`event.isComposing`) cancels the composition, never a layer, and is ignored\n * here for every layer at once.\n *\n * A WeakMap keeps documents collectible; the listener is installed only while\n * a document's stack is non-empty, and controller lifecycle hooks guarantee\n * that disconnected layers never remain registered.\n */\n\n/** Behavior a layer registers when it activates. */\nexport interface EscapeLayerOptions {\n /**\n * Dismisses the layer. Called by the shared resolver when this layer owns a\n * press; the resolver has already consumed the event (`preventDefault()`),\n * so the callback only needs to close and place focus per the widget's\n * contract.\n */\n onDismiss: () => void;\n /**\n * Whether the layer claims the current press. Evaluated per press, so it can\n * depend on live state (e.g. \"focus is inside me or fell to the body\"). A\n * declining layer is skipped and the next layer down is consulted; omitting\n * it means the layer always claims while active.\n */\n claims?: () => boolean;\n}\n\n/** A document's stack plus the one shared listener bound to it. */\ninterface EscapeLayerRegistry {\n stack: EscapeLayer[];\n onKeydown: (event: KeyboardEvent) => void;\n}\n\n/**\n * Claims predicate shared by the click-opened disclosure overlays (dropdown /\n * popover / navigation-menu / menu / context-menu / menubar): the layer claims\n * a press while focus is inside `element`, or after focus fell to the body —\n * a click on non-focusable overlay content blurs to `<body>`, and Escape must\n * still close the overlay (the \"body-focus rescue\"). A press made after focus\n * moved to another interactive element is declined, so closing never yanks\n * focus away from where the user deliberately went.\n */\nexport function claimsWhileFocusWithin(element: Element): () => boolean {\n return () => {\n const active = element.ownerDocument.activeElement;\n return active === null || active === element.ownerDocument.body || element.contains(active);\n };\n}\n\nexport class EscapeLayer {\n static readonly #registries = new WeakMap<Document, EscapeLayerRegistry>();\n\n #ownerDocument: Document | null = null;\n /** Dismissal callback while active; `null` when inactive. */\n #onDismiss: (() => void) | null = null;\n /** Live predicate deciding whether the layer claims a press; `null` = always. */\n #claims: (() => boolean) | null = null;\n\n /**\n * Activates this layer at the top of its document's Escape stack, installing\n * the document's shared resolver listener if this is its first layer.\n * Re-activating an already-active layer moves it to the top.\n */\n activate(ownerDocument: Document = document, options: EscapeLayerOptions): void {\n this.deactivate();\n let registry = EscapeLayer.#registries.get(ownerDocument);\n if (!registry) {\n registry = EscapeLayer.#createRegistry();\n EscapeLayer.#registries.set(ownerDocument, registry);\n ownerDocument.addEventListener(\"keydown\", registry.onKeydown);\n }\n registry.stack.push(this);\n this.#ownerDocument = ownerDocument;\n this.#onDismiss = options.onDismiss;\n this.#claims = options.claims ?? null;\n }\n\n /**\n * Removes this layer from its document's Escape stack, uninstalling the\n * shared listener when the stack empties. Safe to call when inactive.\n */\n deactivate(): void {\n const ownerDocument = this.#ownerDocument;\n if (!ownerDocument) return;\n\n const registry = EscapeLayer.#registries.get(ownerDocument);\n if (registry) {\n const index = registry.stack.lastIndexOf(this);\n if (index >= 0) registry.stack.splice(index, 1);\n if (registry.stack.length === 0) {\n ownerDocument.removeEventListener(\"keydown\", registry.onKeydown);\n EscapeLayer.#registries.delete(ownerDocument);\n }\n }\n this.#ownerDocument = null;\n this.#onDismiss = null;\n this.#claims = null;\n }\n\n /**\n * Whether this active layer would own a press right now: it is the topmost\n * layer whose {@link EscapeLayerOptions.claims} passes. Exposed for tests\n * and diagnostics — production dismissal goes through the shared listener.\n */\n get ownsEscape(): boolean {\n const ownerDocument = this.#ownerDocument;\n if (!ownerDocument) return false;\n const registry = EscapeLayer.#registries.get(ownerDocument);\n if (!registry) return false;\n return EscapeLayer.#resolveOwner(registry.stack) === this;\n }\n\n /** Builds a document's registry with its shared resolver listener. */\n static #createRegistry(): EscapeLayerRegistry {\n const registry: EscapeLayerRegistry = {\n stack: [],\n onKeydown: (event: KeyboardEvent): void => {\n if (event.key !== \"Escape\" || event.defaultPrevented || event.isComposing) return;\n const owner = EscapeLayer.#resolveOwner(registry.stack);\n if (!owner) return;\n event.preventDefault();\n owner.#onDismiss?.();\n },\n };\n return registry;\n }\n\n /** The topmost stack layer whose claims predicate passes, or `null`. */\n static #resolveOwner(stack: EscapeLayer[]): EscapeLayer | null {\n for (let index = stack.length - 1; index >= 0; index--) {\n const layer = stack[index];\n if (!layer) continue;\n if (layer.#claims && !layer.#claims()) continue;\n return layer;\n }\n return null;\n }\n}\n","import { EscapeLayer } from \"./escape_layer\";\n\n/**\n * Modal focus-trap primitive shared by the modal-overlay controllers\n * (dialog / alert-dialog / confirm / drawer / command-palette / sidebar); the\n * non-modal focus scope (focus) reuses it with the modal side effects opted out.\n *\n * The WAI-ARIA APG modal pattern is more than \"cycle Tab inside a box\": a modal\n * also locks background scroll, makes the rest of the page `inert` (so assistive\n * technology and pointer/Tab cannot reach it, honoring `aria-modal=\"true\"`),\n * sends focus inside on open, and restores it to the opener on close — and every\n * one of those side effects must be reverted if the element is torn down while\n * open (a Turbo navigation mid-dialog) and kept out of the snapshot Turbo\n * caches (`turbo:before-cache`). {@link FocusTrap} owns that whole modal\n * lifecycle so each controller only decides *when* to open/close and *what*\n * \"close\" means.\n *\n * It is intentionally **policy-free about closing**. Escape semantics differ per\n * widget (a plain dialog just closes; an alert-dialog closes *as a cancel* with a\n * reason; a drawer runs an exit transition), so the trap merely forwards Escape\n * to an {@link FocusTrapOptions.onEscape | onEscape} callback and never decides on\n * its own what closing entails.\n *\n * @remarks\n * The container is read through a getter so a controller can hand over a Stimulus\n * target without worrying about when the trap instance is constructed relative to\n * `connect()`.\n */\n\n/**\n * Selector matching the elements considered focusable. Shared by the trap's Tab\n * cycling and by form-validation's invalid-focus delegation.\n */\nexport const FOCUSABLE =\n 'a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\n\n/** Behavior hooks a controller supplies when constructing a {@link FocusTrap}. */\nexport interface FocusTrapOptions {\n /**\n * Called when `Escape` is pressed while the trap is active. When omitted,\n * `Escape` is left alone (the trap never joins the Escape stack). Dismissal\n * is resolved by the shared {@link EscapeLayer}: an Escape already consumed\n * by an inner handler is ignored, and among active layers the most recently\n * activated claiming one owns the press. The resolver consumes the event\n * before invoking the callback (the shared layered-Escape contract).\n */\n onEscape?: () => void;\n /**\n * Returns the element to focus when the trap activates. When it returns `null`\n * (or is omitted), the first focusable descendant is used, falling back to the\n * container itself (made programmatically focusable with `tabindex=-1`).\n */\n initialFocus?: () => HTMLElement | null;\n /**\n * Returns the element to focus on deactivation when nothing was focused before\n * the trap opened (e.g. the trigger). The element focused *before* opening\n * always takes precedence.\n */\n fallbackFocus?: () => HTMLElement | null;\n /**\n * Lock background scroll (`body` overflow) while active. Defaults to `true` for\n * the modal overlays; a lighter focus scope passes `false`. Read on `activate`.\n */\n lockScroll?: boolean | (() => boolean);\n /**\n * Make background siblings `inert` while active (the `aria-modal` isolation).\n * Defaults to `true` for the modal overlays; a soft focus scope can opt out so\n * the background stays reachable while `Tab` still cycles inside. Read on `activate`.\n */\n isolate?: boolean | (() => boolean);\n /**\n * Move focus inside on `activate`. Defaults to `true`; a focus scope that only\n * wants the `Tab` boundary (no focus move) passes `false`. Read on `activate`.\n */\n autoFocus?: boolean | (() => boolean);\n}\n\n/**\n * Owns the modal side effects (scroll lock, background `inert`, focus trap, focus\n * restore) for a single container, applied on {@link activate} and reverted on\n * {@link deactivate}.\n */\nexport class FocusTrap {\n /** The element focused before activation, restored on deactivation. */\n #previouslyFocused: HTMLElement | null = null;\n /** The body's inline `overflow` before locking, restored on deactivation. */\n #previousBodyOverflow = \"\";\n /** Whether scroll was locked this activation (so it is only restored if applied). */\n #scrollLocked = false;\n /** Background siblings made `inert` while active, restored on deactivation. */\n #inertedSiblings: HTMLElement[] = [];\n /** Whether the modal side effects are currently applied. */\n #activeState = false;\n /** Registers the trap on the shared Escape stack while active (see {@link EscapeLayer}). */\n readonly #escapeLayer = new EscapeLayer();\n\n /** Returns the trapped element; called on every operation for the live target. */\n readonly #getContainer: () => HTMLElement;\n /** Closing/focus hooks; see {@link FocusTrapOptions}. */\n readonly #options: FocusTrapOptions;\n\n /**\n * @param getContainer - Returns the trapped element. Called on every operation\n * so the live target is always used.\n * @param options - Closing/focus hooks; see {@link FocusTrapOptions}.\n */\n constructor(getContainer: () => HTMLElement, options: FocusTrapOptions = {}) {\n this.#getContainer = getContainer;\n this.#options = options;\n }\n\n /** Whether the trap is currently active. */\n get active(): boolean {\n return this.#activeState;\n }\n\n /**\n * Applies the trap: records the current focus, optionally locks background scroll\n * and makes background siblings `inert`, listens for `Tab`/`Escape`, and (unless\n * `autoFocus` is off) moves focus inside. No-ops if already active.\n */\n activate(): void {\n if (this.#activeState) return;\n this.#activeState = true;\n // Record the opener so it can be refocused on close. `<body>` (the default\n // active element when nothing is focused) is treated as \"nothing\", so the\n // fallback target — typically the trigger — wins in that case.\n const active = document.activeElement;\n this.#previouslyFocused =\n active instanceof HTMLElement && active !== document.body ? active : null;\n if (this.#flag(this.#options.lockScroll, true)) {\n this.#previousBodyOverflow = document.body.style.overflow;\n document.body.style.overflow = \"hidden\";\n this.#scrollLocked = true;\n }\n if (this.#flag(this.#options.isolate, true)) this.#isolateBackground();\n document.addEventListener(\"keydown\", this.#onKeydown);\n document.addEventListener(\"turbo:before-cache\", this.#onBeforeCache);\n const onEscape = this.#options.onEscape;\n if (onEscape) this.#escapeLayer.activate(document, { onDismiss: () => onEscape() });\n if (this.#flag(this.#options.autoFocus, true)) this.#focusInitial();\n }\n\n /**\n * Reverts every side effect applied by {@link activate}. No-ops if inactive, so\n * a controller can call it defensively from both `close()` and `disconnect()`.\n *\n * @param restoreFocus - Move focus back to the opener (default `true`). Pass\n * `false` on teardown (`disconnect`), where yanking focus is undesirable.\n */\n deactivate({ restoreFocus = true }: { restoreFocus?: boolean } = {}): void {\n if (!this.#activeState) return;\n this.#activeState = false;\n this.#escapeLayer.deactivate();\n document.removeEventListener(\"keydown\", this.#onKeydown);\n document.removeEventListener(\"turbo:before-cache\", this.#onBeforeCache);\n if (this.#scrollLocked) {\n document.body.style.overflow = this.#previousBodyOverflow;\n this.#scrollLocked = false;\n }\n this.#releaseBackground();\n if (restoreFocus) {\n const target = this.#previouslyFocused ?? this.#options.fallbackFocus?.() ?? null;\n target?.focus();\n }\n }\n\n /** Resolves a boolean-or-getter option, defaulting when it was not provided. */\n #flag(option: boolean | (() => boolean) | undefined, fallback: boolean): boolean {\n if (option === undefined) return fallback;\n return typeof option === \"function\" ? option() : option;\n }\n\n /**\n * Reverts the side effects just before Turbo caches the page snapshot, so an\n * overlay left open does not bake the scroll lock into `body[style]` — a\n * restored page would feed that locked value back into {@link activate} as the\n * baseline, and closing would then never unlock the page. Markup state stays\n * untouched (restore-open designs reopen against a clean baseline), and focus\n * is left alone mid-navigation. The listener lives only while active.\n */\n readonly #onBeforeCache = (): void => {\n this.deactivate({ restoreFocus: false });\n };\n\n /**\n * Handles `Tab` (focus trap) while active. `Escape` dismissal is owned by the\n * shared {@link EscapeLayer} resolver, so Tab trapping stays independent of\n * which layer currently owns Escape.\n */\n readonly #onKeydown = (event: KeyboardEvent): void => {\n if (event.key === \"Tab\") this.#trapTab(event);\n };\n\n /** Keeps `Tab` focus cycling within the container's focusable elements. */\n #trapTab(event: KeyboardEvent): void {\n const focusable = this.#focusableElements();\n if (focusable.length === 0) {\n event.preventDefault();\n return;\n }\n const first = focusable[0];\n const last = focusable[focusable.length - 1];\n const active = document.activeElement;\n\n // If focus has somehow escaped the container, pull it back to the first item.\n if (!(active instanceof Node) || !this.#getContainer().contains(active)) {\n event.preventDefault();\n first?.focus();\n return;\n }\n\n if (event.shiftKey && active === first) {\n event.preventDefault();\n last?.focus();\n } else if (!event.shiftKey && active === last) {\n event.preventDefault();\n first?.focus();\n }\n }\n\n /**\n * Marks every element outside the container's subtree as `inert` so background\n * content cannot be focused or reached by assistive technology, honoring the\n * `aria-modal=\"true\"` contract. An element that was *already* `inert` is left\n * untracked so `#releaseBackground` does not wrongly clear it.\n */\n #isolateBackground(): void {\n const container = this.#getContainer();\n this.#inertedSiblings = [];\n for (const sibling of Array.from(document.body.children)) {\n if (!(sibling instanceof HTMLElement)) continue;\n if (sibling.contains(container) || sibling.inert) continue;\n sibling.inert = true;\n this.#inertedSiblings.push(sibling);\n }\n }\n\n /** Reverts the `inert` flags applied by `#isolateBackground`. */\n #releaseBackground(): void {\n for (const sibling of this.#inertedSiblings) {\n sibling.inert = false;\n }\n this.#inertedSiblings = [];\n }\n\n /** Moves focus to the initial target, the first focusable, or the container. */\n #focusInitial(): void {\n const preferred = this.#options.initialFocus?.();\n if (preferred) {\n preferred.focus();\n return;\n }\n const focusable = this.#focusableElements();\n if (focusable[0]) {\n focusable[0].focus();\n return;\n }\n const container = this.#getContainer();\n container.tabIndex = -1;\n container.focus();\n }\n\n /** Collects the container's currently focusable descendants in DOM order. */\n #focusableElements(): HTMLElement[] {\n return Array.from(this.#getContainer().querySelectorAll<HTMLElement>(FOCUSABLE)).filter(\n (el) => !el.hidden,\n );\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { FocusTrap } from \"../utils/focus_trap\";\n\n/** Reason carried by the `cancel` event: an explicit cancel vs. the Escape key. */\ntype CancelReason = \"user\" | \"escape\";\n\n/**\n * Headless, accessible **alert dialog** behavior.\n *\n * Markup contract (identifier: `stimeo--alert-dialog`):\n * <div data-controller=\"stimeo--alert-dialog\">\n * <button data-stimeo--alert-dialog-target=\"trigger\"\n * data-action=\"click->stimeo--alert-dialog#open\">Delete…</button>\n * <div data-stimeo--alert-dialog-target=\"dialog\" role=\"alertdialog\"\n * aria-modal=\"true\" aria-labelledby=\"t\" aria-describedby=\"d\" hidden>\n * <h2 id=\"t\">…</h2><p id=\"d\">…</p>\n * <button data-stimeo--alert-dialog-target=\"initialFocus\"\n * data-action=\"click->stimeo--alert-dialog#cancel\">Cancel</button>\n * <button data-action=\"click->stimeo--alert-dialog#confirm\">Delete</button>\n * </div>\n * </div>\n *\n * Implements the WAI-ARIA APG **Alert Dialog** pattern. It is the same modal as\n * `stimeo--dialog` with two deliberate differences that suit an *interrupting\n * confirmation*: it never closes on a backdrop click (an accidental dismissal\n * would be dangerous), and it exposes explicit {@link confirm}/{@link cancel}\n * actions that emit events so the consumer only writes the message and \"what to\n * do on confirm\".\n *\n * @remarks\n * Behavior only. The modal lifecycle (focus trap, scroll lock, background\n * `inert`, focus restore, teardown reversal) is delegated to the shared\n * {@link FocusTrap}. The only closing affordances are the confirm/cancel actions\n * and `Escape` (which cancels) — there is intentionally no backdrop close.\n *\n * Behavior provided:\n * - {@link open} shows the dialog and moves focus to the `initialFocus` target\n * (the least destructive action, by convention), else the first focusable\n * element.\n * - `Tab`/`Shift+Tab` cycle focus within the dialog (focus trap).\n * - {@link confirm} closes and dispatches `stimeo--alert-dialog:confirm`.\n * - {@link cancel} and `Escape` close and dispatch `stimeo--alert-dialog:cancel`\n * with a `reason` of `\"user\"` / `\"escape\"`. Focus returns to the opener.\n */\nexport class AlertDialogController extends Controller<HTMLElement> {\n static override targets = [\"trigger\", \"dialog\", \"initialFocus\"];\n static actions = [\"cancel\", \"confirm\", \"open\"] as const;\n static events = [\"cancel\", \"confirm\"] as const;\n\n declare readonly triggerTarget: HTMLElement;\n declare readonly dialogTarget: HTMLElement;\n declare readonly initialFocusTarget: HTMLElement;\n declare readonly hasTriggerTarget: boolean;\n declare readonly hasDialogTarget: boolean;\n declare readonly hasInitialFocusTarget: boolean;\n\n /**\n * Owns the modal side effects. Escape is routed through {@link cancel} so it\n * emits the same event as the cancel button (tagged `\"escape\"`); focus falls\n * back to the trigger when nothing was focused before opening.\n */\n readonly #trap = new FocusTrap(() => this.dialogTarget, {\n onEscape: () => this.#requestCancel(\"escape\"),\n initialFocus: () => (this.hasInitialFocusTarget ? this.initialFocusTarget : null),\n fallbackFocus: () => (this.hasTriggerTarget ? this.triggerTarget : null),\n });\n\n /** Starts closed (idempotently reflects the closed state on the markup). */\n override connect(): void {\n if (this.hasDialogTarget) this.dialogTarget.hidden = true;\n }\n\n /** Reverts the modal side effects if torn down while open (Turbo navigation). */\n override disconnect(): void {\n this.#trap.deactivate({ restoreFocus: false });\n }\n\n /** Opens the dialog, traps focus, and locks background scroll. */\n open(): void {\n if (!this.hasDialogTarget || this.#isOpen) return;\n this.dialogTarget.hidden = false;\n this.#trap.activate();\n }\n\n /** Confirms: closes and dispatches `confirm`. Bound via `data-action`. */\n confirm(): void {\n if (!this.#isOpen) return;\n this.dispatch(\"confirm\");\n this.#closeDialog();\n }\n\n /** Cancels (user action): closes and dispatches `cancel` with `reason: \"user\"`. */\n cancel(): void {\n this.#requestCancel(\"user\");\n }\n\n /** Shared cancel path used by both the cancel action and the Escape key. */\n #requestCancel(reason: CancelReason): void {\n if (!this.#isOpen) return;\n this.dispatch(\"cancel\", { detail: { reason } });\n this.#closeDialog();\n }\n\n /** Hides the dialog and reverts the modal side effects (restoring focus). */\n #closeDialog(): void {\n this.dialogTarget.hidden = true;\n this.#trap.deactivate();\n }\n\n /** Whether the dialog is currently visible. */\n get #isOpen(): boolean {\n return this.hasDialogTarget && !this.dialogTarget.hidden;\n }\n}\n"]}
@@ -2,6 +2,53 @@ import { Controller } from '@hotwired/stimulus';
2
2
 
3
3
  // src/controllers/auto_submit_controller.ts
4
4
 
5
+ // src/utils/composition_tracker.ts
6
+ var CompositionTracker = class {
7
+ #observedTargets = /* @__PURE__ */ new Set();
8
+ #activeTargets = /* @__PURE__ */ new Set();
9
+ #onStart;
10
+ #onEnd;
11
+ constructor(options = {}) {
12
+ this.#onStart = options.onStart;
13
+ this.#onEnd = options.onEnd;
14
+ }
15
+ /** Starts lifecycle tracking for `target`; repeated calls are idempotent. */
16
+ observe(target) {
17
+ if (this.#observedTargets.has(target)) return;
18
+ target.addEventListener("compositionstart", this.#handleStart);
19
+ target.addEventListener("compositionend", this.#handleEnd);
20
+ this.#observedTargets.add(target);
21
+ }
22
+ /** Stops tracking one target and clears any active composition it owned. */
23
+ unobserve(target) {
24
+ if (!this.#observedTargets.delete(target)) return;
25
+ target.removeEventListener("compositionstart", this.#handleStart);
26
+ target.removeEventListener("compositionend", this.#handleEnd);
27
+ this.#activeTargets.delete(target);
28
+ }
29
+ /** Releases every listener and clears state so reconnect starts cleanly. */
30
+ disconnect() {
31
+ for (const target of this.#observedTargets) {
32
+ target.removeEventListener("compositionstart", this.#handleStart);
33
+ target.removeEventListener("compositionend", this.#handleEnd);
34
+ }
35
+ this.#observedTargets.clear();
36
+ this.#activeTargets.clear();
37
+ }
38
+ /** True when lifecycle tracking or the current event reports composition. */
39
+ isComposing(event) {
40
+ return this.#activeTargets.size > 0 || event?.isComposing === true;
41
+ }
42
+ #handleStart = (event) => {
43
+ if (event.currentTarget) this.#activeTargets.add(event.currentTarget);
44
+ this.#onStart?.(event);
45
+ };
46
+ #handleEnd = (event) => {
47
+ if (event.currentTarget) this.#activeTargets.delete(event.currentTarget);
48
+ this.#onEnd?.(event);
49
+ };
50
+ };
51
+
5
52
  // src/utils/safe_timeout.ts
6
53
  var TimerRegistry = class {
7
54
  /** Live timer ids that have not yet been cleared (or, for timeouts, fired). */
@@ -79,34 +126,22 @@ var AutoSubmitController = class extends Controller {
79
126
  window.dispatchEvent(new CustomEvent("stimeo--announcer:announce", { detail: { message } }));
80
127
  }
81
128
  };
82
- /** True while an IME composition is in progress on one of the form's fields. */
83
- #composing = false;
84
- /** Marks composition active so `input` events mid-conversion don't submit. */
85
- #onCompositionStart = () => {
86
- this.#composing = true;
87
- };
88
- /**
89
- * Composition finished (the IME conversion is confirmed): clear the flag and
90
- * schedule a submit as if `input` fired, so the settled text triggers a submit
91
- * even on browsers whose post-composition `input` still reads `isComposing`.
92
- */
93
- #onCompositionEnd = (event) => {
94
- this.#composing = false;
95
- if (this.#triggers("input")) this.#schedule(event.target ?? null);
96
- };
129
+ /** Owns delegated IME lifecycle state and submits confirmed input text. */
130
+ #composition = new CompositionTracker({
131
+ onEnd: (event) => {
132
+ if (this.#triggers("input")) this.#schedule(event.target ?? null);
133
+ }
134
+ });
97
135
  connect() {
98
136
  this.#form.addEventListener("turbo:submit-end", this.#onSubmitEnd);
99
- this.#form.addEventListener("compositionstart", this.#onCompositionStart);
100
- this.#form.addEventListener("compositionend", this.#onCompositionEnd);
137
+ this.#composition.observe(this.#form);
101
138
  }
102
139
  disconnect() {
103
140
  this.#timers.clearAll();
104
141
  this.#pendingId = 0;
105
- this.#composing = false;
142
+ this.#composition.disconnect();
106
143
  this.#form.removeAttribute("data-auto-submit-pending");
107
144
  this.#form.removeEventListener("turbo:submit-end", this.#onSubmitEnd);
108
- this.#form.removeEventListener("compositionstart", this.#onCompositionStart);
109
- this.#form.removeEventListener("compositionend", this.#onCompositionEnd);
110
145
  }
111
146
  /**
112
147
  * Schedules a debounced submit. Wired to `input`/`change`; the `on` value is an
@@ -115,7 +150,7 @@ var AutoSubmitController = class extends Controller {
115
150
  */
116
151
  submit(event) {
117
152
  if (!this.#triggers(event.type)) return;
118
- if (event.type === "input" && (this.#composing || event.isComposing)) return;
153
+ if (event.type === "input" && this.#composition.isComposing(event)) return;
119
154
  this.#schedule(event.target ?? null);
120
155
  }
121
156
  /** Schedules (and coalesces) the debounced submit for the given trigger. */
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/safe_timeout.ts","../../src/controllers/auto_submit_controller.ts"],"names":[],"mappings":";;;;;AAwBA,IAAe,gBAAf,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AAM,MAAA,IAAiC,IAAI,CAAA;AAAA,EAC7D;AAAA;AAAA,EAGA,UAAU,OAAA,EAAmC;AAC3C,IAAA,IAAA,CAAK,KAAA,CAAM,YAAA,CAAa,0BAAA,EAA4B,MAAM,CAAA;AAC1D,IAAA,IAAI,KAAK,UAAA,EAAY,IAAA,CAAK,OAAA,CAAQ,KAAA,CAAM,KAAK,UAAU,CAAA;AAEvD,IAAA,IAAA,CAAK,UAAA,GAAa,IAAA,CAAK,OAAA,CAAQ,GAAA,CAAI,MAAM;AACvC,MAAA,IAAA,CAAK,UAAA,GAAa,CAAA;AAClB,MAAA,IAAA,CAAK,KAAA,CAAM,gBAAgB,0BAA0B,CAAA;AACrD,MAAA,IAAA,CAAK,SAAS,QAAA,EAAU,EAAE,QAAQ,EAAE,OAAA,IAAW,CAAA;AAO/C,MAAA,IAAI,IAAA,CAAK,KAAA,CAAM,aAAA,EAAc,EAAG;AAC9B,QAAA,IAAA,CAAK,KAAA,CAAM,YAAA,CAAa,WAAA,EAAa,MAAM,CAAA;AAAA,MAC7C;AACA,MAAA,IAAA,CAAK,MAAM,aAAA,EAAc;AAAA,IAC3B,CAAA,EAAG,KAAK,aAAa,CAAA;AAAA,EACvB;AAAA;AAAA,EAGA,IAAI,KAAA,GAAyB;AAC3B,IAAA,OAAO,IAAA,CAAK,aAAA,GAAgB,IAAA,CAAK,UAAA,GAAc,IAAA,CAAK,OAAA;AAAA,EACtD;AAAA;AAAA,EAGA,UAAU,IAAA,EAAuB;AAC/B,IAAA,OAAO,IAAA,CAAK,QAAQ,KAAA,CAAM,KAAK,EAAE,MAAA,CAAO,OAAO,CAAA,CAAE,QAAA,CAAS,IAAI,CAAA;AAAA,EAChE;AACF","file":"auto_submit_controller.js","sourcesContent":["/**\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 { SafeTimeout } from \"../utils/safe_timeout\";\n\n/**\n * Headless **debounced auto-submit** for forms (no dedicated APG pattern). Submits\n * the form a configurable delay after `input`/`change`, so Rails search/filter\n * forms refresh via Turbo without a submit button.\n *\n * Markup contract (identifier: `stimeo--auto-submit`):\n * <form data-controller=\"stimeo--auto-submit\"\n * data-stimeo--auto-submit-debounce-value=\"300\"\n * data-action=\"input->stimeo--auto-submit#submit\n * change->stimeo--auto-submit#submit\">\n * <input type=\"search\" name=\"q\">\n * </form>\n *\n * <!-- Or with the form as a target nested under the controller element: -->\n * <div data-controller=\"stimeo--auto-submit\">\n * <form data-stimeo--auto-submit-target=\"form\"> … </form>\n * </div>\n *\n * @remarks\n * Behavior only — it owns *triggering* the submit (debounce + `requestSubmit`),\n * never the submit itself (Turbo / native form submission) or validation. It\n * **never moves focus** (WCAG 2.2 3.2.2 / 4.1.3): auto-submitting must not yank the\n * caret out of the field. While a result swap is silent for screen-reader users,\n * setting `announce` bridges the completion to the shared `stimeo--announcer`\n * as a safety net; apps can also listen for `stimeo--auto-submit:done`\n * and announce richer text themselves. `aria-busy` marks the in-flight window and\n * `data-auto-submit-pending` the debounce window, for consumer CSS. During IME\n * composition it holds the submit until `compositionend` (the confirmed\n * conversion) so it does not fire on each intermediate keystroke. The debounce\n * timer and the `turbo:submit-end`/composition listeners are torn down on\n * `disconnect()`.\n */\nexport class AutoSubmitController extends Controller<HTMLElement> {\n static override targets = [\"form\"];\n static override values = {\n debounce: { type: Number, default: 300 },\n on: { type: String, default: \"input change\" },\n announce: { type: Boolean, default: false },\n message: { type: String, default: \"\" },\n };\n static actions = [\"submit\"] as const;\n static events = [\"submit\", \"done\"] as const;\n\n declare readonly formTarget: HTMLFormElement;\n declare readonly hasFormTarget: boolean;\n\n declare debounceValue: number;\n declare onValue: string;\n declare announceValue: boolean;\n declare messageValue: string;\n\n /** Debounce timer registry; one `clearAll()` in disconnect tears it down. */\n readonly #timers = new SafeTimeout();\n /** Id of the pending debounce timer, so a new keystroke can reset it. */\n #pendingId = 0;\n\n /** Clears `aria-busy` and emits completion once Turbo finishes the submit. */\n readonly #onSubmitEnd = (): void => {\n this.#form.removeAttribute(\"aria-busy\");\n const message = this.messageValue;\n this.dispatch(\"done\", { detail: { message: message || undefined } });\n // Bridge the silent result swap to the shared Announcer so SR users hear it.\n if (this.announceValue && message) {\n window.dispatchEvent(new CustomEvent(\"stimeo--announcer:announce\", { detail: { message } }));\n }\n };\n\n /** True while an IME composition is in progress on one of the form's fields. */\n #composing = false;\n\n /** Marks composition active so `input` events mid-conversion don't submit. */\n readonly #onCompositionStart = (): void => {\n this.#composing = true;\n };\n\n /**\n * Composition finished (the IME conversion is confirmed): clear the flag and\n * schedule a submit as if `input` fired, so the settled text triggers a submit\n * even on browsers whose post-composition `input` still reads `isComposing`.\n */\n readonly #onCompositionEnd = (event: Event): void => {\n this.#composing = false;\n if (this.#triggers(\"input\")) this.#schedule((event.target as HTMLElement | null) ?? null);\n };\n\n override connect(): void {\n this.#form.addEventListener(\"turbo:submit-end\", this.#onSubmitEnd);\n this.#form.addEventListener(\"compositionstart\", this.#onCompositionStart);\n this.#form.addEventListener(\"compositionend\", this.#onCompositionEnd);\n }\n\n override disconnect(): void {\n this.#timers.clearAll();\n this.#pendingId = 0;\n // Reset so a same-instance reconnect (e.g. Turbo cache restore mid-composition)\n // never starts with submits suppressed.\n this.#composing = false;\n this.#form.removeAttribute(\"data-auto-submit-pending\");\n this.#form.removeEventListener(\"turbo:submit-end\", this.#onSubmitEnd);\n this.#form.removeEventListener(\"compositionstart\", this.#onCompositionStart);\n this.#form.removeEventListener(\"compositionend\", this.#onCompositionEnd);\n }\n\n /**\n * Schedules a debounced submit. Wired to `input`/`change`; the `on` value is an\n * allowlist so a configured subset (e.g. only `change`) is honored even when both\n * are bound in markup. Coalesces rapid events into a single `requestSubmit`.\n */\n submit(event: Event): void {\n if (!this.#triggers(event.type)) return;\n // Ignore `input` events fired mid-IME-composition (e.g. typing kana before the\n // Japanese conversion is confirmed); the confirmed text submits on\n // `compositionend` and the browser's final post-composition `input`.\n if (event.type === \"input\" && (this.#composing || (event as InputEvent).isComposing)) return;\n this.#schedule((event.target as HTMLElement | null) ?? null);\n }\n\n /** Schedules (and coalesces) the debounced submit for the given trigger. */\n #schedule(trigger: HTMLElement | null): void {\n this.#form.setAttribute(\"data-auto-submit-pending\", \"true\");\n if (this.#pendingId) this.#timers.clear(this.#pendingId);\n\n this.#pendingId = this.#timers.set(() => {\n this.#pendingId = 0;\n this.#form.removeAttribute(\"data-auto-submit-pending\");\n this.dispatch(\"submit\", { detail: { trigger } });\n // `requestSubmit()` runs native constraint validation. If the form is\n // invalid the actual submit never happens — the browser blocks it (or, when\n // a `stimeo--form-validation` set `novalidate`, that controller cancels the\n // submit) — so no `turbo:submit-end` arrives to clear `aria-busy`. Only mark\n // the form busy when the submit will really proceed; still call\n // `requestSubmit()` either way so the validation surfaces to the user.\n if (this.#form.checkValidity()) {\n this.#form.setAttribute(\"aria-busy\", \"true\");\n }\n this.#form.requestSubmit();\n }, this.debounceValue);\n }\n\n /** Resolves the form element (explicit `form` target, else the controller root). */\n get #form(): HTMLFormElement {\n return this.hasFormTarget ? this.formTarget : (this.element as HTMLFormElement);\n }\n\n /** Whether `type` is one of the whitespace-separated event types in `on`. */\n #triggers(type: string): boolean {\n return this.onValue.split(/\\s+/).filter(Boolean).includes(type);\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/utils/composition_tracker.ts","../../src/utils/safe_timeout.ts","../../src/controllers/auto_submit_controller.ts"],"names":[],"mappings":";;;;;AAuCO,IAAM,qBAAN,MAAyB;AAAA,EACrB,gBAAA,uBAAuB,GAAA,EAAiB;AAAA,EACxC,cAAA,uBAAqB,GAAA,EAAiB;AAAA,EACtC,QAAA;AAAA,EACA,MAAA;AAAA,EAET,WAAA,CAAY,OAAA,GAAqC,EAAC,EAAG;AACnD,IAAA,IAAA,CAAK,WAAW,OAAA,CAAQ,OAAA;AACxB,IAAA,IAAA,CAAK,SAAS,OAAA,CAAQ,KAAA;AAAA,EACxB;AAAA;AAAA,EAGA,QAAQ,MAAA,EAA2B;AACjC,IAAA,IAAI,IAAA,CAAK,gBAAA,CAAiB,GAAA,CAAI,MAAM,CAAA,EAAG;AACvC,IAAA,MAAA,CAAO,gBAAA,CAAiB,kBAAA,EAAoB,IAAA,CAAK,YAAY,CAAA;AAC7D,IAAA,MAAA,CAAO,gBAAA,CAAiB,gBAAA,EAAkB,IAAA,CAAK,UAAU,CAAA;AACzD,IAAA,IAAA,CAAK,gBAAA,CAAiB,IAAI,MAAM,CAAA;AAAA,EAClC;AAAA;AAAA,EAGA,UAAU,MAAA,EAA2B;AACnC,IAAA,IAAI,CAAC,IAAA,CAAK,gBAAA,CAAiB,MAAA,CAAO,MAAM,CAAA,EAAG;AAC3C,IAAA,MAAA,CAAO,mBAAA,CAAoB,kBAAA,EAAoB,IAAA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IAAA,CAAK,KAAA,CAAM,YAAA,CAAa,WAAA,EAAa,MAAM,CAAA;AAAA,MAC7C;AACA,MAAA,IAAA,CAAK,MAAM,aAAA,EAAc;AAAA,IAC3B,CAAA,EAAG,KAAK,aAAa,CAAA;AAAA,EACvB;AAAA;AAAA,EAGA,IAAI,KAAA,GAAyB;AAC3B,IAAA,OAAO,IAAA,CAAK,aAAA,GAAgB,IAAA,CAAK,UAAA,GAAc,IAAA,CAAK,OAAA;AAAA,EACtD;AAAA;AAAA,EAGA,UAAU,IAAA,EAAuB;AAC/B,IAAA,OAAO,IAAA,CAAK,QAAQ,KAAA,CAAM,KAAK,EAAE,MAAA,CAAO,OAAO,CAAA,CAAE,QAAA,CAAS,IAAI,CAAA;AAAA,EAChE;AACF","file":"auto_submit_controller.js","sourcesContent":["/** Minimal event shape carrying the platform's per-event composition signal. */\nexport interface CompositionSignal {\n readonly isComposing?: boolean;\n}\n\n/** Hooks that keep component-specific work outside {@link CompositionTracker}. */\nexport interface CompositionTrackerOptions {\n /** Runs after lifecycle state is set for a `compositionstart` event. */\n readonly onStart?: (event: Event) => void;\n /** Runs after lifecycle state is cleared for a `compositionend` event. */\n readonly onEnd?: (event: Event) => void;\n}\n\n/**\n * Owns IME composition listeners and transient state for one or more event targets.\n *\n * Some browsers omit `KeyboardEvent.isComposing` on the keydown that confirms a\n * conversion. Tracking `compositionstart` through `compositionend` supplies the\n * missing lifecycle signal without relying on deprecated numeric key codes.\n * Component policy stays with the consumer: filtering, validation, and submission\n * belong in the optional {@link CompositionTrackerOptions.onEnd} callback.\n *\n * @example\n * ```ts\n * #composition = new CompositionTracker({ onEnd: () => this.filter() });\n *\n * connect(): void {\n * this.#composition.observe(this.inputTarget);\n * }\n *\n * disconnect(): void {\n * this.#composition.disconnect();\n * }\n *\n * onKeydown(event: KeyboardEvent): void {\n * if (this.#composition.isComposing(event)) return;\n * }\n * ```\n */\nexport class CompositionTracker {\n readonly #observedTargets = new Set<EventTarget>();\n readonly #activeTargets = new Set<EventTarget>();\n readonly #onStart: ((event: Event) => void) | undefined;\n readonly #onEnd: ((event: Event) => void) | undefined;\n\n constructor(options: CompositionTrackerOptions = {}) {\n this.#onStart = options.onStart;\n this.#onEnd = options.onEnd;\n }\n\n /** Starts lifecycle tracking for `target`; repeated calls are idempotent. */\n observe(target: EventTarget): void {\n if (this.#observedTargets.has(target)) return;\n target.addEventListener(\"compositionstart\", this.#handleStart);\n target.addEventListener(\"compositionend\", this.#handleEnd);\n this.#observedTargets.add(target);\n }\n\n /** Stops tracking one target and clears any active composition it owned. */\n unobserve(target: EventTarget): void {\n if (!this.#observedTargets.delete(target)) return;\n target.removeEventListener(\"compositionstart\", this.#handleStart);\n target.removeEventListener(\"compositionend\", this.#handleEnd);\n this.#activeTargets.delete(target);\n }\n\n /** Releases every listener and clears state so reconnect starts cleanly. */\n disconnect(): void {\n for (const target of this.#observedTargets) {\n target.removeEventListener(\"compositionstart\", this.#handleStart);\n target.removeEventListener(\"compositionend\", this.#handleEnd);\n }\n this.#observedTargets.clear();\n this.#activeTargets.clear();\n }\n\n /** True when lifecycle tracking or the current event reports composition. */\n isComposing(event?: CompositionSignal): boolean {\n return this.#activeTargets.size > 0 || event?.isComposing === true;\n }\n\n readonly #handleStart = (event: Event): void => {\n if (event.currentTarget) this.#activeTargets.add(event.currentTarget);\n this.#onStart?.(event);\n };\n\n readonly #handleEnd = (event: Event): void => {\n if (event.currentTarget) this.#activeTargets.delete(event.currentTarget);\n this.#onEnd?.(event);\n };\n}\n","/**\n * Self-cleaning timer registries shared by Stimeo controllers.\n *\n * Stimulus controllers frequently schedule `setTimeout` / `setInterval` work\n * (auto-dismiss, debouncing, polling). When the element leaves the DOM — a\n * Turbo Drive navigation, a Turbo Stream replacement, or any `disconnect()` —\n * orphaned timers keep firing against a detached controller, leaking memory and\n * mutating stale state. {@link SafeTimeout} and {@link SafeInterval} track every\n * timer they create so a single {@link TimerRegistry.clearAll | clearAll()} call\n * in `disconnect()` tears them all down.\n *\n * These are intentionally low-level primitives: they own *registration and\n * cleanup only*. Higher-level policy (pause/resume, remaining-time accounting)\n * stays in the individual controllers so per-widget semantics are not flattened\n * into a lowest-common-denominator helper.\n */\n\n/**\n * Shared registry bookkeeping for the timeout/interval variants.\n *\n * Subclasses provide the scheduling primitive ({@link schedule}) and its matching\n * canceller ({@link cancel}); this base owns the set of live ids plus the\n * per-id and bulk teardown shared by both.\n */\nabstract class TimerRegistry {\n /** Live timer ids that have not yet been cleared (or, for timeouts, fired). */\n protected readonly ids = new Set<number>();\n\n /** Schedules the underlying platform timer and returns its id. */\n protected abstract schedule(callback: () => void, delay: number): number;\n\n /** Cancels the underlying platform timer for `id`. */\n protected abstract cancel(id: number): void;\n\n /**\n * Cancels a single tracked timer.\n *\n * No-ops if the id is unknown (already cleared, fired, or never owned by this\n * registry), so callers can clear defensively without guarding.\n */\n clear(id: number): void {\n if (this.ids.delete(id)) {\n this.cancel(id);\n }\n }\n\n /**\n * Cancels every tracked timer. Call this from a controller's `disconnect()`\n * to guarantee no timer outlives the element.\n */\n clearAll(): void {\n for (const id of this.ids) {\n this.cancel(id);\n }\n this.ids.clear();\n }\n\n /** Number of timers currently tracked (pending). */\n get size(): number {\n return this.ids.size;\n }\n}\n\n/**\n * `setTimeout` wrapper that auto-forgets each timer once it fires and supports\n * bulk teardown on disconnect.\n *\n * @example\n * ```ts\n * #timers = new SafeTimeout();\n *\n * connect() {\n * this.#timers.set(() => this.dismiss(), 5000);\n * }\n *\n * disconnect() {\n * this.#timers.clearAll();\n * }\n * ```\n */\nexport class SafeTimeout extends TimerRegistry {\n /**\n * Schedules `callback` after `delay` ms and returns the timer id.\n *\n * The id is removed from the registry automatically when the timeout fires,\n * so {@link TimerRegistry.size | size} reflects only still-pending timers.\n */\n set(callback: () => void, delay: number): number {\n const id = this.schedule(() => {\n this.ids.delete(id);\n callback();\n }, delay);\n this.ids.add(id);\n return id;\n }\n\n protected schedule(callback: () => void, delay: number): number {\n return window.setTimeout(callback, delay);\n }\n\n protected cancel(id: number): void {\n window.clearTimeout(id);\n }\n}\n\n/**\n * `setInterval` wrapper that tracks every interval for bulk teardown on\n * disconnect. Unlike {@link SafeTimeout}, intervals are retained until they are\n * explicitly cleared because they fire repeatedly.\n *\n * @example\n * ```ts\n * #intervals = new SafeInterval();\n *\n * connect() {\n * this.#intervals.set(() => this.tick(), 1000);\n * }\n *\n * disconnect() {\n * this.#intervals.clearAll();\n * }\n * ```\n */\nexport class SafeInterval extends TimerRegistry {\n /** Schedules a repeating `callback` every `delay` ms and returns the timer id. */\n set(callback: () => void, delay: number): number {\n const id = this.schedule(callback, delay);\n this.ids.add(id);\n return id;\n }\n\n protected schedule(callback: () => void, delay: number): number {\n return window.setInterval(callback, delay);\n }\n\n protected cancel(id: number): void {\n window.clearInterval(id);\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { CompositionTracker } from \"../utils/composition_tracker\";\nimport { SafeTimeout } from \"../utils/safe_timeout\";\n\n/**\n * Headless **debounced auto-submit** for forms (no dedicated APG pattern). Submits\n * the form a configurable delay after `input`/`change`, so Rails search/filter\n * forms refresh via Turbo without a submit button.\n *\n * Markup contract (identifier: `stimeo--auto-submit`):\n * <form data-controller=\"stimeo--auto-submit\"\n * data-stimeo--auto-submit-debounce-value=\"300\"\n * data-action=\"input->stimeo--auto-submit#submit\n * change->stimeo--auto-submit#submit\">\n * <input type=\"search\" name=\"q\">\n * </form>\n *\n * <!-- Or with the form as a target nested under the controller element: -->\n * <div data-controller=\"stimeo--auto-submit\">\n * <form data-stimeo--auto-submit-target=\"form\"> … </form>\n * </div>\n *\n * @remarks\n * Behavior only — it owns *triggering* the submit (debounce + `requestSubmit`),\n * never the submit itself (Turbo / native form submission) or validation. It\n * **never moves focus** (WCAG 2.2 3.2.2 / 4.1.3): auto-submitting must not yank the\n * caret out of the field. While a result swap is silent for screen-reader users,\n * setting `announce` bridges the completion to the shared `stimeo--announcer`\n * as a safety net; apps can also listen for `stimeo--auto-submit:done`\n * and announce richer text themselves. `aria-busy` marks the in-flight window and\n * `data-auto-submit-pending` the debounce window, for consumer CSS. During IME\n * composition it holds the submit until `compositionend` (the confirmed\n * conversion) so it does not fire on each intermediate keystroke. The debounce\n * timer and the `turbo:submit-end`/composition listeners are torn down on\n * `disconnect()`.\n */\nexport class AutoSubmitController extends Controller<HTMLElement> {\n static override targets = [\"form\"];\n static override values = {\n debounce: { type: Number, default: 300 },\n on: { type: String, default: \"input change\" },\n announce: { type: Boolean, default: false },\n message: { type: String, default: \"\" },\n };\n static actions = [\"submit\"] as const;\n static events = [\"submit\", \"done\"] as const;\n\n declare readonly formTarget: HTMLFormElement;\n declare readonly hasFormTarget: boolean;\n\n declare debounceValue: number;\n declare onValue: string;\n declare announceValue: boolean;\n declare messageValue: string;\n\n /** Debounce timer registry; one `clearAll()` in disconnect tears it down. */\n readonly #timers = new SafeTimeout();\n /** Id of the pending debounce timer, so a new keystroke can reset it. */\n #pendingId = 0;\n\n /** Clears `aria-busy` and emits completion once Turbo finishes the submit. */\n readonly #onSubmitEnd = (): void => {\n this.#form.removeAttribute(\"aria-busy\");\n const message = this.messageValue;\n this.dispatch(\"done\", { detail: { message: message || undefined } });\n // Bridge the silent result swap to the shared Announcer so SR users hear it.\n if (this.announceValue && message) {\n window.dispatchEvent(new CustomEvent(\"stimeo--announcer:announce\", { detail: { message } }));\n }\n };\n\n /** Owns delegated IME lifecycle state and submits confirmed input text. */\n readonly #composition = new CompositionTracker({\n onEnd: (event) => {\n if (this.#triggers(\"input\")) this.#schedule((event.target as HTMLElement | null) ?? null);\n },\n });\n\n override connect(): void {\n this.#form.addEventListener(\"turbo:submit-end\", this.#onSubmitEnd);\n this.#composition.observe(this.#form);\n }\n\n override disconnect(): void {\n this.#timers.clearAll();\n this.#pendingId = 0;\n this.#composition.disconnect();\n this.#form.removeAttribute(\"data-auto-submit-pending\");\n this.#form.removeEventListener(\"turbo:submit-end\", this.#onSubmitEnd);\n }\n\n /**\n * Schedules a debounced submit. Wired to `input`/`change`; the `on` value is an\n * allowlist so a configured subset (e.g. only `change`) is honored even when both\n * are bound in markup. Coalesces rapid events into a single `requestSubmit`.\n */\n submit(event: Event): void {\n if (!this.#triggers(event.type)) return;\n // Ignore `input` events fired mid-IME-composition (e.g. typing kana before the\n // Japanese conversion is confirmed); the confirmed text submits on\n // `compositionend` and the browser's final post-composition `input`.\n if (event.type === \"input\" && this.#composition.isComposing(event as InputEvent)) return;\n this.#schedule((event.target as HTMLElement | null) ?? null);\n }\n\n /** Schedules (and coalesces) the debounced submit for the given trigger. */\n #schedule(trigger: HTMLElement | null): void {\n this.#form.setAttribute(\"data-auto-submit-pending\", \"true\");\n if (this.#pendingId) this.#timers.clear(this.#pendingId);\n\n this.#pendingId = this.#timers.set(() => {\n this.#pendingId = 0;\n this.#form.removeAttribute(\"data-auto-submit-pending\");\n this.dispatch(\"submit\", { detail: { trigger } });\n // `requestSubmit()` runs native constraint validation. If the form is\n // invalid the actual submit never happens — the browser blocks it (or, when\n // a `stimeo--form-validation` set `novalidate`, that controller cancels the\n // submit) — so no `turbo:submit-end` arrives to clear `aria-busy`. Only mark\n // the form busy when the submit will really proceed; still call\n // `requestSubmit()` either way so the validation surfaces to the user.\n if (this.#form.checkValidity()) {\n this.#form.setAttribute(\"aria-busy\", \"true\");\n }\n this.#form.requestSubmit();\n }, this.debounceValue);\n }\n\n /** Resolves the form element (explicit `form` target, else the controller root). */\n get #form(): HTMLFormElement {\n return this.hasFormTarget ? this.formTarget : (this.element as HTMLFormElement);\n }\n\n /** Whether `type` is one of the whitespace-separated event types in `on`. */\n #triggers(type: string): boolean {\n return this.onValue.split(/\\s+/).filter(Boolean).includes(type);\n }\n}\n"]}
@@ -0,0 +1,100 @@
1
+ import { Controller } from '@hotwired/stimulus';
2
+
3
+ /**
4
+ * Headless, accessible **Carousel** (slideshow) behavior.
5
+ *
6
+ * Markup contract (identifier: `stimeo--carousel`):
7
+ * <section data-controller="stimeo--carousel" aria-roledescription="carousel"
8
+ * aria-label="Featured"
9
+ * data-stimeo--carousel-autoplay-value="false"
10
+ * data-stimeo--carousel-interval-value="5000"
11
+ * data-stimeo--carousel-loop-value="true"
12
+ * data-action="mouseenter->stimeo--carousel#pause
13
+ * mouseleave->stimeo--carousel#resume
14
+ * focusin->stimeo--carousel#pause
15
+ * focusout->stimeo--carousel#resume">
16
+ * <button data-stimeo--carousel-target="playToggle"
17
+ * data-action="stimeo--carousel#togglePlay">…</button>
18
+ * <div data-stimeo--carousel-target="viewport">
19
+ * <div role="tabpanel" data-stimeo--carousel-target="slide">…</div>
20
+ * <div role="tabpanel" data-stimeo--carousel-target="slide" hidden>…</div>
21
+ * </div>
22
+ * <button data-stimeo--carousel-target="prev" data-action="stimeo--carousel#prev">‹</button>
23
+ * <button data-stimeo--carousel-target="next" data-action="stimeo--carousel#next">›</button>
24
+ * <div role="tablist">
25
+ * <button role="tab" data-stimeo--carousel-target="picker"
26
+ * data-action="stimeo--carousel#goto
27
+ * keydown->stimeo--carousel#onPickerKeydown"></button>
28
+ * </div>
29
+ * </section>
30
+ *
31
+ * Implements the WAI-ARIA APG **Carousel** (tabbed) pattern. The current slide is
32
+ * exposed through `data-state` (`active`/`inactive`) and the `hidden` attribute on
33
+ * inactive slides (removing them from focus order); the matching picker carries
34
+ * `aria-selected` and the single roving `tabindex`. The play/pause toggle's
35
+ * `aria-pressed` mirrors the autoplay state.
36
+ *
37
+ * @remarks
38
+ * Behavior only — transitions, layout, and visuals are the consumer's CSS.
39
+ * Autoplay honors WCAG 2.2.2: it suspends while the pointer is over the carousel
40
+ * and **hard-stops** when keyboard focus enters (it does not silently resume on
41
+ * focus out — the user must press play), so motion never surprises a keyboard
42
+ * user. The interval is cleared on `disconnect()` (Turbo navigation included).
43
+ * Picker arrow keys move focus only (manual activation); slide changes never steal
44
+ * focus from the control the user operated.
45
+ */
46
+ declare class CarouselController extends Controller<HTMLElement> {
47
+ #private;
48
+ static targets: string[];
49
+ static values: {
50
+ autoplay: {
51
+ type: BooleanConstructor;
52
+ default: boolean;
53
+ };
54
+ interval: {
55
+ type: NumberConstructor;
56
+ default: number;
57
+ };
58
+ loop: {
59
+ type: BooleanConstructor;
60
+ default: boolean;
61
+ };
62
+ };
63
+ static actions: readonly ["goto", "next", "onPickerKeydown", "pause", "prev", "resume", "togglePlay"];
64
+ static events: readonly ["change", "pause", "play"];
65
+ readonly slideTargets: HTMLElement[];
66
+ readonly pickerTargets: HTMLElement[];
67
+ readonly playToggleTarget: HTMLElement;
68
+ readonly hasPlayToggleTarget: boolean;
69
+ autoplayValue: boolean;
70
+ intervalValue: number;
71
+ loopValue: boolean;
72
+ /** Renders the initial slide and starts autoplay when requested. */
73
+ connect(): void;
74
+ /** Clears the autoplay interval so it never fires after teardown. */
75
+ disconnect(): void;
76
+ /** Advances to the next slide. Bound via `data-action`. */
77
+ next(): void;
78
+ /** Returns to the previous slide. Bound via `data-action`. */
79
+ prev(): void;
80
+ /** Jumps to the slide whose picker was activated (click / Enter / Space). */
81
+ goto(event: Event): void;
82
+ /** Toggles autoplay on the user's explicit request and syncs the timer. */
83
+ togglePlay(): void;
84
+ /**
85
+ * Suspends autoplay. Hover (`mouseenter`) is a temporary suspension that resumes
86
+ * on leave; keyboard focus (`focusin`) is a hard stop that turns autoplay off so
87
+ * it cannot resume without an explicit play (WCAG 2.2.2).
88
+ */
89
+ pause(event?: Event): void;
90
+ /**
91
+ * Lifts a hover suspension (`mouseleave`) and resumes autoplay if it is still
92
+ * on. A `focusout` does nothing here: the focus pause was a hard stop, so the
93
+ * user must press play to restart.
94
+ */
95
+ resume(event?: Event): void;
96
+ /** Picker roving: arrows move focus only; Home/End activate first/last slide. */
97
+ onPickerKeydown(event: KeyboardEvent): void;
98
+ }
99
+
100
+ export { CarouselController };
@@ -0,0 +1,272 @@
1
+ import { Controller } from '@hotwired/stimulus';
2
+
3
+ // src/controllers/carousel_controller.ts
4
+
5
+ // src/utils/roving_tabindex.ts
6
+ var RovingTabindex = class {
7
+ /** Returns the current ordered item elements; called on every operation. */
8
+ #getItems;
9
+ /**
10
+ * @param getItems - Returns the current ordered item elements. Called on every
11
+ * operation so the live target list is always used.
12
+ */
13
+ constructor(getItems) {
14
+ this.#getItems = getItems;
15
+ }
16
+ /** Index of the currently tabbable item (`tabindex="0"`), or `-1` if none. */
17
+ get activeIndex() {
18
+ return this.#getItems().findIndex((item) => item.tabIndex === 0);
19
+ }
20
+ /**
21
+ * Makes exactly the item at `index` tabbable (`tabindex="0"`) and removes every
22
+ * other item from the Tab sequence (`tabindex="-1"`). An out-of-range `index`
23
+ * (e.g. `-1`) leaves all items at `-1`, which a controller can use to express
24
+ * "nothing is currently tabbable".
25
+ *
26
+ * @param index - Position of the item to make tabbable.
27
+ * @param options - Pass `{ focus: true }` to also move DOM focus to that item.
28
+ */
29
+ setActive(index, { focus = false } = {}) {
30
+ const items = this.#getItems();
31
+ items.forEach((item, i) => {
32
+ item.tabIndex = i === index ? 0 : -1;
33
+ });
34
+ if (focus) items[index]?.focus();
35
+ }
36
+ };
37
+ function rovingMove(current, length, delta, wrap) {
38
+ if (length === 0) return -1;
39
+ const next = current + delta;
40
+ return (next + length) % length;
41
+ }
42
+
43
+ // src/utils/safe_timeout.ts
44
+ var TimerRegistry = class {
45
+ /** Live timer ids that have not yet been cleared (or, for timeouts, fired). */
46
+ ids = /* @__PURE__ */ new Set();
47
+ /**
48
+ * Cancels a single tracked timer.
49
+ *
50
+ * No-ops if the id is unknown (already cleared, fired, or never owned by this
51
+ * registry), so callers can clear defensively without guarding.
52
+ */
53
+ clear(id) {
54
+ if (this.ids.delete(id)) {
55
+ this.cancel(id);
56
+ }
57
+ }
58
+ /**
59
+ * Cancels every tracked timer. Call this from a controller's `disconnect()`
60
+ * to guarantee no timer outlives the element.
61
+ */
62
+ clearAll() {
63
+ for (const id of this.ids) {
64
+ this.cancel(id);
65
+ }
66
+ this.ids.clear();
67
+ }
68
+ /** Number of timers currently tracked (pending). */
69
+ get size() {
70
+ return this.ids.size;
71
+ }
72
+ };
73
+ var SafeInterval = class extends TimerRegistry {
74
+ /** Schedules a repeating `callback` every `delay` ms and returns the timer id. */
75
+ set(callback, delay) {
76
+ const id = this.schedule(callback, delay);
77
+ this.ids.add(id);
78
+ return id;
79
+ }
80
+ schedule(callback, delay) {
81
+ return window.setInterval(callback, delay);
82
+ }
83
+ cancel(id) {
84
+ window.clearInterval(id);
85
+ }
86
+ };
87
+
88
+ // src/controllers/carousel_controller.ts
89
+ var CarouselController = class extends Controller {
90
+ static targets = ["slide", "viewport", "prev", "next", "picker", "playToggle"];
91
+ static values = {
92
+ autoplay: { type: Boolean, default: false },
93
+ interval: { type: Number, default: 5e3 },
94
+ loop: { type: Boolean, default: true }
95
+ };
96
+ static actions = [
97
+ "goto",
98
+ "next",
99
+ "onPickerKeydown",
100
+ "pause",
101
+ "prev",
102
+ "resume",
103
+ "togglePlay"
104
+ ];
105
+ static events = ["change", "pause", "play"];
106
+ #roving = new RovingTabindex(() => this.pickerTargets);
107
+ #intervals = new SafeInterval();
108
+ /** Index of the visible slide. */
109
+ #index = 0;
110
+ /** User intent to autoplay (toggled by the play button / focus hard-stop). */
111
+ #playing = false;
112
+ /** Pointer is hovering the carousel: a temporary, auto-resuming suspension. */
113
+ #pointerPaused = false;
114
+ /** Id of the live autoplay interval, or null when stopped. */
115
+ #timerId = null;
116
+ /** Renders the initial slide and starts autoplay when requested. */
117
+ connect() {
118
+ const preselected = this.pickerTargets.findIndex(
119
+ (picker) => picker.getAttribute("aria-selected") === "true"
120
+ );
121
+ this.#index = preselected === -1 ? 0 : preselected;
122
+ this.#playing = this.#initialPlaying();
123
+ this.#render({ focus: false });
124
+ this.#syncTimer();
125
+ }
126
+ /**
127
+ * Resolves the starting autoplay intent. The play toggle's `aria-pressed` is the
128
+ * source of truth **when present**, so a Turbo Drive cache restore / morph that
129
+ * re-runs `connect()` against existing DOM does not silently resume autoplay the
130
+ * user had stopped (e.g. by focusing into the carousel). Only when no toggle
131
+ * carries `aria-pressed` does it fall back to the declarative `autoplay` value.
132
+ */
133
+ #initialPlaying() {
134
+ if (this.hasPlayToggleTarget && this.playToggleTarget.hasAttribute("aria-pressed")) {
135
+ return this.playToggleTarget.getAttribute("aria-pressed") === "true";
136
+ }
137
+ return this.autoplayValue;
138
+ }
139
+ /** Clears the autoplay interval so it never fires after teardown. */
140
+ disconnect() {
141
+ this.#intervals.clearAll();
142
+ this.#timerId = null;
143
+ }
144
+ /** Advances to the next slide. Bound via `data-action`. */
145
+ next() {
146
+ this.#select(this.#step(1), { focus: false });
147
+ }
148
+ /** Returns to the previous slide. Bound via `data-action`. */
149
+ prev() {
150
+ this.#select(this.#step(-1), { focus: false });
151
+ }
152
+ /** Jumps to the slide whose picker was activated (click / Enter / Space). */
153
+ goto(event) {
154
+ const target = event.currentTarget;
155
+ const index = this.pickerTargets.indexOf(target);
156
+ if (index !== -1) this.#select(index, { focus: false });
157
+ }
158
+ /** Toggles autoplay on the user's explicit request and syncs the timer. */
159
+ togglePlay() {
160
+ this.#playing = !this.#playing;
161
+ this.#syncTimer();
162
+ }
163
+ /**
164
+ * Suspends autoplay. Hover (`mouseenter`) is a temporary suspension that resumes
165
+ * on leave; keyboard focus (`focusin`) is a hard stop that turns autoplay off so
166
+ * it cannot resume without an explicit play (WCAG 2.2.2).
167
+ */
168
+ pause(event) {
169
+ if (event?.type.startsWith("focus")) {
170
+ this.#playing = false;
171
+ } else {
172
+ this.#pointerPaused = true;
173
+ }
174
+ this.#syncTimer();
175
+ }
176
+ /**
177
+ * Lifts a hover suspension (`mouseleave`) and resumes autoplay if it is still
178
+ * on. A `focusout` does nothing here: the focus pause was a hard stop, so the
179
+ * user must press play to restart.
180
+ */
181
+ resume(event) {
182
+ if (event?.type.startsWith("focus")) return;
183
+ this.#pointerPaused = false;
184
+ this.#syncTimer();
185
+ }
186
+ /** Picker roving: arrows move focus only; Home/End activate first/last slide. */
187
+ onPickerKeydown(event) {
188
+ const current = this.pickerTargets.indexOf(event.currentTarget);
189
+ if (current === -1) return;
190
+ const length = this.pickerTargets.length;
191
+ switch (event.key) {
192
+ case "ArrowRight":
193
+ case "ArrowDown":
194
+ event.preventDefault();
195
+ this.#roving.setActive(rovingMove(current, length, 1), { focus: true });
196
+ return;
197
+ case "ArrowLeft":
198
+ case "ArrowUp":
199
+ event.preventDefault();
200
+ this.#roving.setActive(rovingMove(current, length, -1), { focus: true });
201
+ return;
202
+ case "Home":
203
+ event.preventDefault();
204
+ this.#select(0, { focus: true });
205
+ return;
206
+ case "End":
207
+ event.preventDefault();
208
+ this.#select(length - 1, { focus: true });
209
+ return;
210
+ }
211
+ }
212
+ /** Resolves the index one step away from the current one, honoring `loop`. */
213
+ #step(delta) {
214
+ const total = this.slideTargets.length;
215
+ if (total === 0) return 0;
216
+ const next = this.#index + delta;
217
+ if (this.loopValue) return (next + total) % total;
218
+ return Math.min(total - 1, Math.max(0, next));
219
+ }
220
+ /**
221
+ * Changes the active slide, updates state hooks, and emits `change` — but only
222
+ * when the index actually changes, so a `next`/`prev` clamped at the end (or an
223
+ * autoplay tick at a non-looping boundary) re-renders without a spurious event
224
+ * (matching the "emit on real change" policy of flash/masonry/bulk-select).
225
+ */
226
+ #select(index, { focus }) {
227
+ const changed = index !== this.#index;
228
+ this.#index = index;
229
+ this.#render({ focus });
230
+ this.#syncTimer();
231
+ if (changed) this.dispatch("change", { detail: { index, total: this.slideTargets.length } });
232
+ }
233
+ /** Reflects `this.#index` onto slides and pickers (state hooks + roving). */
234
+ #render({ focus }) {
235
+ this.slideTargets.forEach((slide, i) => {
236
+ const active = i === this.#index;
237
+ slide.setAttribute("data-state", active ? "active" : "inactive");
238
+ slide.hidden = !active;
239
+ });
240
+ this.pickerTargets.forEach((picker, i) => {
241
+ picker.setAttribute("aria-selected", i === this.#index ? "true" : "false");
242
+ });
243
+ this.#roving.setActive(this.#index, { focus });
244
+ }
245
+ /**
246
+ * Drives the autoplay interval toward the desired state. Autoplay should run
247
+ * only when the user wants it (`playing`), the pointer is not hovering, and more
248
+ * than one slide exists. Transitions emit `play`/`pause` and keep the toggle's
249
+ * `aria-pressed` in sync.
250
+ */
251
+ #syncTimer() {
252
+ if (!this.loopValue && this.#index >= this.slideTargets.length - 1) {
253
+ this.#playing = false;
254
+ }
255
+ const shouldRun = this.#playing && !this.#pointerPaused && this.slideTargets.length > 1;
256
+ if (shouldRun && this.#timerId === null) {
257
+ this.#timerId = this.#intervals.set(() => this.next(), this.intervalValue);
258
+ this.dispatch("play");
259
+ } else if (!shouldRun && this.#timerId !== null) {
260
+ this.#intervals.clear(this.#timerId);
261
+ this.#timerId = null;
262
+ this.dispatch("pause");
263
+ }
264
+ if (this.hasPlayToggleTarget) {
265
+ this.playToggleTarget.setAttribute("aria-pressed", this.#playing ? "true" : "false");
266
+ }
267
+ }
268
+ };
269
+
270
+ export { CarouselController };
271
+ //# sourceMappingURL=carousel_controller.js.map
272
+ //# sourceMappingURL=carousel_controller.js.map