stimeo-ui 0.14.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +212 -0
- package/README.md +120 -0
- package/dist/cable/index.js +123 -29
- package/dist/cable/index.js.map +1 -1
- package/dist/controllers/accordion_controller.d.ts +30 -3
- package/dist/controllers/accordion_controller.js +98 -9
- package/dist/controllers/accordion_controller.js.map +1 -1
- package/dist/controllers/alert_dialog_controller.d.ts +8 -7
- package/dist/controllers/alert_dialog_controller.js.map +1 -1
- package/dist/controllers/announcer_controller.d.ts +3 -2
- package/dist/controllers/announcer_controller.js +96 -62
- package/dist/controllers/announcer_controller.js.map +1 -1
- package/dist/controllers/auto_submit_controller.js +83 -7
- package/dist/controllers/auto_submit_controller.js.map +1 -1
- package/dist/controllers/avatar_controller.js +1 -1
- package/dist/controllers/avatar_controller.js.map +1 -1
- package/dist/controllers/breadcrumb_controller.d.ts +10 -7
- package/dist/controllers/breadcrumb_controller.js +38 -11
- package/dist/controllers/breadcrumb_controller.js.map +1 -1
- package/dist/controllers/bulk_select_controller.d.ts +4 -4
- package/dist/controllers/bulk_select_controller.js +7 -6
- package/dist/controllers/bulk_select_controller.js.map +1 -1
- package/dist/controllers/calendar_controller.d.ts +101 -23
- package/dist/controllers/calendar_controller.js +340 -123
- package/dist/controllers/calendar_controller.js.map +1 -1
- package/dist/controllers/carousel_controller.d.ts +67 -22
- package/dist/controllers/carousel_controller.js +263 -38
- package/dist/controllers/carousel_controller.js.map +1 -1
- package/dist/controllers/character_counter_controller.d.ts +1 -1
- package/dist/controllers/character_counter_controller.js +40 -2
- package/dist/controllers/character_counter_controller.js.map +1 -1
- package/dist/controllers/checkbox_controller.js +81 -12
- package/dist/controllers/checkbox_controller.js.map +1 -1
- package/dist/controllers/clipboard_controller.d.ts +28 -2
- package/dist/controllers/clipboard_controller.js +63 -5
- package/dist/controllers/clipboard_controller.js.map +1 -1
- package/dist/controllers/collapsible_controller.d.ts +25 -1
- package/dist/controllers/collapsible_controller.js +99 -14
- package/dist/controllers/collapsible_controller.js.map +1 -1
- package/dist/controllers/color_picker_controller.d.ts +29 -8
- package/dist/controllers/color_picker_controller.js +80 -34
- package/dist/controllers/color_picker_controller.js.map +1 -1
- package/dist/controllers/combobox_controller.d.ts +10 -1
- package/dist/controllers/combobox_controller.js +106 -16
- package/dist/controllers/combobox_controller.js.map +1 -1
- package/dist/controllers/command_palette_controller.d.ts +3 -3
- package/dist/controllers/command_palette_controller.js +35 -3
- package/dist/controllers/command_palette_controller.js.map +1 -1
- package/dist/controllers/conditional_fields_controller.js +85 -17
- package/dist/controllers/conditional_fields_controller.js.map +1 -1
- package/dist/controllers/confirm_controller.js +3 -0
- package/dist/controllers/confirm_controller.js.map +1 -1
- package/dist/controllers/context_menu_controller.d.ts +6 -0
- package/dist/controllers/context_menu_controller.js +32 -12
- package/dist/controllers/context_menu_controller.js.map +1 -1
- package/dist/controllers/count_up_controller.js.map +1 -1
- package/dist/controllers/countdown_controller.d.ts +30 -1
- package/dist/controllers/countdown_controller.js +129 -26
- package/dist/controllers/countdown_controller.js.map +1 -1
- package/dist/controllers/currency_input_controller.d.ts +77 -16
- package/dist/controllers/currency_input_controller.js +221 -67
- package/dist/controllers/currency_input_controller.js.map +1 -1
- package/dist/controllers/data_grid_controller.d.ts +63 -18
- package/dist/controllers/data_grid_controller.js +195 -29
- package/dist/controllers/data_grid_controller.js.map +1 -1
- package/dist/controllers/date_range_picker_controller.d.ts +41 -6
- package/dist/controllers/date_range_picker_controller.js +151 -30
- package/dist/controllers/date_range_picker_controller.js.map +1 -1
- package/dist/controllers/dialog_controller.d.ts +10 -3
- package/dist/controllers/dialog_controller.js +35 -8
- package/dist/controllers/dialog_controller.js.map +1 -1
- package/dist/controllers/direct_upload_controller.js +22 -4
- package/dist/controllers/direct_upload_controller.js.map +1 -1
- package/dist/controllers/dirty_form_controller.d.ts +2 -2
- package/dist/controllers/dirty_form_controller.js +46 -13
- package/dist/controllers/dirty_form_controller.js.map +1 -1
- package/dist/controllers/dismissible_controller.js +1 -0
- package/dist/controllers/dismissible_controller.js.map +1 -1
- package/dist/controllers/drawer_controller.d.ts +18 -10
- package/dist/controllers/drawer_controller.js +54 -19
- package/dist/controllers/drawer_controller.js.map +1 -1
- package/dist/controllers/dropdown_controller.d.ts +9 -3
- package/dist/controllers/dropdown_controller.js +36 -9
- package/dist/controllers/dropdown_controller.js.map +1 -1
- package/dist/controllers/editable_controller.js +34 -0
- package/dist/controllers/editable_controller.js.map +1 -1
- package/dist/controllers/file_dropzone_controller.js +144 -51
- package/dist/controllers/file_dropzone_controller.js.map +1 -1
- package/dist/controllers/filter_controller.d.ts +10 -4
- package/dist/controllers/filter_controller.js +20 -6
- package/dist/controllers/filter_controller.js.map +1 -1
- package/dist/controllers/flash_controller.d.ts +26 -6
- package/dist/controllers/flash_controller.js +432 -71
- package/dist/controllers/flash_controller.js.map +1 -1
- package/dist/controllers/focus_controller.js +1 -0
- package/dist/controllers/focus_controller.js.map +1 -1
- package/dist/controllers/form_field_controller.js +7 -5
- package/dist/controllers/form_field_controller.js.map +1 -1
- package/dist/controllers/form_validation_controller.js +19 -13
- package/dist/controllers/form_validation_controller.js.map +1 -1
- package/dist/controllers/frame_loading_controller.js +45 -8
- package/dist/controllers/frame_loading_controller.js.map +1 -1
- package/dist/controllers/highlight_controller.js +82 -25
- package/dist/controllers/highlight_controller.js.map +1 -1
- package/dist/controllers/hover_card_controller.d.ts +10 -2
- package/dist/controllers/hover_card_controller.js +40 -14
- package/dist/controllers/hover_card_controller.js.map +1 -1
- package/dist/controllers/idle_controller.d.ts +16 -3
- package/dist/controllers/idle_controller.js +90 -5
- package/dist/controllers/idle_controller.js.map +1 -1
- package/dist/controllers/input_mask_controller.d.ts +5 -2
- package/dist/controllers/input_mask_controller.js +65 -9
- package/dist/controllers/input_mask_controller.js.map +1 -1
- package/dist/controllers/intersection_controller.js +3 -0
- package/dist/controllers/intersection_controller.js.map +1 -1
- package/dist/controllers/lazy_frame_controller.js +11 -2
- package/dist/controllers/lazy_frame_controller.js.map +1 -1
- package/dist/controllers/listbox_controller.d.ts +50 -8
- package/dist/controllers/listbox_controller.js +203 -45
- package/dist/controllers/listbox_controller.js.map +1 -1
- package/dist/controllers/local_time_controller.js +10 -5
- package/dist/controllers/local_time_controller.js.map +1 -1
- package/dist/controllers/masonry_controller.d.ts +3 -3
- package/dist/controllers/masonry_controller.js +31 -15
- package/dist/controllers/masonry_controller.js.map +1 -1
- package/dist/controllers/menu_controller.d.ts +9 -3
- package/dist/controllers/menu_controller.js +45 -16
- package/dist/controllers/menu_controller.js.map +1 -1
- package/dist/controllers/menubar_controller.d.ts +11 -0
- package/dist/controllers/menubar_controller.js +58 -24
- package/dist/controllers/menubar_controller.js.map +1 -1
- package/dist/controllers/meter_controller.js +9 -5
- package/dist/controllers/meter_controller.js.map +1 -1
- package/dist/controllers/multi_select_controller.d.ts +18 -3
- package/dist/controllers/multi_select_controller.js +278 -104
- package/dist/controllers/multi_select_controller.js.map +1 -1
- package/dist/controllers/navigation_menu_controller.d.ts +11 -0
- package/dist/controllers/navigation_menu_controller.js +48 -15
- package/dist/controllers/navigation_menu_controller.js.map +1 -1
- package/dist/controllers/nested_form_controller.js +37 -8
- package/dist/controllers/nested_form_controller.js.map +1 -1
- package/dist/controllers/network_status_controller.js +9 -1
- package/dist/controllers/network_status_controller.js.map +1 -1
- package/dist/controllers/number_input_controller.d.ts +36 -8
- package/dist/controllers/number_input_controller.js +124 -21
- package/dist/controllers/number_input_controller.js.map +1 -1
- package/dist/controllers/optimistic_controller.js +42 -5
- package/dist/controllers/optimistic_controller.js.map +1 -1
- package/dist/controllers/otp_controller.d.ts +22 -7
- package/dist/controllers/otp_controller.js +198 -55
- package/dist/controllers/otp_controller.js.map +1 -1
- package/dist/controllers/overflow_indicator_controller.d.ts +8 -12
- package/dist/controllers/overflow_indicator_controller.js +115 -21
- package/dist/controllers/overflow_indicator_controller.js.map +1 -1
- package/dist/controllers/overflow_menu_controller.d.ts +26 -6
- package/dist/controllers/overflow_menu_controller.js +141 -44
- package/dist/controllers/overflow_menu_controller.js.map +1 -1
- package/dist/controllers/pagination_controller.d.ts +19 -11
- package/dist/controllers/pagination_controller.js +74 -28
- package/dist/controllers/pagination_controller.js.map +1 -1
- package/dist/controllers/password_reveal_controller.d.ts +15 -1
- package/dist/controllers/password_reveal_controller.js +59 -2
- package/dist/controllers/password_reveal_controller.js.map +1 -1
- package/dist/controllers/persist_controller.js +30 -8
- package/dist/controllers/persist_controller.js.map +1 -1
- package/dist/controllers/pointer_drag_controller.js +131 -52
- package/dist/controllers/pointer_drag_controller.js.map +1 -1
- package/dist/controllers/popover_controller.d.ts +9 -3
- package/dist/controllers/popover_controller.js +45 -11
- package/dist/controllers/popover_controller.js.map +1 -1
- package/dist/controllers/portal_controller.d.ts +1 -1
- package/dist/controllers/portal_controller.js +6 -2
- package/dist/controllers/portal_controller.js.map +1 -1
- package/dist/controllers/preview_guard_controller.js +16 -1
- package/dist/controllers/preview_guard_controller.js.map +1 -1
- package/dist/controllers/progress_controller.js +8 -4
- package/dist/controllers/progress_controller.js.map +1 -1
- package/dist/controllers/radio_group_controller.d.ts +6 -4
- package/dist/controllers/radio_group_controller.js +42 -17
- package/dist/controllers/radio_group_controller.js.map +1 -1
- package/dist/controllers/range_slider_controller.d.ts +49 -1
- package/dist/controllers/range_slider_controller.js +88 -42
- package/dist/controllers/range_slider_controller.js.map +1 -1
- package/dist/controllers/rating_controller.d.ts +14 -3
- package/dist/controllers/rating_controller.js +39 -15
- package/dist/controllers/rating_controller.js.map +1 -1
- package/dist/controllers/read_more_controller.d.ts +24 -2
- package/dist/controllers/read_more_controller.js +100 -7
- package/dist/controllers/read_more_controller.js.map +1 -1
- package/dist/controllers/reading_progress_controller.js +65 -19
- package/dist/controllers/reading_progress_controller.js.map +1 -1
- package/dist/controllers/relative_time_controller.js +10 -5
- package/dist/controllers/relative_time_controller.js.map +1 -1
- package/dist/controllers/resizable_controller.d.ts +16 -2
- package/dist/controllers/resizable_controller.js +82 -22
- package/dist/controllers/resizable_controller.js.map +1 -1
- package/dist/controllers/scroll_area_controller.js +75 -27
- package/dist/controllers/scroll_area_controller.js.map +1 -1
- package/dist/controllers/scroll_restore_controller.js +37 -16
- package/dist/controllers/scroll_restore_controller.js.map +1 -1
- package/dist/controllers/scroll_visibility_controller.js +49 -30
- package/dist/controllers/scroll_visibility_controller.js.map +1 -1
- package/dist/controllers/scrollspy_controller.d.ts +3 -2
- package/dist/controllers/scrollspy_controller.js +71 -26
- package/dist/controllers/scrollspy_controller.js.map +1 -1
- package/dist/controllers/separator_controller.d.ts +41 -14
- package/dist/controllers/separator_controller.js +66 -37
- package/dist/controllers/separator_controller.js.map +1 -1
- package/dist/controllers/sidebar_controller.d.ts +20 -3
- package/dist/controllers/sidebar_controller.js +77 -18
- package/dist/controllers/sidebar_controller.js.map +1 -1
- package/dist/controllers/skeleton_controller.js +6 -1
- package/dist/controllers/skeleton_controller.js.map +1 -1
- package/dist/controllers/slider_controller.d.ts +45 -7
- package/dist/controllers/slider_controller.js +82 -47
- package/dist/controllers/slider_controller.js.map +1 -1
- package/dist/controllers/smart_sticky_header_controller.js +60 -26
- package/dist/controllers/smart_sticky_header_controller.js.map +1 -1
- package/dist/controllers/sortable_controller.js +17 -2
- package/dist/controllers/sortable_controller.js.map +1 -1
- package/dist/controllers/spinner_controller.js +10 -2
- package/dist/controllers/spinner_controller.js.map +1 -1
- package/dist/controllers/step_indicator_controller.d.ts +19 -17
- package/dist/controllers/step_indicator_controller.js +18 -17
- package/dist/controllers/step_indicator_controller.js.map +1 -1
- package/dist/controllers/stepper_controller.d.ts +34 -9
- package/dist/controllers/stepper_controller.js +101 -19
- package/dist/controllers/stepper_controller.js.map +1 -1
- package/dist/controllers/stick_to_bottom_controller.d.ts +19 -0
- package/dist/controllers/stick_to_bottom_controller.js +104 -8
- package/dist/controllers/stick_to_bottom_controller.js.map +1 -1
- package/dist/controllers/submit_once_controller.d.ts +3 -2
- package/dist/controllers/submit_once_controller.js +45 -9
- package/dist/controllers/submit_once_controller.js.map +1 -1
- package/dist/controllers/switch_controller.d.ts +29 -7
- package/dist/controllers/switch_controller.js +101 -10
- package/dist/controllers/switch_controller.js.map +1 -1
- package/dist/controllers/tabs_controller.d.ts +12 -0
- package/dist/controllers/tabs_controller.js +21 -2
- package/dist/controllers/tabs_controller.js.map +1 -1
- package/dist/controllers/tags_input_controller.d.ts +15 -3
- package/dist/controllers/tags_input_controller.js +209 -59
- package/dist/controllers/tags_input_controller.js.map +1 -1
- package/dist/controllers/textarea_autosize_controller.js +29 -3
- package/dist/controllers/textarea_autosize_controller.js.map +1 -1
- package/dist/controllers/theme_controller.d.ts +20 -3
- package/dist/controllers/theme_controller.js +64 -14
- package/dist/controllers/theme_controller.js.map +1 -1
- package/dist/controllers/time_picker_controller.js +23 -8
- package/dist/controllers/time_picker_controller.js.map +1 -1
- package/dist/controllers/toast_controller.d.ts +55 -15
- package/dist/controllers/toast_controller.js +451 -105
- package/dist/controllers/toast_controller.js.map +1 -1
- package/dist/controllers/toggle_group_controller.d.ts +49 -7
- package/dist/controllers/toggle_group_controller.js +159 -23
- package/dist/controllers/toggle_group_controller.js.map +1 -1
- package/dist/controllers/toolbar_controller.js +32 -0
- package/dist/controllers/toolbar_controller.js.map +1 -1
- package/dist/controllers/tooltip_controller.d.ts +8 -0
- package/dist/controllers/tooltip_controller.js +39 -13
- package/dist/controllers/tooltip_controller.js.map +1 -1
- package/dist/controllers/transition_controller.js +4 -0
- package/dist/controllers/transition_controller.js.map +1 -1
- package/dist/controllers/tree_view_controller.d.ts +39 -8
- package/dist/controllers/tree_view_controller.js +169 -16
- package/dist/controllers/tree_view_controller.js.map +1 -1
- package/dist/index.d.ts +28 -1
- package/dist/index.js +5002 -1911
- package/dist/index.js.map +1 -1
- package/dist/inspector/cli.d.ts +72 -6
- package/dist/inspector/cli.js +262 -51
- package/dist/inspector/cli.js.map +1 -1
- package/dist/inspector/cli_bin.js +309 -51
- package/dist/inspector/cli_bin.js.map +1 -1
- package/dist/inspector/examples.json +40 -40
- package/dist/inspector/manifest.json +529 -61
- package/dist/positioning/index.js +2 -0
- package/dist/positioning/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/microtask_coalescer.ts","../../src/controllers/step_indicator_controller.ts"],"names":[],"mappings":";;;;;AAqDO,IAAM,qBAAN,MAAyB;AAAA,EACrB,IAAA;AAAA,EACT,OAAA,GAAU,KAAA;AAAA,EACV,OAAA,GAAU,KAAA;AAAA,EACV,WAAA,GAAc,CAAA;AAAA;AAAA,EAGd,YAAY,GAAA,EAAiB;AAC3B,IAAA,IAAA,CAAK,IAAA,GAAO,GAAA;AAAA,EACd;AAAA;AAAA,EAGA,QAAA,GAAiB;AACf,IAAA,IAAA,CAAK,OAAA,GAAU,IAAA;AAAA,EACjB;AAAA;AAAA,EAGA,MAAA,GAAe;AACb,IAAA,IAAA,CAAK,OAAA,GAAU,KAAA;AACf,IAAA,IAAA,CAAK,OAAA,GAAU,KAAA;AACf,IAAA,IAAA,CAAK,WAAA,IAAe,CAAA;AAAA,EACtB;AAAA;AAAA,EAGA,QAAA,GAAiB;AACf,IAAA,IAAI,CAAC,IAAA,CAAK,OAAA,IAAW,IAAA,CAAK,OAAA,EAAS;AACnC,IAAA,IAAA,CAAK,OAAA,GAAU,IAAA;AACf,IAAA,MAAM,aAAa,IAAA,CAAK,WAAA;AACxB,IAAA,cAAA,CAAe,MAAM;AAEnB,MAAA,IAAI,UAAA,KAAe,KAAK,WAAA,IAAe,CAAC,KAAK,OAAA,IAAW,CAAC,KAAK,OAAA,EAAS;AACvE,MAAA,IAAA,CAAK,OAAA,GAAU,KAAA;AACf,MAAA,IAAA,CAAK,IAAA,EAAK;AAAA,IACZ,CAAC,CAAA;AAAA,EACH;AACF,CAAA;;;ACtDO,IAAM,uBAAA,GAAN,cAAsC,UAAA,CAAwB;AA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,QAAA,CAAS,KAAK,GAAG,OAAO,CAAA;AAChD,IAAA,OAAO,IAAA,CAAK,GAAA,CAAI,IAAA,EAAM,IAAA,CAAK,GAAA,CAAI,GAAG,IAAA,CAAK,KAAA,CAAM,KAAK,CAAC,CAAC,CAAA;AAAA,EACtD;AACF","file":"step_indicator_controller.js","sourcesContent":["/**\n * Collapses many Stimulus lifecycle callbacks from one DOM mutation into a\n * single pass.\n *\n * Stimulus fires `<name>TargetConnected` / `Disconnected` once per element and\n * `<name>ValueChanged` once per changed attribute. Replacing a list of N options\n * or morphing several render Values therefore delivers N callbacks — but the\n * useful unit of work is \"reconcile against the resulting declarative input\",\n * once, after the batch has settled. Every controller with reconcilable targets\n * or render Values needs the same shape: a `queued` flag plus `queueMicrotask`.\n *\n * **A microtask is the right horizon, and the reason is specific.** Stimulus\n * drives these callbacks from a `MutationObserver`, whose own callback already\n * runs as a microtask with the whole batch in hand; scheduling one more lands\n * after the last sibling callback of that batch and still before paint or any\n * event handler. A timer would be later than it needs to be, and reconciling\n * synchronously would run once per element against a half-applied DOM.\n *\n * **The two guards are not the same guard.** Scheduling is refused before the\n * controller connects, and running is refused after it disconnects:\n *\n * - **Before `connect()`** — Stimulus delivers initial target and Value callbacks\n * ahead of `connect()`. Reconciling there would compute output against a\n * controller whose own state has not been initialised, and `connect()` is\n * about to do a full pass anyway.\n * - **After `disconnect()`** — Stimulus fires a callback for **every** target\n * during teardown, and a microtask queued just before it would otherwise run\n * against a detached tree. {@link MicrotaskCoalescer.cancel} exists for the\n * teardown path to drop the pending pass outright.\n *\n * Both guards are part of one contract here rather than something each consumer\n * has to remember separately.\n *\n * Scope is the scheduling only. *What* to reconcile — keep the surviving active\n * option, fall back to the next / previous / first visible one, rebuild derived\n * chips or hidden fields — stays in the controller, because no two consumers\n * answer it the same way.\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 #reconcile = new MicrotaskCoalescer(() => this.#reconcileOptions());\n *\n * connect() { this.#reconcile.activate(); }\n * disconnect() { this.#reconcile.cancel(); }\n *\n * optionTargetConnected() { this.#reconcile.schedule(); }\n * optionTargetDisconnected() { this.#reconcile.schedule(); }\n * ```\n */\nexport class MicrotaskCoalescer {\n readonly #run: () => void;\n #queued = false;\n #active = false;\n #generation = 0;\n\n /** @param run - the single reconciliation pass, invoked at most once per batch. */\n constructor(run: () => void) {\n this.#run = run;\n }\n\n /** Opens the window in which {@link schedule} is honoured; call from `connect()`. */\n activate(): void {\n this.#active = true;\n }\n\n /** Closes the window and drops any pending pass; call from `disconnect()`. */\n cancel(): void {\n this.#active = false;\n this.#queued = false;\n this.#generation += 1;\n }\n\n /** Requests one pass after the batch settles. Idempotent; inert outside the window. */\n schedule(): void {\n if (!this.#active || this.#queued) return;\n this.#queued = true;\n const generation = this.#generation;\n queueMicrotask(() => {\n // A cancelled callback must not consume a pass queued after reconnect.\n if (generation !== this.#generation || !this.#queued || !this.#active) return;\n this.#queued = false;\n this.#run();\n });\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { MicrotaskCoalescer } from \"../utils/microtask_coalescer\";\n\n/**\n * Headless, accessible **read-only** step-progress indicator.\n *\n * Markup contract (identifier: `stimeo--step-indicator`):\n * <ol data-controller=\"stimeo--step-indicator\" aria-label=\"Checkout progress\"\n * data-stimeo--step-indicator-current-value=\"1\"\n * data-action=\"step:set->stimeo--step-indicator#setCurrent\">\n * <li data-stimeo--step-indicator-target=\"step\">Cart</li>\n * <li data-stimeo--step-indicator-target=\"step\">Shipping</li>\n * <li data-stimeo--step-indicator-target=\"step\">Payment</li>\n * </ol>\n *\n * There is no dedicated APG widget; the current position is expressed with\n * `aria-current=\"step\"`. This indicator is **read only** — it never moves focus\n * and the steps are not operable. For an interactive wizard whose steps are\n * `<button>`s, use {@link StepperController | Stepper}.\n *\n * `change` dispatches `{ current: number, total: number }`.\n *\n * @remarks\n * Behavior only. Each step `<li>` gets a `data-state` (`complete`/`current`/\n * `upcoming`) derived from the current index; the consumer draws the circles,\n * lines, and numbers from those hooks. A `--stimeo--step-indicator-ratio`\n * (0–1) custom property on the root expresses overall progress for CSS.\n *\n * Behavior provided:\n * - Reflects `current` onto each step's `data-state` and `aria-current`.\n * - Re-derives every step when the step set changes at runtime.\n * - `setCurrent` (bound to an event whose `detail.current` is the 0-based index)\n * updates the current step and dispatches `stimeo--step-indicator:change`.\n */\nexport class StepIndicatorController extends Controller<HTMLElement> {\n static override targets = [\"step\"];\n static override values = {\n current: { type: Number, default: 0 },\n };\n static actions = [\"setCurrent\"] as const;\n static events = [\"change\"] as const;\n\n declare readonly stepTargets: HTMLElement[];\n declare currentValue: number;\n\n /**\n * Collapses a batch of step callbacks — and a morph that swaps `current` with\n * them — into one repaint. Replacing a list of N steps delivers N callbacks, and\n * each one would otherwise rewrite every step's state.\n */\n readonly #repaint = new MicrotaskCoalescer(() => this.#render());\n\n /** Renders the initial state from the `current` value. */\n override connect(): void {\n this.#repaint.activate();\n this.#render();\n }\n\n /** Closes the window in which a queued repaint may still run. */\n override disconnect(): void {\n this.#repaint.cancel();\n }\n\n /** Syncs a step appended or replaced at runtime (the consumer owns the list). */\n stepTargetConnected(): void {\n this.#repaint.schedule();\n }\n\n /** Re-derives the remaining steps when one is removed at runtime. */\n stepTargetDisconnected(): void {\n this.#repaint.schedule();\n }\n\n /** Repaints when application code (or a Turbo morph) changes `current` at runtime. */\n currentValueChanged(): void {\n this.#repaint.schedule();\n }\n\n /**\n * Updates the current step from an external event (`detail.current`, 0-based)\n * and dispatches `change`. Out-of-range indices are clamped to the step set,\n * and both sides of the no-op test are clamped, so moving onto the step an\n * out-of-range `current` already renders is not reported as a change.\n */\n setCurrent(event: CustomEvent<{ current?: number }>): void {\n const next = event.detail?.current;\n if (typeof next !== \"number\" || !Number.isFinite(next)) return;\n const clamped = this.#clamp(next);\n const moved = clamped !== this.#clamp(this.currentValue);\n // Normalise even when the display does not move: an out-of-range `current` left\n // in the markup would otherwise be re-clamped against a later step set and land\n // somewhere the consumer never asked for. Writing it here is the consumer-driven\n // path, the only one that owns the Value.\n this.currentValue = clamped;\n if (!moved) return;\n this.#render();\n this.dispatch(\"change\", {\n detail: { current: clamped, total: this.stepTargets.length },\n });\n }\n\n /**\n * Applies `data-state`, `aria-current`, and the progress ratio custom property.\n *\n * A pure function of the step set and `current`, so running it again writes the\n * same values — which is what lets the action path paint synchronously (the event\n * goes out after the DOM is updated) while a coalesced pass may still follow.\n *\n * @stimeoRenderRoot\n */\n #render(): void {\n const total = this.stepTargets.length;\n const current = this.#clamp(this.currentValue);\n this.stepTargets.forEach((step, index) => {\n step.dataset.state =\n index < current ? \"complete\" : index === current ? \"current\" : \"upcoming\";\n if (index === current) {\n step.setAttribute(\"aria-current\", \"step\");\n } else {\n step.removeAttribute(\"aria-current\");\n }\n });\n const ratio = total > 1 ? current / (total - 1) : 0;\n this.element.style.setProperty(\"--stimeo--step-indicator-ratio\", String(ratio));\n }\n\n /**\n * Constrains an index to `[0, total-1]` (or `0` when there are no steps). A\n * non-finite index falls back to the first step: `current` is read from markup,\n * so an unparsable attribute arrives as `NaN` and would otherwise propagate\n * into every state hook.\n */\n #clamp(index: number): number {\n const last = this.stepTargets.length - 1;\n if (last < 0 || !Number.isFinite(index)) return 0;\n return Math.min(last, Math.max(0, Math.trunc(index)));\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/microtask_coalescer.ts","../../src/controllers/step_indicator_controller.ts"],"names":[],"mappings":";;;;;AAqDO,IAAM,qBAAN,MAAyB;AAAA,EACrB,IAAA;AAAA,EACT,OAAA,GAAU,KAAA;AAAA,EACV,OAAA,GAAU,KAAA;AAAA,EACV,WAAA,GAAc,CAAA;AAAA;AAAA,EAGd,YAAY,GAAA,EAAiB;AAC3B,IAAA,IAAA,CAAK,IAAA,GAAO,GAAA;AAAA,EACd;AAAA;AAAA,EAGA,QAAA,GAAiB;AACf,IAA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Y,OAAA,CAAQ,CAAC,IAAA,EAAM,KAAA,KAAU;AACxC,MAAA,IAAA,CAAK,QAAQ,KAAA,GACX,KAAA,GAAQ,UAAU,UAAA,GAAa,KAAA,KAAU,UAAU,SAAA,GAAY,UAAA;AACjE,MAAA,IAAI,UAAU,OAAA,EAAS;AACrB,QAAA,IAAA,CAAK,YAAA,CAAa,gBAAgB,MAAM,CAAA;AAAA,MAC1C,CAAA,MAAO;AACL,QAAA,IAAA,CAAK,gBAAgB,cAAc,CAAA;AAAA,MACrC;AAAA,IACF,CAAC,CAAA;AACD,IAAA,MAAM,KAAA,GAAQ,KAAA,GAAQ,CAAA,GAAI,OAAA,IAAW,QAAQ,CAAA,CAAA,GAAK,CAAA;AAClD,IAAA,IAAA,CAAK,QAAQ,KAAA,CAAM,WAAA,CAAY,gCAAA,EAAkC,MAAA,CAAO,KAAK,CAAC,CAAA;AAAA,EAChF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,KAAA,EAAuB;AAC5B,IAAA,MAAM,IAAA,GAAO,IAAA,CAAK,WAAA,CAAY,MAAA,GAAS,CAAA;AACvC,IAAA,IAAI,OAAO,CAAA,IAAK,CAAC,OAAO,QAAA,CAAS,KAAK,GAAG,OAAO,CAAA;AAChD,IAAA,OAAO,IAAA,CAAK,GAAA,CAAI,IAAA,EAAM,IAAA,CAAK,GAAA,CAAI,GAAG,IAAA,CAAK,KAAA,CAAM,KAAK,CAAC,CAAC,CAAA;AAAA,EACtD;AACF","file":"step_indicator_controller.js","sourcesContent":["/**\n * Collapses many Stimulus lifecycle callbacks from one DOM mutation into a\n * single pass.\n *\n * Stimulus fires `<name>TargetConnected` / `Disconnected` once per element and\n * `<name>ValueChanged` once per changed attribute. Replacing a list of N options\n * or morphing several render Values therefore delivers N callbacks — but the\n * useful unit of work is \"reconcile against the resulting declarative input\",\n * once, after the batch has settled. Every controller with reconcilable targets\n * or render Values needs the same shape: a `queued` flag plus `queueMicrotask`.\n *\n * **A microtask is the right horizon, and the reason is specific.** Stimulus\n * drives these callbacks from a `MutationObserver`, whose own callback already\n * runs as a microtask with the whole batch in hand; scheduling one more lands\n * after the last sibling callback of that batch and still before paint or any\n * event handler. A timer would be later than it needs to be, and reconciling\n * synchronously would run once per element against a half-applied DOM.\n *\n * **The two guards are not the same guard.** Scheduling is refused before the\n * controller connects, and running is refused after it disconnects:\n *\n * - **Before `connect()`** — Stimulus delivers initial target and Value callbacks\n * ahead of `connect()`. Reconciling there would compute output against a\n * controller whose own state has not been initialised, and `connect()` is\n * about to do a full pass anyway.\n * - **After `disconnect()`** — Stimulus fires a callback for **every** target\n * during teardown, and a microtask queued just before it would otherwise run\n * against a detached tree. {@link MicrotaskCoalescer.cancel} exists for the\n * teardown path to drop the pending pass outright.\n *\n * Both guards are part of one contract here rather than something each consumer\n * has to remember separately.\n *\n * Scope is the scheduling only. *What* to reconcile — keep the surviving active\n * option, fall back to the next / previous / first visible one, rebuild derived\n * chips or hidden fields — stays in the controller, because no two consumers\n * answer it the same way.\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 #reconcile = new MicrotaskCoalescer(() => this.#reconcileOptions());\n *\n * connect() { this.#reconcile.activate(); }\n * disconnect() { this.#reconcile.cancel(); }\n *\n * optionTargetConnected() { this.#reconcile.schedule(); }\n * optionTargetDisconnected() { this.#reconcile.schedule(); }\n * ```\n */\nexport class MicrotaskCoalescer {\n readonly #run: () => void;\n #queued = false;\n #active = false;\n #generation = 0;\n\n /** @param run - the single reconciliation pass, invoked at most once per batch. */\n constructor(run: () => void) {\n this.#run = run;\n }\n\n /** Opens the window in which {@link schedule} is honoured; call from `connect()`. */\n activate(): void {\n this.#active = true;\n }\n\n /** Closes the window and drops any pending pass; call from `disconnect()`. */\n cancel(): void {\n this.#active = false;\n this.#queued = false;\n this.#generation += 1;\n }\n\n /** Requests one pass after the batch settles. Idempotent; inert outside the window. */\n schedule(): void {\n if (!this.#active || this.#queued) return;\n this.#queued = true;\n const generation = this.#generation;\n queueMicrotask(() => {\n // A cancelled callback must not consume a pass queued after reconnect.\n if (generation !== this.#generation || !this.#queued || !this.#active) return;\n this.#queued = false;\n this.#run();\n });\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { MicrotaskCoalescer } from \"../utils/microtask_coalescer\";\n\n/**\n * Headless, accessible **read-only** step-progress indicator.\n *\n * Markup contract (identifier: `stimeo--step-indicator`):\n * <ol data-controller=\"stimeo--step-indicator\" aria-label=\"Checkout progress\"\n * data-stimeo--step-indicator-index-value=\"1\"\n * data-action=\"stimeo--stepper:change->stimeo--step-indicator#setIndex\">\n * <li data-stimeo--step-indicator-target=\"step\">Cart</li>\n * <li data-stimeo--step-indicator-target=\"step\">Shipping</li>\n * <li data-stimeo--step-indicator-target=\"step\">Payment</li>\n * </ol>\n *\n * There is no dedicated APG widget; the current position is expressed with\n * `aria-current=\"step\"`. This indicator is **read only** — it never moves focus\n * and the steps are not operable. For an interactive wizard whose steps are\n * `<button>`s, use {@link StepperController | Stepper}.\n *\n * `change` dispatches `{ index: number, previous: number, total: number }`.\n *\n * @remarks\n * Behavior only. Each step `<li>` gets a `data-state` (`complete`/`current`/\n * `upcoming`) derived from the current index; the consumer draws the circles,\n * lines, and numbers from those hooks. A `--stimeo--step-indicator-ratio`\n * (0–1) custom property on the root expresses overall progress for CSS.\n *\n * Behavior provided:\n * - Reflects `index` onto each step's `data-state` and `aria-current`.\n * - Re-derives every step when the step set changes at runtime.\n * - `setIndex` (bound to an event whose `detail.index` is the 0-based position)\n * moves the indicator and dispatches `stimeo--step-indicator:change`. A\n * {@link StepperController | Stepper} dispatches exactly that shape, so the two\n * compose with one `data-action` and no glue.\n */\nexport class StepIndicatorController extends Controller<HTMLElement> {\n static override targets = [\"step\"];\n static override values = {\n index: { type: Number, default: 0 },\n };\n static actions = [\"setIndex\"] as const;\n static events = [\"change\"] as const;\n\n declare readonly stepTargets: HTMLElement[];\n declare indexValue: number;\n\n /**\n * Collapses a batch of step callbacks — and a morph that swaps `index` with\n * them — into one repaint. Replacing a list of N steps delivers N callbacks, and\n * each one would otherwise rewrite every step's state.\n */\n readonly #repaint = new MicrotaskCoalescer(() => this.#render());\n\n /** Renders the initial state from the `index` value. */\n override connect(): void {\n this.#repaint.activate();\n this.#render();\n }\n\n /** Closes the window in which a queued repaint may still run. */\n override disconnect(): void {\n this.#repaint.cancel();\n }\n\n /** Syncs a step appended or replaced at runtime (the consumer owns the list). */\n stepTargetConnected(): void {\n this.#repaint.schedule();\n }\n\n /** Re-derives the remaining steps when one is removed at runtime. */\n stepTargetDisconnected(): void {\n this.#repaint.schedule();\n }\n\n /** Repaints when application code (or a Turbo morph) changes `index` at runtime. */\n indexValueChanged(): void {\n this.#repaint.schedule();\n }\n\n /**\n * Moves the indicator from an external event (`detail.index`, 0-based) and\n * dispatches `change`. Out-of-range positions are clamped to the step set,\n * and both sides of the no-op test are clamped, so moving onto the step an\n * out-of-range `index` already renders is not reported as a change.\n */\n setIndex(event: CustomEvent<{ index?: number }>): void {\n const next = event.detail?.index;\n if (typeof next !== \"number\" || !Number.isFinite(next)) return;\n const clamped = this.#clamp(next);\n const previous = this.#clamp(this.indexValue);\n const moved = clamped !== previous;\n // Normalise even when the display does not move: an out-of-range `index` left\n // in the markup would otherwise be re-clamped against a later step set and land\n // somewhere the consumer never asked for. Writing it here is the consumer-driven\n // path, the only one that owns the Value.\n this.indexValue = clamped;\n if (!moved) return;\n this.#render();\n this.dispatch(\"change\", {\n detail: { index: clamped, previous, total: this.stepTargets.length },\n });\n }\n\n /**\n * Applies `data-state`, `aria-current`, and the progress ratio custom property.\n *\n * A pure function of the step set and `index`, so running it again writes the\n * same values — which is what lets the action path paint synchronously (the event\n * goes out after the DOM is updated) while a coalesced pass may still follow.\n *\n * @stimeoRenderRoot\n */\n #render(): void {\n const total = this.stepTargets.length;\n const current = this.#clamp(this.indexValue);\n this.stepTargets.forEach((step, index) => {\n step.dataset.state =\n index < current ? \"complete\" : index === current ? \"current\" : \"upcoming\";\n if (index === current) {\n step.setAttribute(\"aria-current\", \"step\");\n } else {\n step.removeAttribute(\"aria-current\");\n }\n });\n const ratio = total > 1 ? current / (total - 1) : 0;\n this.element.style.setProperty(\"--stimeo--step-indicator-ratio\", String(ratio));\n }\n\n /**\n * Constrains an index to `[0, total-1]` (or `0` when there are no steps). A\n * non-finite index falls back to the first step: `index` is read from markup,\n * so an unparsable attribute arrives as `NaN` and would otherwise propagate\n * into every state hook.\n */\n #clamp(index: number): number {\n const last = this.stepTargets.length - 1;\n if (last < 0 || !Number.isFinite(index)) return 0;\n return Math.min(last, Math.max(0, Math.trunc(index)));\n }\n}\n"]}
|
|
@@ -16,21 +16,37 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
16
16
|
* `aria-current="step"` on the operable `<button>`. Each step `<li>` also gets a
|
|
17
17
|
* `data-state` (`complete`/`current`/`upcoming`) derived from the current index.
|
|
18
18
|
* For a read-only progress display use
|
|
19
|
-
* {@link StepIndicatorController | Step Indicator}; for panel switching use
|
|
19
|
+
* {@link StepIndicatorController | Step Indicator}; for panel switching use
|
|
20
|
+
* {@link TabsController | Tabs}.
|
|
20
21
|
*
|
|
21
|
-
* `change` dispatches `{ index: number, previous: number, step: HTMLElement }
|
|
22
|
+
* `change` dispatches `{ index: number, previous: number, total: number, step: HTMLElement }`,
|
|
23
|
+
* and `reconcile` dispatches the same
|
|
24
|
+
* `{ index: number, previous: number, total: number, step: HTMLElement }` — `previous`
|
|
25
|
+
* is the position shown before — when a change the page made moves the position of
|
|
26
|
+
* the current step (the clamped `index`).
|
|
22
27
|
*
|
|
23
28
|
* @remarks
|
|
24
29
|
* Behavior only. The controller never traps or restores focus — each step button
|
|
25
|
-
* is in the natural Tab order. `data-state` is purely derived from `index`
|
|
26
|
-
* (completion is not persisted).
|
|
30
|
+
* is in the natural Tab order. `data-state` is purely derived from `index` and the
|
|
31
|
+
* steps present (completion is not persisted).
|
|
27
32
|
*
|
|
28
33
|
* Behavior provided:
|
|
29
34
|
* - `next`/`prev` move one step, ignoring moves past either end.
|
|
30
35
|
* - `goto` jumps to the step in its `index` action param.
|
|
31
36
|
* - With `linear=true`, `goto` may not skip more than one step ahead of the
|
|
32
37
|
* current one (moving backward is always allowed).
|
|
33
|
-
* - Runtime changes to the `index` Value
|
|
38
|
+
* - Runtime changes to the `index` Value, and steps added or removed at runtime,
|
|
39
|
+
* re-derive every step's state once per batch. Once connected, a batch that
|
|
40
|
+
* moves the current position (the clamped `index`) away from the one shown
|
|
41
|
+
* reports `stimeo--stepper:reconcile` once. A batch that leaves the position
|
|
42
|
+
* where it was reports nothing, even when another step now stands there — a
|
|
43
|
+
* step added before the current one, or the current step removed while
|
|
44
|
+
* another follows it — and only redraws `data-state`/`aria-current`;
|
|
45
|
+
* connecting reports nothing.
|
|
46
|
+
* - An `index` outside the step range, fractional, or not a number at all is
|
|
47
|
+
* clamped for display only. The Value keeps what the page declared, so the
|
|
48
|
+
* declared step comes back once enough steps are present; a move the user makes
|
|
49
|
+
* is the one path that writes it.
|
|
34
50
|
* - Each move re-derives `data-state`/`aria-current` and dispatches
|
|
35
51
|
* `stimeo--stepper:change`.
|
|
36
52
|
*/
|
|
@@ -48,23 +64,32 @@ declare class StepperController extends Controller<HTMLElement> {
|
|
|
48
64
|
};
|
|
49
65
|
};
|
|
50
66
|
static actions: readonly ["goto", "next", "prev"];
|
|
51
|
-
static events: readonly ["change"];
|
|
67
|
+
static events: readonly ["change", "reconcile"];
|
|
52
68
|
readonly stepTargets: HTMLElement[];
|
|
53
69
|
indexValue: number;
|
|
54
70
|
linearValue: boolean;
|
|
55
|
-
/**
|
|
71
|
+
/** Renders the initial state from `index`, clamped into the step range. */
|
|
56
72
|
connect(): void;
|
|
73
|
+
/** Drops a pending pass, so nothing renders or reports for a stepper that left. */
|
|
57
74
|
disconnect(): void;
|
|
58
75
|
/** Re-renders when Turbo Morph or application code changes `index` at runtime. */
|
|
59
76
|
indexValueChanged(): void;
|
|
77
|
+
/** Re-derives every step's state for a step added at runtime. */
|
|
78
|
+
stepTargetConnected(): void;
|
|
79
|
+
/** Re-derives every step's state for a step removed at runtime. */
|
|
80
|
+
stepTargetDisconnected(): void;
|
|
60
81
|
/** Advances to the next step (ignored at the last step). */
|
|
61
82
|
next(): void;
|
|
62
83
|
/** Returns to the previous step (ignored at the first step). */
|
|
63
84
|
prev(): void;
|
|
64
|
-
/**
|
|
85
|
+
/**
|
|
86
|
+
* Jumps to the step carried in the action's `index` param. A param that is empty,
|
|
87
|
+
* or that Stimulus parses into anything but a number or a string, is no index,
|
|
88
|
+
* so it jumps nowhere.
|
|
89
|
+
*/
|
|
65
90
|
goto(event: {
|
|
66
91
|
params: {
|
|
67
|
-
index?:
|
|
92
|
+
index?: unknown;
|
|
68
93
|
};
|
|
69
94
|
}): void;
|
|
70
95
|
}
|
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
import { Controller } from '@hotwired/stimulus';
|
|
2
2
|
|
|
3
|
+
// src/controllers/stepper_controller.ts
|
|
4
|
+
|
|
5
|
+
// src/utils/microtask_coalescer.ts
|
|
6
|
+
var MicrotaskCoalescer = class {
|
|
7
|
+
#run;
|
|
8
|
+
#queued = false;
|
|
9
|
+
#active = false;
|
|
10
|
+
#generation = 0;
|
|
11
|
+
/** @param run - the single reconciliation pass, invoked at most once per batch. */
|
|
12
|
+
constructor(run) {
|
|
13
|
+
this.#run = run;
|
|
14
|
+
}
|
|
15
|
+
/** Opens the window in which {@link schedule} is honoured; call from `connect()`. */
|
|
16
|
+
activate() {
|
|
17
|
+
this.#active = true;
|
|
18
|
+
}
|
|
19
|
+
/** Closes the window and drops any pending pass; call from `disconnect()`. */
|
|
20
|
+
cancel() {
|
|
21
|
+
this.#active = false;
|
|
22
|
+
this.#queued = false;
|
|
23
|
+
this.#generation += 1;
|
|
24
|
+
}
|
|
25
|
+
/** Requests one pass after the batch settles. Idempotent; inert outside the window. */
|
|
26
|
+
schedule() {
|
|
27
|
+
if (!this.#active || this.#queued) return;
|
|
28
|
+
this.#queued = true;
|
|
29
|
+
const generation = this.#generation;
|
|
30
|
+
queueMicrotask(() => {
|
|
31
|
+
if (generation !== this.#generation || !this.#queued || !this.#active) return;
|
|
32
|
+
this.#queued = false;
|
|
33
|
+
this.#run();
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
3
38
|
// src/controllers/stepper_controller.ts
|
|
4
39
|
var StepperController = class extends Controller {
|
|
5
40
|
static targets = ["step"];
|
|
@@ -8,20 +43,39 @@ var StepperController = class extends Controller {
|
|
|
8
43
|
linear: { type: Boolean, default: false }
|
|
9
44
|
};
|
|
10
45
|
static actions = ["goto", "next", "prev"];
|
|
11
|
-
static events = ["change"];
|
|
12
|
-
|
|
13
|
-
|
|
46
|
+
static events = ["change", "reconcile"];
|
|
47
|
+
/**
|
|
48
|
+
* Collapses the Value and target callbacks of one mutation into one pass, and
|
|
49
|
+
* refuses the ones Stimulus delivers before `connect()`, which renders itself.
|
|
50
|
+
*/
|
|
51
|
+
#repaint = new MicrotaskCoalescer(() => this.#reconcileStep());
|
|
52
|
+
/**
|
|
53
|
+
* The position shown current last, which the next move is measured from, or
|
|
54
|
+
* `null` before any step has been shown. While no step is present it keeps the
|
|
55
|
+
* last one.
|
|
56
|
+
*/
|
|
57
|
+
#shown = null;
|
|
58
|
+
/** Renders the initial state from `index`, clamped into the step range. */
|
|
14
59
|
connect() {
|
|
15
|
-
this.#
|
|
16
|
-
this.#
|
|
60
|
+
this.#repaint.activate();
|
|
61
|
+
this.#shown = this.#currentStep;
|
|
62
|
+
this.#render();
|
|
17
63
|
}
|
|
64
|
+
/** Drops a pending pass, so nothing renders or reports for a stepper that left. */
|
|
18
65
|
disconnect() {
|
|
19
|
-
this.#
|
|
66
|
+
this.#repaint.cancel();
|
|
20
67
|
}
|
|
21
68
|
/** Re-renders when Turbo Morph or application code changes `index` at runtime. */
|
|
22
69
|
indexValueChanged() {
|
|
23
|
-
|
|
24
|
-
|
|
70
|
+
this.#repaint.schedule();
|
|
71
|
+
}
|
|
72
|
+
/** Re-derives every step's state for a step added at runtime. */
|
|
73
|
+
stepTargetConnected() {
|
|
74
|
+
this.#repaint.schedule();
|
|
75
|
+
}
|
|
76
|
+
/** Re-derives every step's state for a step removed at runtime. */
|
|
77
|
+
stepTargetDisconnected() {
|
|
78
|
+
this.#repaint.schedule();
|
|
25
79
|
}
|
|
26
80
|
/** Advances to the next step (ignored at the last step). */
|
|
27
81
|
next() {
|
|
@@ -31,9 +85,16 @@ var StepperController = class extends Controller {
|
|
|
31
85
|
prev() {
|
|
32
86
|
this.#moveTo(this.#clampIndex(this.indexValue) - 1);
|
|
33
87
|
}
|
|
34
|
-
/**
|
|
88
|
+
/**
|
|
89
|
+
* Jumps to the step carried in the action's `index` param. A param that is empty,
|
|
90
|
+
* or that Stimulus parses into anything but a number or a string, is no index,
|
|
91
|
+
* so it jumps nowhere.
|
|
92
|
+
*/
|
|
35
93
|
goto(event) {
|
|
36
|
-
const
|
|
94
|
+
const { index } = event.params;
|
|
95
|
+
if (index === "") return;
|
|
96
|
+
if (typeof index !== "number" && typeof index !== "string") return;
|
|
97
|
+
const target = Number(index);
|
|
37
98
|
if (!Number.isFinite(target) || !Number.isInteger(target)) return;
|
|
38
99
|
this.#moveTo(target);
|
|
39
100
|
}
|
|
@@ -51,19 +112,39 @@ var StepperController = class extends Controller {
|
|
|
51
112
|
if (this.linearValue && target > current + 1) return;
|
|
52
113
|
const previous = current;
|
|
53
114
|
this.indexValue = target;
|
|
54
|
-
this.#
|
|
115
|
+
this.#shown = target;
|
|
116
|
+
this.#render();
|
|
55
117
|
this.dispatch("change", {
|
|
56
|
-
detail: { index: target, previous, step: this.stepTargets[target] }
|
|
118
|
+
detail: { index: target, previous, total, step: this.stepTargets[target] }
|
|
57
119
|
});
|
|
58
120
|
}
|
|
59
|
-
/**
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
121
|
+
/**
|
|
122
|
+
* Re-derives one settled batch of Value and target changes, and reports a
|
|
123
|
+
* current position that moved from the one shown before as `reconcile`. With no
|
|
124
|
+
* step present there is nothing to report, and the position shown last stays the
|
|
125
|
+
* one the next move is measured from.
|
|
126
|
+
*/
|
|
127
|
+
#reconcileStep() {
|
|
128
|
+
const previous = this.#shown;
|
|
129
|
+
const index = this.#currentStep;
|
|
130
|
+
if (index !== null) this.#shown = index;
|
|
131
|
+
this.#render();
|
|
132
|
+
if (index === null || previous === null || index === previous) return;
|
|
133
|
+
const steps = this.stepTargets;
|
|
134
|
+
this.dispatch("reconcile", {
|
|
135
|
+
detail: { index, previous, total: steps.length, step: steps[index] }
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
/** The current position, clamped into the step range, or `null` when there is no step. */
|
|
139
|
+
get #currentStep() {
|
|
140
|
+
return this.stepTargets.length > 0 ? this.#clampIndex(this.indexValue) : null;
|
|
64
141
|
}
|
|
65
142
|
/**
|
|
66
|
-
* Derives each step's `data-state` and the current button's `aria-current
|
|
143
|
+
* Derives each step's `data-state` and the current button's `aria-current` from
|
|
144
|
+
* `index`, clamped into the step range, without dispatching an action event.
|
|
145
|
+
*
|
|
146
|
+
* The clamp decides only what is shown. This body never writes `index`, so an
|
|
147
|
+
* out-of-range declaration stays in the attribute as the page wrote it.
|
|
67
148
|
*
|
|
68
149
|
* `aria-current="step"` is placed on the step's **first** `<button>`; the markup
|
|
69
150
|
* contract assumes one operable button per step. If a step needs multiple
|
|
@@ -71,7 +152,8 @@ var StepperController = class extends Controller {
|
|
|
71
152
|
*
|
|
72
153
|
* @stimeoRenderRoot
|
|
73
154
|
*/
|
|
74
|
-
#render(
|
|
155
|
+
#render() {
|
|
156
|
+
const current = this.#clampIndex(this.indexValue);
|
|
75
157
|
this.stepTargets.forEach((step, index) => {
|
|
76
158
|
step.dataset.state = index < current ? "complete" : index === current ? "current" : "upcoming";
|
|
77
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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,QAAQ,OAAA,EAAuB;AAC7B,IAAA,IAAA,CAAK,WAAA,CAAY,OAAA,CAAQ,CAAC,IAAA,EAAM,KAAA,KAAU;AACxC,MAAA,IAAA,CAAK,QAAQ,KAAA,GACX,KAAA,GAAQ,UAAU,UAAA,GAAa,KAAA,KAAU,UAAU,SAAA,GAAY,UAAA;AACjE,MAAA,MAAM,MAAA,GAAS,IAAA,CAAK,aAAA,CAA2B,QAAQ,CAAA;AACvD,MAAA,IAAI,CAAC,MAAA,EAAQ;AACb,MAAA,IAAI,UAAU,OAAA,EAAS;AACrB,QAAA,MAAA,CAAO,YAAA,CAAa,gBAAgB,MAAM,CAAA;AAAA,MAC5C,CAAA,MAAO;AACL,QAAA,MAAA,CAAO,gBAAgB,cAAc,CAAA;AAAA,MACvC;AAAA,IACF,CAAC,CAAA;AAAA,EACH;AAAA;AAAA,EAGA,YAAY,KAAA,EAAuB;AACjC,IAAA,MAAM,IAAA,GAAO,IAAA,CAAK,WAAA,CAAY,MAAA,GAAS,CAAA;AACvC,IAAA,IAAI,OAAO,CAAA,IAAK,CAAC,OAAO,QAAA,CAAS,KAAK,GAAG,OAAO,CAAA;AAChD,IAAA,OAAO,IAAA,CAAK,GAAA,CAAI,IAAA,EAAM,IAAA,CAAK,GAAA,CAAI,GAAG,IAAA,CAAK,KAAA,CAAM,KAAK,CAAC,CAAC,CAAA;AAAA,EACtD;AACF","file":"stepper_controller.js","sourcesContent":["import { Controller } from \"@hotwired/stimulus\";\n\n/**\n * Headless, accessible stepper / wizard navigation behavior.\n *\n * Markup contract (identifier: `stimeo--stepper`):\n * <ol data-controller=\"stimeo--stepper\" data-stimeo--stepper-index-value=\"0\">\n * <li data-stimeo--stepper-target=\"step\">\n * <button aria-current=\"step\" data-stimeo--stepper-index-param=\"0\"\n * data-action=\"click->stimeo--stepper#goto\">Account</button>\n * </li>\n * <!-- more steps -->\n * </ol>\n *\n * There is no dedicated APG widget; the current step is expressed with\n * `aria-current=\"step\"` on the operable `<button>`. Each step `<li>` also gets a\n * `data-state` (`complete`/`current`/`upcoming`) derived from the current index.\n * For a read-only progress display use\n * {@link StepIndicatorController | Step Indicator}; for panel switching use Tabs.\n *\n * `change` dispatches `{ index: number, previous: number, step: HTMLElement }`.\n *\n * @remarks\n * Behavior only. The controller never traps or restores focus — each step button\n * is in the natural Tab order. `data-state` is purely derived from `index`\n * (completion is not persisted).\n *\n * Behavior provided:\n * - `next`/`prev` move one step, ignoring moves past either end.\n * - `goto` jumps to the step in its `index` action param.\n * - With `linear=true`, `goto` may not skip more than one step ahead of the\n * current one (moving backward is always allowed).\n * - Runtime changes to the `index` Value re-derive every step's state.\n * - Each move re-derives `data-state`/`aria-current` and dispatches\n * `stimeo--stepper:change`.\n */\nexport class StepperController extends Controller<HTMLElement> {\n static override targets = [\"step\"];\n static override values = {\n index: { type: Number, default: 0 },\n linear: { type: Boolean, default: false },\n };\n static actions = [\"goto\", \"next\", \"prev\"] as const;\n static events = [\"change\"] as const;\n\n declare readonly stepTargets: HTMLElement[];\n declare indexValue: number;\n declare linearValue: boolean;\n\n #isConnected = false;\n\n /** Normalizes an out-of-range initial `index` and renders the initial state. */\n override connect(): void {\n this.#isConnected = true;\n this.#normalizeAndRender();\n }\n\n override disconnect(): void {\n this.#isConnected = false;\n }\n\n /** Re-renders when Turbo Morph or application code changes `index` at runtime. */\n indexValueChanged(): void {\n if (!this.#isConnected) return;\n this.#normalizeAndRender();\n }\n\n /** Advances to the next step (ignored at the last step). */\n next(): void {\n this.#moveTo(this.#clampIndex(this.indexValue) + 1);\n }\n\n /** Returns to the previous step (ignored at the first step). */\n prev(): void {\n this.#moveTo(this.#clampIndex(this.indexValue) - 1);\n }\n\n /** Jumps to the step carried in the action's `index` param. */\n goto(event: { params: { index?: number } }): void {\n const target = Number(event.params.index);\n if (!Number.isFinite(target) || !Number.isInteger(target)) return;\n this.#moveTo(target);\n }\n\n /**\n * Moves the current step to `target` when allowed: in range, not a no-op, and\n * — under `linear` — not skipping more than one step ahead. Re-renders and\n * dispatches `change`.\n */\n #moveTo(target: number): void {\n const total = this.stepTargets.length;\n if (!Number.isFinite(target) || !Number.isInteger(target)) return;\n if (target < 0 || target >= total) return;\n const current = this.#clampIndex(this.indexValue);\n if (target === current) return;\n if (this.linearValue && target > current + 1) return;\n\n const previous = current;\n this.indexValue = target;\n this.#render(target);\n this.dispatch(\"change\", {\n detail: { index: target, previous, step: this.stepTargets[target] },\n });\n }\n\n /** Normalizes the public Value and reflects it without dispatching an action event. */\n #normalizeAndRender(): void {\n const normalized = this.#clampIndex(this.indexValue);\n if (!Object.is(normalized, this.indexValue)) this.indexValue = normalized;\n this.#render(normalized);\n }\n\n /**\n * Derives each step's `data-state` and the current button's `aria-current`.\n *\n * `aria-current=\"step\"` is placed on the step's **first** `<button>`; the markup\n * contract assumes one operable button per step. If a step needs multiple\n * buttons, mark the navigational one first (or this would target the wrong one).\n *\n * @stimeoRenderRoot\n */\n #render(current: number): void {\n this.stepTargets.forEach((step, index) => {\n step.dataset.state =\n index < current ? \"complete\" : index === current ? \"current\" : \"upcoming\";\n const button = step.querySelector<HTMLElement>(\"button\");\n if (!button) return;\n if (index === current) {\n button.setAttribute(\"aria-current\", \"step\");\n } else {\n button.removeAttribute(\"aria-current\");\n }\n });\n }\n\n /** Constrains an index to `[0, total-1]` (or `0` when there are no steps). */\n #clampIndex(index: number): number {\n const last = this.stepTargets.length - 1;\n if (last < 0 || !Number.isFinite(index)) return 0;\n return Math.min(last, Math.max(0, Math.trunc(index)));\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/microtask_coalescer.ts","../../src/controllers/stepper_controller.ts"],"names":[],"mappings":";;;;;AAqDO,IAAM,qBAAN,MAAyB;AAAA,EACrB,IAAA;AAAA,EACT,OAAA,GAAU,KAAA;AAAA,EACV,OAAA,GAAU,KAAA;AAAA,EACV,WAAA,GAAc,CAAA;AAAA;AAA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A;AACvC,IAAA,IAAI,OAAO,CAAA,IAAK,CAAC,OAAO,QAAA,CAAS,KAAK,GAAG,OAAO,CAAA;AAChD,IAAA,OAAO,IAAA,CAAK,GAAA,CAAI,IAAA,EAAM,IAAA,CAAK,GAAA,CAAI,GAAG,IAAA,CAAK,KAAA,CAAM,KAAK,CAAC,CAAC,CAAA;AAAA,EACtD;AACF","file":"stepper_controller.js","sourcesContent":["/**\n * Collapses many Stimulus lifecycle callbacks from one DOM mutation into a\n * single pass.\n *\n * Stimulus fires `<name>TargetConnected` / `Disconnected` once per element and\n * `<name>ValueChanged` once per changed attribute. Replacing a list of N options\n * or morphing several render Values therefore delivers N callbacks — but the\n * useful unit of work is \"reconcile against the resulting declarative input\",\n * once, after the batch has settled. Every controller with reconcilable targets\n * or render Values needs the same shape: a `queued` flag plus `queueMicrotask`.\n *\n * **A microtask is the right horizon, and the reason is specific.** Stimulus\n * drives these callbacks from a `MutationObserver`, whose own callback already\n * runs as a microtask with the whole batch in hand; scheduling one more lands\n * after the last sibling callback of that batch and still before paint or any\n * event handler. A timer would be later than it needs to be, and reconciling\n * synchronously would run once per element against a half-applied DOM.\n *\n * **The two guards are not the same guard.** Scheduling is refused before the\n * controller connects, and running is refused after it disconnects:\n *\n * - **Before `connect()`** — Stimulus delivers initial target and Value callbacks\n * ahead of `connect()`. Reconciling there would compute output against a\n * controller whose own state has not been initialised, and `connect()` is\n * about to do a full pass anyway.\n * - **After `disconnect()`** — Stimulus fires a callback for **every** target\n * during teardown, and a microtask queued just before it would otherwise run\n * against a detached tree. {@link MicrotaskCoalescer.cancel} exists for the\n * teardown path to drop the pending pass outright.\n *\n * Both guards are part of one contract here rather than something each consumer\n * has to remember separately.\n *\n * Scope is the scheduling only. *What* to reconcile — keep the surviving active\n * option, fall back to the next / previous / first visible one, rebuild derived\n * chips or hidden fields — stays in the controller, because no two consumers\n * answer it the same way.\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 #reconcile = new MicrotaskCoalescer(() => this.#reconcileOptions());\n *\n * connect() { this.#reconcile.activate(); }\n * disconnect() { this.#reconcile.cancel(); }\n *\n * optionTargetConnected() { this.#reconcile.schedule(); }\n * optionTargetDisconnected() { this.#reconcile.schedule(); }\n * ```\n */\nexport class MicrotaskCoalescer {\n readonly #run: () => void;\n #queued = false;\n #active = false;\n #generation = 0;\n\n /** @param run - the single reconciliation pass, invoked at most once per batch. */\n constructor(run: () => void) {\n this.#run = run;\n }\n\n /** Opens the window in which {@link schedule} is honoured; call from `connect()`. */\n activate(): void {\n this.#active = true;\n }\n\n /** Closes the window and drops any pending pass; call from `disconnect()`. */\n cancel(): void {\n this.#active = false;\n this.#queued = false;\n this.#generation += 1;\n }\n\n /** Requests one pass after the batch settles. Idempotent; inert outside the window. */\n schedule(): void {\n if (!this.#active || this.#queued) return;\n this.#queued = true;\n const generation = this.#generation;\n queueMicrotask(() => {\n // A cancelled callback must not consume a pass queued after reconnect.\n if (generation !== this.#generation || !this.#queued || !this.#active) return;\n this.#queued = false;\n this.#run();\n });\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { MicrotaskCoalescer } from \"../utils/microtask_coalescer\";\n\n/**\n * Headless, accessible stepper / wizard navigation behavior.\n *\n * Markup contract (identifier: `stimeo--stepper`):\n * <ol data-controller=\"stimeo--stepper\" data-stimeo--stepper-index-value=\"0\">\n * <li data-stimeo--stepper-target=\"step\">\n * <button aria-current=\"step\" data-stimeo--stepper-index-param=\"0\"\n * data-action=\"click->stimeo--stepper#goto\">Account</button>\n * </li>\n * <!-- more steps -->\n * </ol>\n *\n * There is no dedicated APG widget; the current step is expressed with\n * `aria-current=\"step\"` on the operable `<button>`. Each step `<li>` also gets a\n * `data-state` (`complete`/`current`/`upcoming`) derived from the current index.\n * For a read-only progress display use\n * {@link StepIndicatorController | Step Indicator}; for panel switching use\n * {@link TabsController | Tabs}.\n *\n * `change` dispatches `{ index: number, previous: number, total: number, step: HTMLElement }`,\n * and `reconcile` dispatches the same\n * `{ index: number, previous: number, total: number, step: HTMLElement }` — `previous`\n * is the position shown before — when a change the page made moves the position of\n * the current step (the clamped `index`).\n *\n * @remarks\n * Behavior only. The controller never traps or restores focus — each step button\n * is in the natural Tab order. `data-state` is purely derived from `index` and the\n * steps present (completion is not persisted).\n *\n * Behavior provided:\n * - `next`/`prev` move one step, ignoring moves past either end.\n * - `goto` jumps to the step in its `index` action param.\n * - With `linear=true`, `goto` may not skip more than one step ahead of the\n * current one (moving backward is always allowed).\n * - Runtime changes to the `index` Value, and steps added or removed at runtime,\n * re-derive every step's state once per batch. Once connected, a batch that\n * moves the current position (the clamped `index`) away from the one shown\n * reports `stimeo--stepper:reconcile` once. A batch that leaves the position\n * where it was reports nothing, even when another step now stands there — a\n * step added before the current one, or the current step removed while\n * another follows it — and only redraws `data-state`/`aria-current`;\n * connecting reports nothing.\n * - An `index` outside the step range, fractional, or not a number at all is\n * clamped for display only. The Value keeps what the page declared, so the\n * declared step comes back once enough steps are present; a move the user makes\n * is the one path that writes it.\n * - Each move re-derives `data-state`/`aria-current` and dispatches\n * `stimeo--stepper:change`.\n */\nexport class StepperController extends Controller<HTMLElement> {\n static override targets = [\"step\"];\n static override values = {\n index: { type: Number, default: 0 },\n linear: { type: Boolean, default: false },\n };\n static actions = [\"goto\", \"next\", \"prev\"] as const;\n static events = [\"change\", \"reconcile\"] as const;\n\n declare readonly stepTargets: HTMLElement[];\n declare indexValue: number;\n declare linearValue: boolean;\n\n /**\n * Collapses the Value and target callbacks of one mutation into one pass, and\n * refuses the ones Stimulus delivers before `connect()`, which renders itself.\n */\n readonly #repaint = new MicrotaskCoalescer(() => this.#reconcileStep());\n\n /**\n * The position shown current last, which the next move is measured from, or\n * `null` before any step has been shown. While no step is present it keeps the\n * last one.\n */\n #shown: number | null = null;\n\n /** Renders the initial state from `index`, clamped into the step range. */\n override connect(): void {\n this.#repaint.activate();\n this.#shown = this.#currentStep;\n this.#render();\n }\n\n /** Drops a pending pass, so nothing renders or reports for a stepper that left. */\n override disconnect(): void {\n this.#repaint.cancel();\n }\n\n /** Re-renders when Turbo Morph or application code changes `index` at runtime. */\n indexValueChanged(): void {\n this.#repaint.schedule();\n }\n\n /** Re-derives every step's state for a step added at runtime. */\n stepTargetConnected(): void {\n this.#repaint.schedule();\n }\n\n /** Re-derives every step's state for a step removed at runtime. */\n stepTargetDisconnected(): void {\n this.#repaint.schedule();\n }\n\n /** Advances to the next step (ignored at the last step). */\n next(): void {\n this.#moveTo(this.#clampIndex(this.indexValue) + 1);\n }\n\n /** Returns to the previous step (ignored at the first step). */\n prev(): void {\n this.#moveTo(this.#clampIndex(this.indexValue) - 1);\n }\n\n /**\n * Jumps to the step carried in the action's `index` param. A param that is empty,\n * or that Stimulus parses into anything but a number or a string, is no index,\n * so it jumps nowhere.\n */\n goto(event: { params: { index?: unknown } }): void {\n const { index } = event.params;\n if (index === \"\") return;\n if (typeof index !== \"number\" && typeof index !== \"string\") return;\n const target = Number(index);\n if (!Number.isFinite(target) || !Number.isInteger(target)) return;\n this.#moveTo(target);\n }\n\n /**\n * Moves the current step to `target` when allowed: in range, not a no-op, and\n * — under `linear` — not skipping more than one step ahead. Re-renders and\n * dispatches `change`.\n */\n #moveTo(target: number): void {\n const total = this.stepTargets.length;\n if (!Number.isFinite(target) || !Number.isInteger(target)) return;\n if (target < 0 || target >= total) return;\n const current = this.#clampIndex(this.indexValue);\n if (target === current) return;\n if (this.linearValue && target > current + 1) return;\n\n const previous = current;\n this.indexValue = target;\n // Settled before the report, so the pass the Value write starts finds the step\n // already shown, and a listener that moves on is measured from this step.\n this.#shown = target;\n this.#render();\n this.dispatch(\"change\", {\n detail: { index: target, previous, total, step: this.stepTargets[target] },\n });\n }\n\n /**\n * Re-derives one settled batch of Value and target changes, and reports a\n * current position that moved from the one shown before as `reconcile`. With no\n * step present there is nothing to report, and the position shown last stays the\n * one the next move is measured from.\n */\n #reconcileStep(): void {\n const previous = this.#shown;\n const index = this.#currentStep;\n if (index !== null) this.#shown = index;\n this.#render();\n if (index === null || previous === null || index === previous) return;\n const steps = this.stepTargets;\n this.dispatch(\"reconcile\", {\n detail: { index, previous, total: steps.length, step: steps[index] },\n });\n }\n\n /** The current position, clamped into the step range, or `null` when there is no step. */\n get #currentStep(): number | null {\n return this.stepTargets.length > 0 ? this.#clampIndex(this.indexValue) : null;\n }\n\n /**\n * Derives each step's `data-state` and the current button's `aria-current` from\n * `index`, clamped into the step range, without dispatching an action event.\n *\n * The clamp decides only what is shown. This body never writes `index`, so an\n * out-of-range declaration stays in the attribute as the page wrote it.\n *\n * `aria-current=\"step\"` is placed on the step's **first** `<button>`; the markup\n * contract assumes one operable button per step. If a step needs multiple\n * buttons, mark the navigational one first (or this would target the wrong one).\n *\n * @stimeoRenderRoot\n */\n #render(): void {\n const current = this.#clampIndex(this.indexValue);\n this.stepTargets.forEach((step, index) => {\n step.dataset.state =\n index < current ? \"complete\" : index === current ? \"current\" : \"upcoming\";\n const button = step.querySelector<HTMLElement>(\"button\");\n if (!button) return;\n if (index === current) {\n button.setAttribute(\"aria-current\", \"step\");\n } else {\n button.removeAttribute(\"aria-current\");\n }\n });\n }\n\n /** Constrains an index to `[0, total-1]` (or `0` when there are no steps). */\n #clampIndex(index: number): number {\n const last = this.stepTargets.length - 1;\n if (last < 0 || !Number.isFinite(index)) return 0;\n return Math.min(last, Math.max(0, Math.trunc(index)));\n }\n}\n"]}
|
|
@@ -12,6 +12,8 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
12
12
|
* data-stimeo--stick-to-bottom-threshold-value="80"
|
|
13
13
|
* data-stimeo--stick-to-bottom-pin-on-connect-value="true" style="overflow:auto">
|
|
14
14
|
* <ul data-stimeo--stick-to-bottom-target="content"><!-- Turbo Stream appends --></ul>
|
|
15
|
+
* <button type="button" hidden data-stimeo--stick-to-bottom-target="hasNew"
|
|
16
|
+
* data-action="stimeo--stick-to-bottom#scrollToBottom">New messages</button>
|
|
15
17
|
* </div>
|
|
16
18
|
*
|
|
17
19
|
* The container is "pinned" while it has a box to measure and its distance from the
|
|
@@ -21,6 +23,12 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
21
23
|
* emitting `pin` on change; the `scrollToBottom` action jumps back down (a "new messages"
|
|
22
24
|
* button). A `threshold` changed at runtime re-derives the state at once.
|
|
23
25
|
*
|
|
26
|
+
* `data-has-new` says which state the container is in; the optional `hasNew` targets are
|
|
27
|
+
* the regions that belong to the flagged side — the affordance offering the jump back
|
|
28
|
+
* down. They are shown while the flag is up and hidden while it is down, written wherever
|
|
29
|
+
* the flag moves, so an authored `hidden` settles at the first reflection and a restored
|
|
30
|
+
* DOM cannot leave the region contradicting the flag.
|
|
31
|
+
*
|
|
24
32
|
* A container that already overflows renders at `scrollTop` 0 — further than
|
|
25
33
|
* `threshold` from the bottom, so unpinned — and flags the first append rather
|
|
26
34
|
* than following it. `pinOnConnect` opts into the other starting point:
|
|
@@ -72,6 +80,7 @@ declare class StickToBottomController extends Controller<HTMLElement> {
|
|
|
72
80
|
static events: readonly ["pin", "new"];
|
|
73
81
|
readonly contentTarget: HTMLElement;
|
|
74
82
|
readonly hasContentTarget: boolean;
|
|
83
|
+
readonly hasNewTargets: HTMLElement[];
|
|
75
84
|
thresholdValue: number;
|
|
76
85
|
behaviorValue: string;
|
|
77
86
|
pinOnConnectValue: boolean;
|
|
@@ -81,6 +90,16 @@ declare class StickToBottomController extends Controller<HTMLElement> {
|
|
|
81
90
|
contentTargetConnected(): void;
|
|
82
91
|
/** Moves the append watch off a `content` target that left, back onto the container. */
|
|
83
92
|
contentTargetDisconnected(): void;
|
|
93
|
+
/**
|
|
94
|
+
* Settles a has-new region that arrived at runtime on the side the flag is currently
|
|
95
|
+
* on, the way a region present at connect is settled by the connect-time normalization.
|
|
96
|
+
*
|
|
97
|
+
* Stimulus attaches targets before `connect()`, and a container that leaves the document
|
|
98
|
+
* and comes back keeps its controller, so in that window the flag still reads the
|
|
99
|
+
* arrival of the connection that ended. A region attached there is left to the
|
|
100
|
+
* connect-time normalization, which drops the flag and settles the region in one write.
|
|
101
|
+
*/
|
|
102
|
+
hasNewTargetConnected(): void;
|
|
84
103
|
/**
|
|
85
104
|
* Re-derives pinned when the distance that counts as the bottom is changed at runtime
|
|
86
105
|
* (a morph that swaps the attribute on a retained element).
|
|
@@ -8,10 +8,15 @@ var LayoutObserver = class {
|
|
|
8
8
|
#resizeObserverFactory;
|
|
9
9
|
#resizeObserver = null;
|
|
10
10
|
#observingViewport = false;
|
|
11
|
+
#loadContainer = null;
|
|
11
12
|
/** Stable bound handler so add/removeEventListener target the same reference. */
|
|
12
13
|
#handleViewportResize = () => {
|
|
13
14
|
this.#callback();
|
|
14
15
|
};
|
|
16
|
+
/** Stable bound handler for the capture-phase `load`; see {@link observeDescendantLoads}. */
|
|
17
|
+
#handleDescendantLoad = () => {
|
|
18
|
+
this.#callback();
|
|
19
|
+
};
|
|
15
20
|
constructor(callback, options = {}) {
|
|
16
21
|
this.#callback = callback;
|
|
17
22
|
this.#resizeObserverFactory = options.resizeObserverFactory ?? (typeof ResizeObserver === "undefined" ? null : (cb) => new ResizeObserver(cb));
|
|
@@ -47,14 +52,35 @@ var LayoutObserver = class {
|
|
|
47
52
|
window.removeEventListener("resize", this.#handleViewportResize);
|
|
48
53
|
}
|
|
49
54
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
55
|
+
* Starts reporting a `load` from anywhere inside `container` — an image or a
|
|
56
|
+
* frame settling changes the box it sits in, and it measures as zero high until
|
|
57
|
+
* then. `load` does not bubble, so the subscription is a capture-phase listener
|
|
58
|
+
* on the container itself and nothing the caller spells.
|
|
59
|
+
*
|
|
60
|
+
* **One container at a time.** A further call moves the observation, so a widget
|
|
61
|
+
* whose content element is swapped at runtime releases the element it let go by
|
|
62
|
+
* naming the new one — there is no second place for the release to drift from.
|
|
63
|
+
*/
|
|
64
|
+
observeDescendantLoads(container) {
|
|
65
|
+
this.unobserveDescendantLoads();
|
|
66
|
+
this.#loadContainer = container;
|
|
67
|
+
container.addEventListener("load", this.#handleDescendantLoad, true);
|
|
68
|
+
}
|
|
69
|
+
/** Stops reporting descendant loads without affecting element or viewport observation. */
|
|
70
|
+
unobserveDescendantLoads() {
|
|
71
|
+
this.#loadContainer?.removeEventListener("load", this.#handleDescendantLoad, true);
|
|
72
|
+
this.#loadContainer = null;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Releases every observation: disconnects the {@link ResizeObserver} and removes
|
|
76
|
+
* the viewport and descendant-load listeners. Safe to call multiple times. Call
|
|
77
|
+
* this from a controller's `disconnect()`.
|
|
53
78
|
*/
|
|
54
79
|
disconnect() {
|
|
55
80
|
this.#resizeObserver?.disconnect();
|
|
56
81
|
this.#resizeObserver = null;
|
|
57
82
|
this.unobserveViewport();
|
|
83
|
+
this.unobserveDescendantLoads();
|
|
58
84
|
}
|
|
59
85
|
};
|
|
60
86
|
|
|
@@ -63,6 +89,47 @@ function prefersReducedMotion() {
|
|
|
63
89
|
return typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
64
90
|
}
|
|
65
91
|
|
|
92
|
+
// src/utils/state_regions.ts
|
|
93
|
+
var StateRegions = class {
|
|
94
|
+
#whenTrue;
|
|
95
|
+
#whenFalse;
|
|
96
|
+
#taken = /* @__PURE__ */ new WeakSet();
|
|
97
|
+
constructor(options) {
|
|
98
|
+
this.#whenTrue = options.whenTrue;
|
|
99
|
+
this.#whenFalse = options.whenFalse ?? null;
|
|
100
|
+
}
|
|
101
|
+
/** Shows the regions inside `host` that belong to `isTrue` and hides the others. */
|
|
102
|
+
reflect(host, isTrue) {
|
|
103
|
+
const shown = this.#inside(host, this.#whenTrue());
|
|
104
|
+
if (!this.#whenFalse) {
|
|
105
|
+
for (const region of shown) this.#write(region, !isTrue);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const hiddenSide = this.#inside(host, this.#whenFalse());
|
|
109
|
+
if (shown.length === 0 || hiddenSide.length === 0) {
|
|
110
|
+
for (const region of shown) this.#give(region);
|
|
111
|
+
for (const region of hiddenSide) this.#give(region);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
for (const region of shown) this.#write(region, !isTrue);
|
|
115
|
+
for (const region of hiddenSide) this.#write(region, isTrue);
|
|
116
|
+
}
|
|
117
|
+
/** Writes `hidden` where it moves, noting which regions it takes out of view. */
|
|
118
|
+
#write(region, hidden) {
|
|
119
|
+
if (hidden) this.#taken.add(region);
|
|
120
|
+
else this.#taken.delete(region);
|
|
121
|
+
if (region.hidden !== hidden) region.hidden = hidden;
|
|
122
|
+
}
|
|
123
|
+
/** Returns a region this instance hid; one it never hid keeps what it carries. */
|
|
124
|
+
#give(region) {
|
|
125
|
+
if (this.#taken.delete(region)) region.hidden = false;
|
|
126
|
+
}
|
|
127
|
+
/** The declared regions that sit within `host`, which may be the host itself. */
|
|
128
|
+
#inside(host, regions) {
|
|
129
|
+
return regions.filter((region) => host.contains(region));
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
66
133
|
// src/controllers/stick_to_bottom_controller.ts
|
|
67
134
|
var DEFAULT_THRESHOLD = 80;
|
|
68
135
|
var countElements = (nodes) => {
|
|
@@ -71,7 +138,7 @@ var countElements = (nodes) => {
|
|
|
71
138
|
return n;
|
|
72
139
|
};
|
|
73
140
|
var StickToBottomController = class extends Controller {
|
|
74
|
-
static targets = ["content"];
|
|
141
|
+
static targets = ["content", "hasNew"];
|
|
75
142
|
static values = {
|
|
76
143
|
threshold: { type: Number, default: DEFAULT_THRESHOLD },
|
|
77
144
|
behavior: { type: String, default: "auto" },
|
|
@@ -87,11 +154,14 @@ var StickToBottomController = class extends Controller {
|
|
|
87
154
|
#awaitingLayout = false;
|
|
88
155
|
#connected = false;
|
|
89
156
|
#pinned = false;
|
|
157
|
+
#hasNew = false;
|
|
158
|
+
/** Owns `hidden` on the regions declared for the has-new state. */
|
|
159
|
+
#hasNewRegion = new StateRegions({ whenTrue: () => this.hasNewTargets });
|
|
90
160
|
#onScroll = () => this.#updatePinned();
|
|
91
161
|
connect() {
|
|
92
162
|
this.#connected = true;
|
|
93
163
|
if (this.pinOnConnectValue && this.#measurable()) this.#scrollToBottom("instant");
|
|
94
|
-
this
|
|
164
|
+
this.#setHasNew(false);
|
|
95
165
|
this.#pinned = this.#isPinned();
|
|
96
166
|
this.#reflectPinned();
|
|
97
167
|
this.element.addEventListener("scroll", this.#onScroll, { passive: true });
|
|
@@ -112,6 +182,19 @@ var StickToBottomController = class extends Controller {
|
|
|
112
182
|
contentTargetDisconnected() {
|
|
113
183
|
this.#syncWatched();
|
|
114
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* Settles a has-new region that arrived at runtime on the side the flag is currently
|
|
187
|
+
* on, the way a region present at connect is settled by the connect-time normalization.
|
|
188
|
+
*
|
|
189
|
+
* Stimulus attaches targets before `connect()`, and a container that leaves the document
|
|
190
|
+
* and comes back keeps its controller, so in that window the flag still reads the
|
|
191
|
+
* arrival of the connection that ended. A region attached there is left to the
|
|
192
|
+
* connect-time normalization, which drops the flag and settles the region in one write.
|
|
193
|
+
*/
|
|
194
|
+
hasNewTargetConnected() {
|
|
195
|
+
if (!this.#connected) return;
|
|
196
|
+
this.#hasNewRegion.reflect(this.element, this.#hasNew);
|
|
197
|
+
}
|
|
115
198
|
/**
|
|
116
199
|
* Re-derives pinned when the distance that counts as the bottom is changed at runtime
|
|
117
200
|
* (a morph that swaps the attribute on a retained element).
|
|
@@ -133,7 +216,7 @@ var StickToBottomController = class extends Controller {
|
|
|
133
216
|
*/
|
|
134
217
|
scrollToBottom() {
|
|
135
218
|
this.#scrollToBottom();
|
|
136
|
-
this
|
|
219
|
+
this.#setHasNew(false);
|
|
137
220
|
this.#updatePinned();
|
|
138
221
|
}
|
|
139
222
|
/** Follows appended children while pinned; otherwise flags new content. */
|
|
@@ -144,7 +227,7 @@ var StickToBottomController = class extends Controller {
|
|
|
144
227
|
if (this.#pinned) {
|
|
145
228
|
this.#scrollToBottom();
|
|
146
229
|
} else {
|
|
147
|
-
this
|
|
230
|
+
this.#setHasNew(true);
|
|
148
231
|
this.dispatch("new", { detail: { count: added } });
|
|
149
232
|
}
|
|
150
233
|
}
|
|
@@ -164,11 +247,24 @@ var StickToBottomController = class extends Controller {
|
|
|
164
247
|
#reflectPinned() {
|
|
165
248
|
if (this.#pinned) {
|
|
166
249
|
this.element.setAttribute("data-pinned", "true");
|
|
167
|
-
this
|
|
250
|
+
this.#setHasNew(false);
|
|
168
251
|
} else {
|
|
169
252
|
this.element.removeAttribute("data-pinned");
|
|
170
253
|
}
|
|
171
254
|
}
|
|
255
|
+
/**
|
|
256
|
+
* Mirrors whether content has arrived that the container did not follow onto the state
|
|
257
|
+
* hook and onto the regions declared for that state.
|
|
258
|
+
*/
|
|
259
|
+
#setHasNew(hasNew) {
|
|
260
|
+
this.#hasNew = hasNew;
|
|
261
|
+
if (hasNew) {
|
|
262
|
+
this.element.setAttribute("data-has-new", "true");
|
|
263
|
+
} else {
|
|
264
|
+
this.element.removeAttribute("data-has-new");
|
|
265
|
+
}
|
|
266
|
+
this.#hasNewRegion.reflect(this.element, hasNew);
|
|
267
|
+
}
|
|
172
268
|
/** Whether the container currently sits within `threshold` of its bottom. */
|
|
173
269
|
#isPinned() {
|
|
174
270
|
if (!this.#measurable()) return false;
|