stimeo-ui 0.2.0 → 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.
- package/CHANGELOG.md +59 -0
- package/dist/controllers/accordion_controller.d.ts +3 -2
- package/dist/controllers/accordion_controller.js.map +1 -1
- package/dist/controllers/alert_dialog_controller.d.ts +64 -0
- package/dist/controllers/alert_dialog_controller.js +318 -0
- package/dist/controllers/alert_dialog_controller.js.map +1 -0
- package/dist/controllers/carousel_controller.d.ts +100 -0
- package/dist/controllers/carousel_controller.js +272 -0
- package/dist/controllers/carousel_controller.js.map +1 -0
- package/dist/controllers/clipboard_controller.d.ts +72 -0
- package/dist/controllers/clipboard_controller.js +144 -0
- package/dist/controllers/clipboard_controller.js.map +1 -0
- package/dist/controllers/collapsible_controller.d.ts +70 -0
- package/dist/controllers/collapsible_controller.js +327 -0
- package/dist/controllers/collapsible_controller.js.map +1 -0
- package/dist/controllers/color_picker_controller.d.ts +76 -0
- package/dist/controllers/color_picker_controller.js +213 -0
- package/dist/controllers/color_picker_controller.js.map +1 -0
- package/dist/controllers/count_up_controller.js +8 -1
- package/dist/controllers/count_up_controller.js.map +1 -1
- package/dist/controllers/currency_input_controller.d.ts +72 -0
- package/dist/controllers/currency_input_controller.js +147 -0
- package/dist/controllers/currency_input_controller.js.map +1 -0
- package/dist/controllers/data_grid_controller.d.ts +71 -0
- package/dist/controllers/data_grid_controller.js +168 -0
- package/dist/controllers/data_grid_controller.js.map +1 -0
- package/dist/controllers/date_range_picker_controller.d.ts +87 -0
- package/dist/controllers/date_range_picker_controller.js +417 -0
- package/dist/controllers/date_range_picker_controller.js.map +1 -0
- package/dist/controllers/dismissible_controller.d.ts +57 -0
- package/dist/controllers/dismissible_controller.js +117 -0
- package/dist/controllers/dismissible_controller.js.map +1 -0
- package/dist/controllers/drawer_controller.d.ts +96 -0
- package/dist/controllers/drawer_controller.js +630 -0
- package/dist/controllers/drawer_controller.js.map +1 -0
- package/dist/controllers/editable_controller.d.ts +73 -0
- package/dist/controllers/editable_controller.js +168 -0
- package/dist/controllers/editable_controller.js.map +1 -0
- package/dist/controllers/file_dropzone_controller.d.ts +92 -0
- package/dist/controllers/file_dropzone_controller.js +165 -0
- package/dist/controllers/file_dropzone_controller.js.map +1 -0
- package/dist/controllers/filter_controller.d.ts +60 -0
- package/dist/controllers/filter_controller.js +86 -0
- package/dist/controllers/filter_controller.js.map +1 -0
- package/dist/controllers/flash_controller.js +36 -5
- package/dist/controllers/flash_controller.js.map +1 -1
- package/dist/controllers/highlight_controller.js +6 -4
- package/dist/controllers/highlight_controller.js.map +1 -1
- package/dist/controllers/intersection_controller.js +41 -18
- package/dist/controllers/intersection_controller.js.map +1 -1
- package/dist/controllers/lazy_frame_controller.js +33 -11
- package/dist/controllers/lazy_frame_controller.js.map +1 -1
- package/dist/controllers/masonry_controller.d.ts +54 -0
- package/dist/controllers/masonry_controller.js +142 -0
- package/dist/controllers/masonry_controller.js.map +1 -0
- package/dist/controllers/menubar_controller.d.ts +62 -0
- package/dist/controllers/menubar_controller.js +433 -0
- package/dist/controllers/menubar_controller.js.map +1 -0
- package/dist/controllers/multi_select_controller.d.ts +115 -0
- package/dist/controllers/multi_select_controller.js +472 -0
- package/dist/controllers/multi_select_controller.js.map +1 -0
- package/dist/controllers/navigation_menu_controller.d.ts +99 -0
- package/dist/controllers/navigation_menu_controller.js +384 -0
- package/dist/controllers/navigation_menu_controller.js.map +1 -0
- package/dist/controllers/overflow_indicator_controller.d.ts +12 -4
- package/dist/controllers/overflow_indicator_controller.js +178 -27
- package/dist/controllers/overflow_indicator_controller.js.map +1 -1
- package/dist/controllers/password_reveal_controller.d.ts +49 -0
- package/dist/controllers/password_reveal_controller.js +117 -0
- package/dist/controllers/password_reveal_controller.js.map +1 -0
- package/dist/controllers/range_slider_controller.d.ts +87 -0
- package/dist/controllers/range_slider_controller.js +166 -0
- package/dist/controllers/range_slider_controller.js.map +1 -0
- package/dist/controllers/read_more_controller.d.ts +52 -0
- package/dist/controllers/read_more_controller.js +194 -0
- package/dist/controllers/read_more_controller.js.map +1 -0
- package/dist/controllers/scroll_area_controller.js +15 -2
- package/dist/controllers/scroll_area_controller.js.map +1 -1
- package/dist/controllers/scroll_restore_controller.d.ts +54 -0
- package/dist/controllers/scroll_restore_controller.js +93 -0
- package/dist/controllers/scroll_restore_controller.js.map +1 -0
- package/dist/controllers/scroll_visibility_controller.js +8 -4
- package/dist/controllers/scroll_visibility_controller.js.map +1 -1
- package/dist/controllers/scrollspy_controller.js +33 -11
- package/dist/controllers/scrollspy_controller.js.map +1 -1
- package/dist/controllers/separator_controller.d.ts +54 -0
- package/dist/controllers/separator_controller.js +87 -0
- package/dist/controllers/separator_controller.js.map +1 -0
- package/dist/controllers/sidebar_controller.d.ts +107 -0
- package/dist/controllers/sidebar_controller.js +761 -0
- package/dist/controllers/sidebar_controller.js.map +1 -0
- package/dist/controllers/stepper_controller.d.ts +4 -0
- package/dist/controllers/stepper_controller.js +28 -12
- package/dist/controllers/stepper_controller.js.map +1 -1
- package/dist/controllers/stick_to_bottom_controller.js +8 -4
- package/dist/controllers/stick_to_bottom_controller.js.map +1 -1
- package/dist/controllers/sticky_observer_controller.d.ts +17 -4
- package/dist/controllers/sticky_observer_controller.js +88 -20
- package/dist/controllers/sticky_observer_controller.js.map +1 -1
- package/dist/controllers/tabs_controller.d.ts +3 -2
- package/dist/controllers/tabs_controller.js.map +1 -1
- package/dist/controllers/tags_input_controller.d.ts +91 -0
- package/dist/controllers/tags_input_controller.js +275 -0
- package/dist/controllers/tags_input_controller.js.map +1 -0
- package/dist/controllers/theme_controller.js +20 -10
- package/dist/controllers/theme_controller.js.map +1 -1
- package/dist/controllers/time_picker_controller.d.ts +67 -0
- package/dist/controllers/time_picker_controller.js +212 -0
- package/dist/controllers/time_picker_controller.js.map +1 -0
- package/dist/controllers/toast_controller.d.ts +1 -9
- package/dist/controllers/toast_controller.js +36 -9
- package/dist/controllers/toast_controller.js.map +1 -1
- package/dist/controllers/transition_controller.d.ts +14 -8
- package/dist/controllers/transition_controller.js +153 -38
- package/dist/controllers/transition_controller.js.map +1 -1
- package/dist/controllers/tree_view_controller.d.ts +54 -0
- package/dist/controllers/tree_view_controller.js +275 -0
- package/dist/controllers/tree_view_controller.js.map +1 -0
- package/dist/index.d.ts +27 -1818
- package/dist/index.js +811 -295
- package/dist/index.js.map +1 -1
- package/dist/inspector/examples.json +2 -2
- package/dist/inspector/manifest.json +15 -3
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/intersection_watcher.ts","../../src/controllers/sticky_observer_controller.ts"],"names":[],"mappings":";;;;;AA4BO,IAAM,sBAAN,MAA0B;AAAA,EACtB,UAAA;AAAA,EACT,SAAA,GAAyC,IAAA;AAAA,EACzC,OAAA,GAAU,KAAA;AAAA,EAEV,YAAY,SAAA,EAA2D;AACrE,IAAA,IAAA,CAAK,UAAA,GAAa,SAAA;AAAA,EACpB;AAAA;AAAA,EAGA,IAAI,MAAA,GAAkB;AACpB,IAAA,OAAO,IAAA,CAAK,OAAA;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,KAAA,CAAM,OAAA,EAAuC,OAAA,GAAoC,EAAC,EAAY;AAC5F,IAAA,IAAA,CAAK,IAAA,EAAK;AACV,IAAA,IAAI,OAAO,oBAAA,KAAyB,WAAA,EAAa,OAAO,KAAA;AACxD,IAAA,MAAM,OAAO,KAAA,CAAM,OAAA,CAAQ,OAAO,CAAA,GAAK,OAAA,GAAiC,CAAC,OAAkB,CAAA;AAC3F,IAAA,IAAI,IAAA,CAAK,MAAA,KAAW,CAAA,EAAG,OAAO,KAAA;AAE9B,IAAA,MAAM,IAAA,GACJ,MAAA,IAAU,OAAA,GACL,OAAA,CAAQ,IAAA,IAAQ,IAAA,GACjB,OAAA,CAAQ,YAAA,GACN,QAAA,CAAS,aAAA,CAAc,OAAA,CAAQ,YAAY,CAAA,GAC3C,IAAA;A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(`intersection`, `scrollspy`, `sticky-observer`, `lazy-frame`).\n *\n * It centralizes the `IntersectionObserver` support guard, root resolution from\n * a selector, observer creation/teardown, the **active guard** (the browser may\n * flush a final queued callback batch right after `disconnect()`, and a\n * detached controller must not mutate possibly-cached DOM), and the\n * unobserve→observe **re-arm** that re-delivers the current state even when the\n * target never leaves the viewport.\n *\n * Like {@link RovingTabindex} and `FocusTrap`, this is a policy-free internal\n * util: what an intersection *means* (a spied link, a stuck header, a lazy\n * load) stays in each controller. The public `stimeo--intersection` controller\n * is its thin declarative face.\n */\nexport interface IntersectionWatchOptions {\n /**\n * The observation root. Pass an element (or `null` for the viewport) when\n * the caller already resolved it; omit to resolve from `rootSelector`.\n */\n root?: Element | null;\n /** Selector for the observation root; empty/omitted = viewport. */\n rootSelector?: string;\n rootMargin?: string;\n threshold?: number | number[];\n}\n\nexport class IntersectionWatcher {\n readonly #onEntries: (entries: IntersectionObserverEntry[]) => void;\n #observer: IntersectionObserver | null = null;\n #active = false;\n\n constructor(onEntries: (entries: IntersectionObserverEntry[]) => void) {\n this.#onEntries = onEntries;\n }\n\n /** Whether an observer is live (started, `IntersectionObserver` supported). */\n get active(): boolean {\n return this.#active;\n }\n\n /**\n * (Re)creates the observer and observes `targets`. Returns `false` — leaving\n * the watcher inert — without `IntersectionObserver` support (very old\n * browsers; the caller's no-JS fallback stays in charge) or with no targets.\n */\n start(targets: Element | readonly Element[], options: IntersectionWatchOptions = {}): boolean {\n this.stop();\n if (typeof IntersectionObserver === \"undefined\") return false;\n const list = Array.isArray(targets) ? (targets as readonly Element[]) : [targets as Element];\n if (list.length === 0) return false;\n\n const root =\n \"root\" in options\n ? (options.root ?? null)\n : options.rootSelector\n ? document.querySelector(options.rootSelector)\n : null;\n\n this.#active = true;\n this.#observer = new IntersectionObserver(\n (entries) => {\n if (this.#active) this.#onEntries(entries);\n },\n { root, rootMargin: options.rootMargin, threshold: options.threshold },\n );\n for (const target of list) this.#observer.observe(target);\n return true;\n }\n\n /**\n * Re-delivers `target`'s CURRENT intersection state: `IntersectionObserver`\n * only reports *changes*, but `observe()` always reports the present state,\n * so unobserve→observe turns \"still intersecting\" into a fresh callback.\n */\n rearm(target: Element): void {\n if (!this.#observer) return;\n this.#observer.unobserve(target);\n this.#observer.observe(target);\n }\n\n /** Severs the observer; late queued callbacks become no-ops via the guard. */\n stop(): void {\n this.#active = false;\n this.#observer?.disconnect();\n this.#observer = null;\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { IntersectionWatcher } from \"../utils/intersection_watcher\";\n\n/**\n * Headless **Sticky State Observer**: detects whether a `position: sticky`\n * element is currently stuck and publishes it as `data-stuck`. No APG widget — a\n * pure state-detection utility. Detection uses an {@link IntersectionObserver}\n * and a sentinel placed just before the sticky element, avoiding per-frame scroll\n * math.\n *\n * Markup contract (identifier: `stimeo--sticky-observer`):\n * <div data-controller=\"stimeo--sticky-observer\">\n * <div data-stimeo--sticky-observer-target=\"sentinel\"\n * aria-hidden=\"true\" style=\"height: 1px;\"></div>\n * <header data-stimeo--sticky-observer-target=\"element\"\n * style=\"position: sticky; top: 0;\">Site heading</header>\n * <main>…</main>\n * </div>\n *\n * When the sentinel scrolls out past the top of the viewport (or `rootSelector`\n * container), the sticky element is considered stuck and `data-stuck=\"true\"` is\n * set; otherwise `false`. The `change` event fires on each transition.\n *\n * @remarks\n * Behavior only — `position: sticky`, shadows, and shrink effects are the\n * consumer's CSS (`[data-stuck=\"true\"] { … }`). `data-stuck` is a visual hook\n * only: it carries no ARIA role/state. `offset` feeds a negative top `rootMargin`\n * and must match the sticky element's CSS `top`. The observer is disconnected on\n * `disconnect()` (Turbo navigation included).\n */\nexport class StickyObserverController extends Controller<HTMLElement> {\n static override targets = [\"sentinel\", \"element\"];\n static override values = {\n rootSelector: { type: String, default: \"\" },\n offset: { type: Number, default: 0 },\n };\n static events = [\"change\"] as const;\n\n declare readonly sentinelTarget: HTMLElement;\n declare readonly elementTarget: HTMLElement;\n declare readonly hasSentinelTarget: boolean;\n declare readonly hasElementTarget: boolean;\n\n declare rootSelectorValue: string;\n declare offsetValue: number;\n\n /** Shared IO plumbing (support guard, root resolution, active guard). */\n readonly #watcher = new IntersectionWatcher((entries) => this.#onIntersect(entries));\n /** Last reported stuck state, so `change` fires only on transitions. */\n #stuck: boolean | null = null;\n\n #onIntersect(entries: IntersectionObserverEntry[]): void {\n const entry = entries[entries.length - 1];\n if (!entry) return;\n // The sentinel sits above the sticky element; once it is no longer\n // intersecting the (top-inset) root, the sticky element has stuck.\n this.#setStuck(!entry.isIntersecting);\n }\n\n override connect(): void {\n if (!this.hasSentinelTarget) return;\n this.#watcher.start(this.sentinelTarget, {\n rootSelector: this.rootSelectorValue,\n rootMargin: `-${this.offsetValue}px 0px 0px 0px`,\n threshold: [0],\n });\n }\n\n override disconnect(): void {\n this.#watcher.stop();\n this.#stuck = null;\n }\n\n /** Reflects the stuck state onto the sticky element and emits `change`. */\n #setStuck(next: boolean): void {\n if (next === this.#stuck) return;\n this.#stuck = next;\n if (this.hasElementTarget) {\n this.elementTarget.setAttribute(\"data-stuck\", next ? \"true\" : \"false\");\n }\n this.dispatch(\"change\", { detail: { stuck: next } });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/intersection_watcher.ts","../../src/controllers/sticky_observer_controller.ts"],"names":[],"mappings":";;;;;AA8BO,SAAS,kBAAkB,KAAA,EAA2C;AAC3E,EAAA,MAAM,OAAO,KAAA,CAAM,kBAAA;AACnB,EAAA,IAAI,KAAK,KAAA,KAAU,CAAA,IAAK,IAAA,CAAK,MAAA,KAAW,GAAG,OAAO,KAAA;AAGlD,EAAA,MAAM,OAAA,GAAU,KAAA,CAAM,UAAA,EAAY,GAAA,IAAO,CAAA;AACzC,EAAA,OAAO,KAAK,MAAA,IAAU,OAAA;AACxB;AAcO,IAAM,sBAAN,MAA0B;AAAA,EACtB,UAAA;AAAA,EACT,SAAA,GAAyC,IAAA;AAAA,EACzC,OAAA,GAAU,KAAA;AAAA,EA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AAA,IAAA,CAAK,QAAA,CAAS,UAAU,EAAE,MAAA,EAAQ,EAAE,KAAA,EAAO,IAAA,IAAQ,CAAA;AAAA,EACrD;AACF","file":"sticky_observer_controller.js","sourcesContent":["/**\n * Shared `IntersectionObserver` plumbing for Stimeo's scroll-triggered\n * controllers (`intersection`, `scrollspy`, `sticky-observer`, `lazy-frame`).\n *\n * It centralizes the `IntersectionObserver` support guard, root resolution from\n * a selector, observer creation/teardown, the **active guard** (the browser may\n * flush a final queued callback batch right after `disconnect()`, and a\n * detached controller must not mutate possibly-cached DOM), and the\n * unobserve→observe **re-arm** that re-delivers the current state even when the\n * target never leaves the viewport.\n *\n * Like {@link RovingTabindex} and `FocusTrap`, this is a policy-free internal\n * util: what an intersection *means* (a spied link, a stuck header, a lazy\n * load) stays in each controller. The public `stimeo--intersection` controller\n * is its thin declarative face.\n */\n/**\n * Whether `entry`'s target sits entirely before the root's **start (top)** edge —\n * the \"scrolled past the top\" half of a non-intersecting entry, as opposed to\n * \"not reached yet\" below the root.\n *\n * A target with no layout box (`display: none`, a `hidden` ancestor, a collapsed\n * `<details>`) is reported with an **empty rect**, whose `bottom` of `0` would\n * otherwise satisfy `bottom <= rootTop` for a viewport root and read as \"passed\"\n * even though the target was never scrolled anywhere. An empty rect carries no\n * position at all, so it is deliberately never \"before the edge\"; what a caller\n * publishes for that case is its own policy (both consumers treat it as the\n * neutral \"not passed\"/\"not stuck\", and the real rect that arrives once the\n * target is laid out re-establishes the true state).\n */\nexport function isBeforeRootStart(entry: IntersectionObserverEntry): boolean {\n const rect = entry.boundingClientRect;\n if (rect.width === 0 && rect.height === 0) return false;\n // rootBounds is null for a cross-origin/removed root; fall back to the\n // viewport origin.\n const rootTop = entry.rootBounds?.top ?? 0;\n return rect.bottom <= rootTop;\n}\n\nexport interface IntersectionWatchOptions {\n /**\n * The observation root. Pass an element (or `null` for the viewport) when\n * the caller already resolved it; omit to resolve from `rootSelector`.\n */\n root?: Element | null;\n /** Selector for the observation root; empty/omitted = viewport. */\n rootSelector?: string;\n rootMargin?: string;\n threshold?: number | number[];\n}\n\nexport class IntersectionWatcher {\n readonly #onEntries: (entries: IntersectionObserverEntry[]) => void;\n #observer: IntersectionObserver | null = null;\n #active = false;\n\n constructor(onEntries: (entries: IntersectionObserverEntry[]) => void) {\n this.#onEntries = onEntries;\n }\n\n /** Whether an observer is live (started, `IntersectionObserver` supported). */\n get active(): boolean {\n return this.#active;\n }\n\n /**\n * (Re)creates the observer and observes `targets`. Returns `false` — leaving\n * the watcher inert — without `IntersectionObserver` support (very old\n * browsers; the caller's no-JS fallback stays in charge) or with no targets.\n *\n * @throws Whatever the platform throws for an invalid `rootMargin`/`threshold`\n * or a failing `observe()`. The exception is passed through unchanged, but\n * the watcher rolls back first: every target observed so far is released and\n * `active` stays `false`, so a caller that retries starts from a clean slate.\n */\n start(targets: Element | readonly Element[], options: IntersectionWatchOptions = {}): boolean {\n this.stop();\n if (typeof IntersectionObserver === \"undefined\") return false;\n const list = Array.isArray(targets) ? (targets as readonly Element[]) : [targets as Element];\n if (list.length === 0) return false;\n\n const root =\n \"root\" in options\n ? (options.root ?? null)\n : options.rootSelector\n ? document.querySelector(options.rootSelector)\n : null;\n\n let observer: IntersectionObserver | null = null;\n try {\n observer = new IntersectionObserver(\n (entries) => {\n // Identity matters across an immediate restart: the old observer can\n // flush a queued batch after the new observer has made `active` true.\n if (this.#active && this.#observer === observer) this.#onEntries(entries);\n },\n { root, rootMargin: options.rootMargin, threshold: options.threshold },\n );\n for (const target of list) observer.observe(target);\n this.#observer = observer;\n this.#active = true;\n return true;\n } catch (error) {\n // A constructor or partial observe failure must not leave earlier targets\n // observed or report an active watcher. Preserve the platform exception.\n observer?.disconnect();\n this.#observer = null;\n this.#active = false;\n throw error;\n }\n }\n\n /**\n * Re-delivers `target`'s CURRENT intersection state: `IntersectionObserver`\n * only reports *changes*, but `observe()` always reports the present state,\n * so unobserve→observe turns \"still intersecting\" into a fresh callback.\n *\n * @throws Whatever `unobserve()`/`observe()` throws. The watcher is stopped\n * first, so it never stays live with a half-rearmed target.\n */\n rearm(target: Element): void {\n if (!this.#observer) return;\n try {\n this.#observer.unobserve(target);\n this.#observer.observe(target);\n } catch (error) {\n this.stop();\n throw error;\n }\n }\n\n /** Severs the observer; late queued callbacks become no-ops via the guard. */\n stop(): void {\n this.#active = false;\n this.#observer?.disconnect();\n this.#observer = null;\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { IntersectionWatcher, isBeforeRootStart } from \"../utils/intersection_watcher\";\n\n/**\n * Headless **Sticky State Observer**: detects whether a `position: sticky`\n * element is currently stuck and publishes it as `data-stuck`. No APG widget — a\n * pure state-detection utility. Detection uses an {@link IntersectionObserver}\n * and a sentinel placed just before the sticky element, avoiding per-frame scroll\n * math.\n *\n * Markup contract (identifier: `stimeo--sticky-observer`):\n * <div data-controller=\"stimeo--sticky-observer\">\n * <div data-stimeo--sticky-observer-target=\"sentinel\"\n * aria-hidden=\"true\" style=\"height: 1px;\"></div>\n * <header data-stimeo--sticky-observer-target=\"element\"\n * style=\"position: sticky; top: 0;\">Site heading</header>\n * <main>…</main>\n * </div>\n *\n * When the sentinel scrolls out past the top of the viewport (or `rootSelector`\n * container), the sticky element is considered stuck and `data-stuck=\"true\"` is\n * set; otherwise `false`. The observer's initial snapshot dispatches `change`\n * once with the current state, including after a Turbo reconnect; subsequent\n * notifications dispatch only when that state changes.\n *\n * @remarks\n * Behavior only — `position: sticky`, shadows, and shrink effects are the\n * consumer's CSS (`[data-stuck=\"true\"] { … }`). `data-stuck` is a visual hook\n * only: it carries no ARIA role/state. `offset` is negated numerically for the\n * top `rootMargin` (so negative offsets remain valid) and must match the sticky\n * element's CSS `top`. The observer follows dynamic sentinel targets and value\n * changes, and is disconnected on `disconnect()` (Turbo navigation included).\n */\nexport class StickyObserverController extends Controller<HTMLElement> {\n static override targets = [\"sentinel\", \"element\"];\n static override values = {\n rootSelector: { type: String, default: \"\" },\n offset: { type: Number, default: 0 },\n };\n static events = [\"change\"] as const;\n\n declare readonly sentinelTarget: HTMLElement;\n declare readonly elementTarget: HTMLElement;\n declare readonly hasSentinelTarget: boolean;\n declare readonly hasElementTarget: boolean;\n\n declare rootSelectorValue: string;\n declare offsetValue: number;\n\n /** Shared IO plumbing (support guard, root resolution, active guard). */\n readonly #watcher = new IntersectionWatcher((entries) => this.#onIntersect(entries));\n /** Last reported stuck state, so `change` fires only on transitions. */\n #stuck: boolean | null = null;\n /** Target currently owned by the watcher, used to avoid duplicate restarts. */\n #observedSentinel: HTMLElement | null = null;\n #connected = false;\n\n #onIntersect(entries: IntersectionObserverEntry[]): void {\n // Delivery can batch multiple transitions after a fast scroll. Process\n // every snapshot in order so an above→visible pair is not collapsed.\n for (const entry of entries) {\n if (!this.#connected || !this.#watcher.active) return;\n // A sentinel with no layout box (hidden tab panel, collapsed section, an\n // undisplayed Turbo Frame) reports an empty rect that the shared edge test\n // deliberately refuses, so an unrendered sticky element is never published\n // as stuck; the state stays put until the sentinel is actually laid out.\n this.#setStuck(!entry.isIntersecting && isBeforeRootStart(entry));\n }\n }\n\n override connect(): void {\n this.#connected = true;\n this.#stuck = null;\n this.#syncObserver();\n }\n\n override disconnect(): void {\n this.#connected = false;\n this.#watcher.stop();\n this.#observedSentinel = null;\n this.#stuck = null;\n }\n\n /** Starts observation when a sentinel is inserted after connection. */\n sentinelTargetConnected(): void {\n if (this.#connected) this.#syncObserver();\n }\n\n /** Stops or transfers observation when the current sentinel is removed. */\n sentinelTargetDisconnected(): void {\n if (this.#connected) this.#syncObserver();\n }\n\n /** Reflects the last snapshot onto an element inserted after that snapshot. */\n elementTargetConnected(element: HTMLElement): void {\n if (this.#stuck !== null) {\n element.setAttribute(\"data-stuck\", this.#stuck ? \"true\" : \"false\");\n }\n }\n\n /** Rebuilds the observer when Turbo morphs the configured root. */\n rootSelectorValueChanged(): void {\n if (this.#connected) this.#syncObserver(true);\n }\n\n /** Rebuilds the observer when Turbo morphs the configured top offset. */\n offsetValueChanged(): void {\n if (this.#connected) this.#syncObserver(true);\n }\n\n #syncObserver(force = false): void {\n const sentinel = this.hasSentinelTarget ? this.sentinelTarget : null;\n if (!force && sentinel === this.#observedSentinel && this.#watcher.active) return;\n\n this.#watcher.stop();\n this.#observedSentinel = null;\n if (!sentinel) return;\n\n const configuredOffset = this.offsetValue;\n const offset = Number.isFinite(configuredOffset) ? configuredOffset : 0;\n const started = this.#watcher.start(sentinel, {\n rootSelector: this.rootSelectorValue,\n rootMargin: `${-offset}px 0px 0px 0px`,\n threshold: [0],\n });\n if (started) this.#observedSentinel = sentinel;\n }\n\n /** Reflects the stuck state onto the sticky element and emits `change`. */\n #setStuck(next: boolean): void {\n if (next === this.#stuck) return;\n this.#stuck = next;\n if (this.hasElementTarget) {\n this.elementTarget.setAttribute(\"data-stuck\", next ? \"true\" : \"false\");\n }\n this.dispatch(\"change\", { detail: { stuck: next } });\n }\n}\n"]}
|
|
@@ -24,9 +24,9 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
24
24
|
* @remarks
|
|
25
25
|
* Behavior only. State is exposed through `aria-selected`, roving `tabindex`
|
|
26
26
|
* (`0` for the active tab, `-1` for the rest), and the panel `hidden` attribute;
|
|
27
|
-
* the consumer owns all styling. The
|
|
27
|
+
* the consumer owns all styling. The required `list` target marks the tablist
|
|
28
28
|
* container as part of the semantic contract — the Inspector requires its
|
|
29
|
-
*
|
|
29
|
+
* role and accessible name; the controller performs no runtime work on it.
|
|
30
30
|
*
|
|
31
31
|
* Behavior provided:
|
|
32
32
|
* - Click a tab to select it.
|
|
@@ -37,6 +37,7 @@ declare class TabsController extends Controller<HTMLElement> {
|
|
|
37
37
|
#private;
|
|
38
38
|
static targets: string[];
|
|
39
39
|
static actions: readonly ["onKeydown", "select"];
|
|
40
|
+
readonly listTarget: HTMLElement;
|
|
40
41
|
readonly tabTargets: HTMLButtonElement[];
|
|
41
42
|
readonly panelTargets: HTMLElement[];
|
|
42
43
|
/** Selects the initially active tab (the pre-selected one, else the first). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/controllers/tabs_controller.ts"],"names":[],"mappings":";;;AAmCO,IAAM,cAAA,GAAN,cAA6B,UAAA,CAAwB;AAAA,EAC1D,OAAgB,OAAA,GAAU,CAAC,KAAA,EAAO,SAAS,MAAM,CAAA;AAAA,EACjD,OAAO,OAAA,GAAU,CAAC,WAAA,EAAa,QAAQ,CAAA;AAAA;AAAA,
|
|
1
|
+
{"version":3,"sources":["../../src/controllers/tabs_controller.ts"],"names":[],"mappings":";;;AAmCO,IAAM,cAAA,GAAN,cAA6B,UAAA,CAAwB;AAAA,EAC1D,OAAgB,OAAA,GAAU,CAAC,KAAA,EAAO,SAAS,MAAM,CAAA;AAAA,EACjD,OAAO,OAAA,GAAU,CAAC,WAAA,EAAa,QAAQ,CAAA;AAAA;AAAA,EAO9B,OAAA,GAAgB;AACvB,IAAA,MAAM,WAAA,GAAc,KAAK,UAAA,CAAW,SAAA;AAAA,MAClC,CAAC,GAAA,KAAQ,GAAA,CAAI,YAAA,CAAa,eAAe,CAAA,KAAM;AAAA,KACjD;AACA,IAAA,IAAA,CAAK,YAAA,CAAa,gBAAgB,EAAA,GAAK,CAAA,GAAI,aAAa,EAAE,KAAA,EAAO,OAAO,CAAA;AAAA,EAC1E;AAAA;AAAA,EAGA,OAAO,KAAA,EAAoB;AACzB,IAAA,MAAM,KAAA,GAAQ,IAAA,CAAK,UAAA,CAAW,OAAA,CAAQ,MAAM,aAAkC,CAAA;AAC9E,IAAA,IAAI,KAAA,KAAU,IAAI,IAAA,CAAK,YAAA,CAAa,OAAO,EAAE,KAAA,EAAO,OAAO,CAAA;AAAA,EAC7D;AAAA;AAAA,EAGA,UAAU,KAAA,EAA4B;AACpC,IAAA,MAAM,OAAO,IAAA,CAAK,UAAA;AAClB,IAAA,MAAM,YAAA,GAAe,IAAA,CAAK,OAAA,CAAQ,KAAA,CAAM,aAAkC,CAAA;AAC1E,IAAA,IAAI,iBAAiB,EAAA,EAA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file":"tabs_controller.js","sourcesContent":["import { Controller } from \"@hotwired/stimulus\";\n\n/**\n * Headless, accessible tabs behavior.\n *\n * Markup contract (identifier: `stimeo--tabs`):\n * <div data-controller=\"stimeo--tabs\">\n * <div role=\"tablist\" aria-label=\"…\" data-stimeo--tabs-target=\"list\">\n * <button role=\"tab\" id=\"tab-1\" aria-controls=\"panel-1\"\n * data-stimeo--tabs-target=\"tab\"\n * data-action=\"stimeo--tabs#select\n * keydown->stimeo--tabs#onKeydown\">Tab 1</button>\n * <!-- more tabs -->\n * </div>\n * <div role=\"tabpanel\" id=\"panel-1\" aria-labelledby=\"tab-1\"\n * data-stimeo--tabs-target=\"panel\">…</div>\n * <!-- more panels -->\n * </div>\n *\n * Implements the WAI-ARIA APG **Tabs** pattern with **automatic activation**:\n * moving focus with the arrow keys immediately selects the focused tab. Tabs are\n * paired to panels by index (the Nth tab controls the Nth panel).\n *\n * @remarks\n * Behavior only. State is exposed through `aria-selected`, roving `tabindex`\n * (`0` for the active tab, `-1` for the rest), and the panel `hidden` attribute;\n * the consumer owns all styling. The required `list` target marks the tablist\n * container as part of the semantic contract — the Inspector requires its\n * role and accessible name; the controller performs no runtime work on it.\n *\n * Behavior provided:\n * - Click a tab to select it.\n * - `ArrowRight`/`ArrowLeft` move to and select the next/previous tab (wrapping);\n * `Home`/`End` select the first/last tab.\n */\nexport class TabsController extends Controller<HTMLElement> {\n static override targets = [\"tab\", \"panel\", \"list\"];\n static actions = [\"onKeydown\", \"select\"] as const;\n\n declare readonly listTarget: HTMLElement;\n declare readonly tabTargets: HTMLButtonElement[];\n declare readonly panelTargets: HTMLElement[];\n\n /** Selects the initially active tab (the pre-selected one, else the first). */\n override connect(): void {\n const preselected = this.tabTargets.findIndex(\n (tab) => tab.getAttribute(\"aria-selected\") === \"true\",\n );\n this.#selectIndex(preselected === -1 ? 0 : preselected, { focus: false });\n }\n\n /** Selects the clicked tab. Bound via `data-action` (click). */\n select(event: Event): void {\n const index = this.tabTargets.indexOf(event.currentTarget as HTMLButtonElement);\n if (index !== -1) this.#selectIndex(index, { focus: false });\n }\n\n /** Implements arrow/Home/End navigation with automatic activation. */\n onKeydown(event: KeyboardEvent): void {\n const tabs = this.tabTargets;\n const currentIndex = tabs.indexOf(event.currentTarget as HTMLButtonElement);\n if (currentIndex === -1) return;\n\n let nextIndex: number | null = null;\n switch (event.key) {\n case \"ArrowRight\":\n nextIndex = (currentIndex + 1) % tabs.length;\n break;\n case \"ArrowLeft\":\n nextIndex = (currentIndex - 1 + tabs.length) % tabs.length;\n break;\n case \"Home\":\n nextIndex = 0;\n break;\n case \"End\":\n nextIndex = tabs.length - 1;\n break;\n default:\n return;\n }\n\n event.preventDefault();\n this.#selectIndex(nextIndex, { focus: true });\n }\n\n /**\n * Activates the tab/panel pair at `index`: updates `aria-selected`, the roving\n * `tabindex`, and panel visibility. Optionally moves focus to the new tab.\n */\n #selectIndex(index: number, { focus }: { focus: boolean }): void {\n this.tabTargets.forEach((tab, i) => {\n const selected = i === index;\n tab.setAttribute(\"aria-selected\", selected ? \"true\" : \"false\");\n tab.tabIndex = selected ? 0 : -1;\n });\n this.panelTargets.forEach((panel, i) => {\n panel.hidden = i !== index;\n });\n if (focus) this.tabTargets[index]?.focus();\n }\n}\n"]}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Headless, accessible free-input tags / chips field.
|
|
5
|
+
*
|
|
6
|
+
* Markup contract (identifier: `stimeo--tags-input`):
|
|
7
|
+
* <div data-controller="stimeo--tags-input"
|
|
8
|
+
* data-stimeo--tags-input-delimiter-value=",">
|
|
9
|
+
* <ul role="list" aria-label="Tags" data-stimeo--tags-input-target="tags"></ul>
|
|
10
|
+
* <input type="text" aria-label="Add tag" aria-describedby="tags-help"
|
|
11
|
+
* data-stimeo--tags-input-target="input"
|
|
12
|
+
* data-action="keydown->stimeo--tags-input#onKeydown" />
|
|
13
|
+
* <span role="status" aria-live="polite" class="visually-hidden"
|
|
14
|
+
* data-stimeo--tags-input-target="status"></span>
|
|
15
|
+
* <div data-stimeo--tags-input-target="fields"></div>
|
|
16
|
+
* <template data-stimeo--tags-input-target="tagTemplate">
|
|
17
|
+
* <li role="listitem" data-stimeo--tags-input-target="tag">
|
|
18
|
+
* <span data-tags-input-slot="label"></span>
|
|
19
|
+
* <!-- Removal is delegated on the tags container; no per-chip action needed. -->
|
|
20
|
+
* <button type="button" tabindex="-1">×</button>
|
|
21
|
+
* </li>
|
|
22
|
+
* </template>
|
|
23
|
+
* </div>
|
|
24
|
+
*
|
|
25
|
+
* There is no single established APG pattern; this composes a labeled text input
|
|
26
|
+
* with a roving-tabindex list of removable chips, mapping to WCAG 2.1.1, 2.4.7,
|
|
27
|
+
* 4.1.2, 4.1.3, and 1.3.1. Unlike {@link MultiSelectController} (pick from a
|
|
28
|
+
* candidate list) the user types arbitrary strings.
|
|
29
|
+
*
|
|
30
|
+
* Behavior provided:
|
|
31
|
+
* - `Enter` or the configured delimiter commits the trimmed input as a tag.
|
|
32
|
+
* - Empty / duplicate / over-limit additions are rejected with
|
|
33
|
+
* `stimeo--tags-input:reject`; duplicates are allowed when `allowDuplicates`.
|
|
34
|
+
* - Tags render from the `tagTemplate`, each with a `Remove {label}` button; the
|
|
35
|
+
* `fields` container mirrors the tag set as `name`d hidden inputs for form
|
|
36
|
+
* submission, and every change dispatches `stimeo--tags-input:change`.
|
|
37
|
+
* - The remove buttons form one roving Tab stop: `ArrowLeft`/`ArrowRight` move
|
|
38
|
+
* between them (right past the end returns to the input), `Delete`/`Backspace`
|
|
39
|
+
* delete the focused tag, and `Backspace` on an empty input deletes the last.
|
|
40
|
+
* - Removing a tag moves focus to the neighboring tag, else back to the input.
|
|
41
|
+
*/
|
|
42
|
+
declare class TagsInputController extends Controller<HTMLElement> {
|
|
43
|
+
#private;
|
|
44
|
+
static targets: string[];
|
|
45
|
+
static values: {
|
|
46
|
+
delimiter: {
|
|
47
|
+
type: StringConstructor;
|
|
48
|
+
default: string;
|
|
49
|
+
};
|
|
50
|
+
max: {
|
|
51
|
+
type: NumberConstructor;
|
|
52
|
+
default: number;
|
|
53
|
+
};
|
|
54
|
+
allowDuplicates: {
|
|
55
|
+
type: BooleanConstructor;
|
|
56
|
+
default: boolean;
|
|
57
|
+
};
|
|
58
|
+
name: {
|
|
59
|
+
type: StringConstructor;
|
|
60
|
+
default: string;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
static actions: readonly ["onKeydown"];
|
|
64
|
+
static events: readonly ["change", "reject"];
|
|
65
|
+
readonly inputTarget: HTMLInputElement;
|
|
66
|
+
readonly tagsTarget: HTMLElement;
|
|
67
|
+
readonly tagTargets: HTMLElement[];
|
|
68
|
+
readonly tagTemplateTarget: HTMLTemplateElement;
|
|
69
|
+
readonly statusTarget: HTMLElement;
|
|
70
|
+
readonly fieldsTarget: HTMLElement;
|
|
71
|
+
readonly hasStatusTarget: boolean;
|
|
72
|
+
readonly hasFieldsTarget: boolean;
|
|
73
|
+
readonly hasTagTemplateTarget: boolean;
|
|
74
|
+
readonly hasInputTarget: boolean;
|
|
75
|
+
delimiterValue: string;
|
|
76
|
+
maxValue: number;
|
|
77
|
+
allowDuplicatesValue: boolean;
|
|
78
|
+
nameValue: string;
|
|
79
|
+
/** Wires tag-list keyboard navigation and removal, and seeds the single Tab stop. */
|
|
80
|
+
connect(): void;
|
|
81
|
+
/** Releases the delegated listeners so no handler outlives the element. */
|
|
82
|
+
disconnect(): void;
|
|
83
|
+
/** Tracks an input added initially or after connect. */
|
|
84
|
+
inputTargetConnected(input: HTMLInputElement): void;
|
|
85
|
+
/** Removes composition listeners when the active input is replaced or removed. */
|
|
86
|
+
inputTargetDisconnected(input: HTMLInputElement): void;
|
|
87
|
+
/** Commits on `Enter`/delimiter and deletes the last tag on empty `Backspace`. */
|
|
88
|
+
onKeydown(event: KeyboardEvent): void;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export { TagsInputController };
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
|
2
|
+
|
|
3
|
+
// src/controllers/tags_input_controller.ts
|
|
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
|
+
|
|
52
|
+
// src/utils/roving_tabindex.ts
|
|
53
|
+
var RovingTabindex = class {
|
|
54
|
+
/** Returns the current ordered item elements; called on every operation. */
|
|
55
|
+
#getItems;
|
|
56
|
+
/**
|
|
57
|
+
* @param getItems - Returns the current ordered item elements. Called on every
|
|
58
|
+
* operation so the live target list is always used.
|
|
59
|
+
*/
|
|
60
|
+
constructor(getItems) {
|
|
61
|
+
this.#getItems = getItems;
|
|
62
|
+
}
|
|
63
|
+
/** Index of the currently tabbable item (`tabindex="0"`), or `-1` if none. */
|
|
64
|
+
get activeIndex() {
|
|
65
|
+
return this.#getItems().findIndex((item) => item.tabIndex === 0);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Makes exactly the item at `index` tabbable (`tabindex="0"`) and removes every
|
|
69
|
+
* other item from the Tab sequence (`tabindex="-1"`). An out-of-range `index`
|
|
70
|
+
* (e.g. `-1`) leaves all items at `-1`, which a controller can use to express
|
|
71
|
+
* "nothing is currently tabbable".
|
|
72
|
+
*
|
|
73
|
+
* @param index - Position of the item to make tabbable.
|
|
74
|
+
* @param options - Pass `{ focus: true }` to also move DOM focus to that item.
|
|
75
|
+
*/
|
|
76
|
+
setActive(index, { focus = false } = {}) {
|
|
77
|
+
const items = this.#getItems();
|
|
78
|
+
items.forEach((item, i) => {
|
|
79
|
+
item.tabIndex = i === index ? 0 : -1;
|
|
80
|
+
});
|
|
81
|
+
if (focus) items[index]?.focus();
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// src/controllers/tags_input_controller.ts
|
|
86
|
+
var TagsInputController = class extends Controller {
|
|
87
|
+
static targets = ["input", "tags", "tag", "tagTemplate", "status", "fields"];
|
|
88
|
+
static values = {
|
|
89
|
+
delimiter: { type: String, default: "," },
|
|
90
|
+
max: { type: Number, default: 0 },
|
|
91
|
+
allowDuplicates: { type: Boolean, default: false },
|
|
92
|
+
name: { type: String, default: "tags[]" }
|
|
93
|
+
};
|
|
94
|
+
static actions = ["onKeydown"];
|
|
95
|
+
static events = ["change", "reject"];
|
|
96
|
+
#roving = new RovingTabindex(() => this.#removeButtons);
|
|
97
|
+
/** Owns IME lifecycle state for commit-key guarding. */
|
|
98
|
+
#composition = new CompositionTracker();
|
|
99
|
+
/** Wires tag-list keyboard navigation and removal, and seeds the single Tab stop. */
|
|
100
|
+
connect() {
|
|
101
|
+
if (this.hasInputTarget) this.#composition.observe(this.inputTarget);
|
|
102
|
+
this.tagsTarget.addEventListener("keydown", this.#onTagKeydown);
|
|
103
|
+
this.tagsTarget.addEventListener("click", this.#onTagClick);
|
|
104
|
+
this.#syncState();
|
|
105
|
+
}
|
|
106
|
+
/** Releases the delegated listeners so no handler outlives the element. */
|
|
107
|
+
disconnect() {
|
|
108
|
+
this.#composition.disconnect();
|
|
109
|
+
this.tagsTarget.removeEventListener("keydown", this.#onTagKeydown);
|
|
110
|
+
this.tagsTarget.removeEventListener("click", this.#onTagClick);
|
|
111
|
+
}
|
|
112
|
+
/** Tracks an input added initially or after connect. */
|
|
113
|
+
inputTargetConnected(input) {
|
|
114
|
+
this.#composition.observe(input);
|
|
115
|
+
}
|
|
116
|
+
/** Removes composition listeners when the active input is replaced or removed. */
|
|
117
|
+
inputTargetDisconnected(input) {
|
|
118
|
+
this.#composition.unobserve(input);
|
|
119
|
+
}
|
|
120
|
+
/** Commits on `Enter`/delimiter and deletes the last tag on empty `Backspace`. */
|
|
121
|
+
onKeydown(event) {
|
|
122
|
+
if (this.#composition.isComposing(event)) return;
|
|
123
|
+
if (event.key === "Enter" || event.key === this.delimiterValue) {
|
|
124
|
+
event.preventDefault();
|
|
125
|
+
this.#commitInput();
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (event.key === "Backspace" && this.inputTarget.value === "") {
|
|
129
|
+
const buttons = this.#removeButtons;
|
|
130
|
+
if (buttons.length > 0) {
|
|
131
|
+
event.preventDefault();
|
|
132
|
+
this.#removeAt(buttons.length - 1);
|
|
133
|
+
}
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (event.key === "ArrowLeft" && this.inputTarget.value === "") {
|
|
137
|
+
const buttons = this.#removeButtons;
|
|
138
|
+
if (buttons.length > 0) {
|
|
139
|
+
event.preventDefault();
|
|
140
|
+
this.#roving.setActive(buttons.length - 1, { focus: true });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Deletes the tag whose remove button was clicked. Delegated on the tags
|
|
146
|
+
* container (like `#onTagKeydown`) rather than bound per chip via
|
|
147
|
+
* `data-action`, so it works the instant a chip is appended without waiting on
|
|
148
|
+
* Stimulus to wire a freshly created element.
|
|
149
|
+
*/
|
|
150
|
+
#onTagClick = (event) => {
|
|
151
|
+
const button = event.target.closest("button");
|
|
152
|
+
if (!button || !this.tagsTarget.contains(button)) return;
|
|
153
|
+
const index = this.#removeButtons.indexOf(button);
|
|
154
|
+
if (index !== -1) this.#removeAt(index);
|
|
155
|
+
};
|
|
156
|
+
/** Validates and adds the current input value as a tag, then clears the input. */
|
|
157
|
+
#commitInput() {
|
|
158
|
+
const value = this.inputTarget.value.trim();
|
|
159
|
+
if (value === "") {
|
|
160
|
+
this.#reject(value, "empty");
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (this.maxValue > 0 && this.tagTargets.length >= this.maxValue) {
|
|
164
|
+
this.#reject(value, "max");
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (!this.allowDuplicatesValue && this.#values.includes(value)) {
|
|
168
|
+
this.#reject(value, "duplicate");
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
this.#appendTag(value);
|
|
172
|
+
this.inputTarget.value = "";
|
|
173
|
+
this.#announce(value);
|
|
174
|
+
this.#syncState();
|
|
175
|
+
this.dispatch("change", { detail: { tags: this.#values } });
|
|
176
|
+
}
|
|
177
|
+
/** Builds one chip from the template and appends it to the tag list. */
|
|
178
|
+
#appendTag(value) {
|
|
179
|
+
if (!this.hasTagTemplateTarget) return;
|
|
180
|
+
const fragment = this.tagTemplateTarget.content.cloneNode(true);
|
|
181
|
+
const tag = fragment.querySelector('[data-stimeo--tags-input-target="tag"]');
|
|
182
|
+
const label = fragment.querySelector('[data-tags-input-slot="label"]');
|
|
183
|
+
const button = fragment.querySelector("button");
|
|
184
|
+
if (!tag || !button) return;
|
|
185
|
+
tag.dataset.value = value;
|
|
186
|
+
if (label) label.textContent = value;
|
|
187
|
+
button.setAttribute("aria-label", `Remove ${value}`);
|
|
188
|
+
button.tabIndex = -1;
|
|
189
|
+
this.tagsTarget.appendChild(fragment);
|
|
190
|
+
}
|
|
191
|
+
/** Removes the tag at `index`, then moves focus to a neighbor or the input. */
|
|
192
|
+
#removeAt(index) {
|
|
193
|
+
const tag = this.tagTargets[index];
|
|
194
|
+
if (!tag) return;
|
|
195
|
+
const value = tag.dataset.value ?? "";
|
|
196
|
+
tag.remove();
|
|
197
|
+
this.#announce(value);
|
|
198
|
+
this.#syncState();
|
|
199
|
+
this.dispatch("change", { detail: { tags: this.#values } });
|
|
200
|
+
const remaining = this.#removeButtons;
|
|
201
|
+
if (remaining.length === 0) {
|
|
202
|
+
this.inputTarget.focus();
|
|
203
|
+
} else {
|
|
204
|
+
this.#roving.setActive(Math.min(index, remaining.length - 1), { focus: true });
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/** Handles arrow navigation and deletion within the chip list (delegated). */
|
|
208
|
+
#onTagKeydown = (event) => {
|
|
209
|
+
const button = event.target.closest("button");
|
|
210
|
+
if (!button) return;
|
|
211
|
+
const buttons = this.#removeButtons;
|
|
212
|
+
const index = buttons.indexOf(button);
|
|
213
|
+
if (index === -1) return;
|
|
214
|
+
switch (event.key) {
|
|
215
|
+
case "ArrowLeft":
|
|
216
|
+
if (index > 0) {
|
|
217
|
+
event.preventDefault();
|
|
218
|
+
this.#roving.setActive(index - 1, { focus: true });
|
|
219
|
+
}
|
|
220
|
+
break;
|
|
221
|
+
case "ArrowRight":
|
|
222
|
+
event.preventDefault();
|
|
223
|
+
if (index < buttons.length - 1) {
|
|
224
|
+
this.#roving.setActive(index + 1, { focus: true });
|
|
225
|
+
} else {
|
|
226
|
+
this.inputTarget.focus();
|
|
227
|
+
}
|
|
228
|
+
break;
|
|
229
|
+
case "Delete":
|
|
230
|
+
case "Backspace":
|
|
231
|
+
event.preventDefault();
|
|
232
|
+
this.#removeAt(index);
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
/** Rebuilds the hidden form fields, the `full` flag, and the roving Tab stop. */
|
|
237
|
+
#syncState() {
|
|
238
|
+
if (this.hasFieldsTarget) {
|
|
239
|
+
this.fieldsTarget.replaceChildren(
|
|
240
|
+
...this.#values.map((value) => {
|
|
241
|
+
const input = document.createElement("input");
|
|
242
|
+
input.type = "hidden";
|
|
243
|
+
input.name = this.nameValue;
|
|
244
|
+
input.value = value;
|
|
245
|
+
return input;
|
|
246
|
+
})
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
const full = this.maxValue > 0 && this.tagTargets.length >= this.maxValue;
|
|
250
|
+
this.element.toggleAttribute("data-stimeo--tags-input-full", full);
|
|
251
|
+
if (this.#removeButtons.length > 0 && this.#roving.activeIndex === -1) {
|
|
252
|
+
this.#roving.setActive(0);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/** Mirrors the changed tag into the live region for assistive tech. */
|
|
256
|
+
#announce(value) {
|
|
257
|
+
if (this.hasStatusTarget) this.statusTarget.textContent = value;
|
|
258
|
+
}
|
|
259
|
+
/** Reports a rejected addition via `stimeo--tags-input:reject`. */
|
|
260
|
+
#reject(value, reason) {
|
|
261
|
+
this.dispatch("reject", { detail: { value, reason } });
|
|
262
|
+
}
|
|
263
|
+
/** The remove buttons in document order (the roving navigation set). */
|
|
264
|
+
get #removeButtons() {
|
|
265
|
+
return Array.from(this.tagsTarget.querySelectorAll("button"));
|
|
266
|
+
}
|
|
267
|
+
/** Current tag values in order. */
|
|
268
|
+
get #values() {
|
|
269
|
+
return this.tagTargets.map((tag) => tag.dataset.value ?? "");
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
export { TagsInputController };
|
|
274
|
+
//# sourceMappingURL=tags_input_controller.js.map
|
|
275
|
+
//# sourceMappingURL=tags_input_controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/composition_tracker.ts","../../src/utils/roving_tabindex.ts","../../src/controllers/tags_input_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,M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. */\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 * Low-level roving-tabindex primitive shared by composite-widget controllers.\n *\n * The APG roving-tabindex pattern keeps a composite widget a single Tab stop:\n * exactly one item is in the Tab sequence (`tabindex=\"0\"`) while the rest are\n * removed from it (`tabindex=\"-1\"`), and the arrow keys move both DOM focus and\n * that single tabbable position together. {@link RovingTabindex} owns *only* that\n * mechanical bookkeeping — \"which one item is tabbable, and move focus there\".\n *\n * It is intentionally **policy-free**. Orientation, wrapping vs. clamping,\n * selection-follows-focus, typeahead, and `Home`/`End` semantics differ per APG\n * pattern (Radio Group, Toolbar, Rating, …); folding them into one helper would\n * flatten those widgets to a lowest common denominator and lose each pattern's\n * correctness. Those decisions therefore stay in each controller, which calls\n * {@link RovingTabindex.setActive} with an index it computed itself (optionally\n * via the pure {@link rovingMove} helper).\n *\n * @remarks\n * Items are read lazily through a getter so a controller can add or remove\n * targets (Stimulus re-scans the DOM) without re-wiring this helper.\n */\nexport class RovingTabindex {\n /** Returns the current ordered item elements; called on every operation. */\n readonly #getItems: () => HTMLElement[];\n\n /**\n * @param getItems - Returns the current ordered item elements. Called on every\n * operation so the live target list is always used.\n */\n constructor(getItems: () => HTMLElement[]) {\n this.#getItems = getItems;\n }\n\n /** Index of the currently tabbable item (`tabindex=\"0\"`), or `-1` if none. */\n get activeIndex(): number {\n return this.#getItems().findIndex((item) => item.tabIndex === 0);\n }\n\n /**\n * Makes exactly the item at `index` tabbable (`tabindex=\"0\"`) and removes every\n * other item from the Tab sequence (`tabindex=\"-1\"`). An out-of-range `index`\n * (e.g. `-1`) leaves all items at `-1`, which a controller can use to express\n * \"nothing is currently tabbable\".\n *\n * @param index - Position of the item to make tabbable.\n * @param options - Pass `{ focus: true }` to also move DOM focus to that item.\n */\n setActive(index: number, { focus = false }: { focus?: boolean } = {}): void {\n const items = this.#getItems();\n items.forEach((item, i) => {\n item.tabIndex = i === index ? 0 : -1;\n });\n if (focus) items[index]?.focus();\n }\n}\n\n/** Edge behavior for {@link rovingMove}: cycle past the ends, or stop at them. */\nexport type RovingWrap = \"wrap\" | \"clamp\";\n\n/**\n * Pure helper that resolves the target index for a one-step directional move.\n *\n * Keyboard/orientation mapping stays in the caller: it decides that a key means\n * `delta` `+1` (next) or `-1` (previous) and whether the widget should `\"wrap\"`\n * (Radio Group, Toolbar) or `\"clamp\"` at the ends.\n *\n * @param current - The index focus is moving from.\n * @param length - Number of items in the set.\n * @param delta - `+1` to move to the next item, `-1` for the previous.\n * @param wrap - `\"wrap\"` cycles around the ends; `\"clamp\"` stops at them.\n * @returns The resolved index, or `-1` when there are no items.\n */\nexport function rovingMove(\n current: number,\n length: number,\n delta: number,\n wrap: RovingWrap,\n): number {\n if (length === 0) return -1;\n const next = current + delta;\n if (wrap === \"wrap\") return (next + length) % length;\n return Math.min(length - 1, Math.max(0, next));\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { CompositionTracker } from \"../utils/composition_tracker\";\nimport { RovingTabindex } from \"../utils/roving_tabindex\";\n\n/**\n * Headless, accessible free-input tags / chips field.\n *\n * Markup contract (identifier: `stimeo--tags-input`):\n * <div data-controller=\"stimeo--tags-input\"\n * data-stimeo--tags-input-delimiter-value=\",\">\n * <ul role=\"list\" aria-label=\"Tags\" data-stimeo--tags-input-target=\"tags\"></ul>\n * <input type=\"text\" aria-label=\"Add tag\" aria-describedby=\"tags-help\"\n * data-stimeo--tags-input-target=\"input\"\n * data-action=\"keydown->stimeo--tags-input#onKeydown\" />\n * <span role=\"status\" aria-live=\"polite\" class=\"visually-hidden\"\n * data-stimeo--tags-input-target=\"status\"></span>\n * <div data-stimeo--tags-input-target=\"fields\"></div>\n * <template data-stimeo--tags-input-target=\"tagTemplate\">\n * <li role=\"listitem\" data-stimeo--tags-input-target=\"tag\">\n * <span data-tags-input-slot=\"label\"></span>\n * <!-- Removal is delegated on the tags container; no per-chip action needed. -->\n * <button type=\"button\" tabindex=\"-1\">×</button>\n * </li>\n * </template>\n * </div>\n *\n * There is no single established APG pattern; this composes a labeled text input\n * with a roving-tabindex list of removable chips, mapping to WCAG 2.1.1, 2.4.7,\n * 4.1.2, 4.1.3, and 1.3.1. Unlike {@link MultiSelectController} (pick from a\n * candidate list) the user types arbitrary strings.\n *\n * Behavior provided:\n * - `Enter` or the configured delimiter commits the trimmed input as a tag.\n * - Empty / duplicate / over-limit additions are rejected with\n * `stimeo--tags-input:reject`; duplicates are allowed when `allowDuplicates`.\n * - Tags render from the `tagTemplate`, each with a `Remove {label}` button; the\n * `fields` container mirrors the tag set as `name`d hidden inputs for form\n * submission, and every change dispatches `stimeo--tags-input:change`.\n * - The remove buttons form one roving Tab stop: `ArrowLeft`/`ArrowRight` move\n * between them (right past the end returns to the input), `Delete`/`Backspace`\n * delete the focused tag, and `Backspace` on an empty input deletes the last.\n * - Removing a tag moves focus to the neighboring tag, else back to the input.\n */\nexport class TagsInputController extends Controller<HTMLElement> {\n static override targets = [\"input\", \"tags\", \"tag\", \"tagTemplate\", \"status\", \"fields\"];\n static override values = {\n delimiter: { type: String, default: \",\" },\n max: { type: Number, default: 0 },\n allowDuplicates: { type: Boolean, default: false },\n name: { type: String, default: \"tags[]\" },\n };\n static actions = [\"onKeydown\"] as const;\n static events = [\"change\", \"reject\"] as const;\n\n declare readonly inputTarget: HTMLInputElement;\n declare readonly tagsTarget: HTMLElement;\n declare readonly tagTargets: HTMLElement[];\n declare readonly tagTemplateTarget: HTMLTemplateElement;\n declare readonly statusTarget: HTMLElement;\n declare readonly fieldsTarget: HTMLElement;\n declare readonly hasStatusTarget: boolean;\n declare readonly hasFieldsTarget: boolean;\n declare readonly hasTagTemplateTarget: boolean;\n declare readonly hasInputTarget: boolean;\n\n declare delimiterValue: string;\n declare maxValue: number;\n declare allowDuplicatesValue: boolean;\n declare nameValue: string;\n\n readonly #roving = new RovingTabindex(() => this.#removeButtons);\n /** Owns IME lifecycle state for commit-key guarding. */\n readonly #composition = new CompositionTracker();\n\n /** Wires tag-list keyboard navigation and removal, and seeds the single Tab stop. */\n override connect(): void {\n if (this.hasInputTarget) this.#composition.observe(this.inputTarget);\n this.tagsTarget.addEventListener(\"keydown\", this.#onTagKeydown);\n this.tagsTarget.addEventListener(\"click\", this.#onTagClick);\n this.#syncState();\n }\n\n /** Releases the delegated listeners so no handler outlives the element. */\n override disconnect(): void {\n this.#composition.disconnect();\n this.tagsTarget.removeEventListener(\"keydown\", this.#onTagKeydown);\n this.tagsTarget.removeEventListener(\"click\", this.#onTagClick);\n }\n\n /** Tracks an input added initially or after connect. */\n inputTargetConnected(input: HTMLInputElement): void {\n this.#composition.observe(input);\n }\n\n /** Removes composition listeners when the active input is replaced or removed. */\n inputTargetDisconnected(input: HTMLInputElement): void {\n this.#composition.unobserve(input);\n }\n\n /** Commits on `Enter`/delimiter and deletes the last tag on empty `Backspace`. */\n onKeydown(event: KeyboardEvent): void {\n // Ignore keys fired during IME composition: the `Enter` that confirms a\n // candidate (and arrows that move within it) must not commit/navigate the\n // chip list. Controller-owned lifecycle state covers confirming events that\n // omit the standard per-event signal.\n if (this.#composition.isComposing(event)) return;\n if (event.key === \"Enter\" || event.key === this.delimiterValue) {\n event.preventDefault();\n this.#commitInput();\n return;\n }\n if (event.key === \"Backspace\" && this.inputTarget.value === \"\") {\n const buttons = this.#removeButtons;\n if (buttons.length > 0) {\n event.preventDefault();\n this.#removeAt(buttons.length - 1);\n }\n return;\n }\n if (event.key === \"ArrowLeft\" && this.inputTarget.value === \"\") {\n const buttons = this.#removeButtons;\n if (buttons.length > 0) {\n event.preventDefault();\n this.#roving.setActive(buttons.length - 1, { focus: true });\n }\n }\n }\n\n /**\n * Deletes the tag whose remove button was clicked. Delegated on the tags\n * container (like `#onTagKeydown`) rather than bound per chip via\n * `data-action`, so it works the instant a chip is appended without waiting on\n * Stimulus to wire a freshly created element.\n */\n readonly #onTagClick = (event: MouseEvent): void => {\n const button = (event.target as HTMLElement).closest(\"button\");\n if (!button || !this.tagsTarget.contains(button)) return;\n const index = this.#removeButtons.indexOf(button as HTMLButtonElement);\n if (index !== -1) this.#removeAt(index);\n };\n\n /** Validates and adds the current input value as a tag, then clears the input. */\n #commitInput(): void {\n const value = this.inputTarget.value.trim();\n if (value === \"\") {\n this.#reject(value, \"empty\");\n return;\n }\n if (this.maxValue > 0 && this.tagTargets.length >= this.maxValue) {\n this.#reject(value, \"max\");\n return;\n }\n if (!this.allowDuplicatesValue && this.#values.includes(value)) {\n this.#reject(value, \"duplicate\");\n return;\n }\n this.#appendTag(value);\n this.inputTarget.value = \"\";\n this.#announce(value);\n this.#syncState();\n this.dispatch(\"change\", { detail: { tags: this.#values } });\n }\n\n /** Builds one chip from the template and appends it to the tag list. */\n #appendTag(value: string): void {\n if (!this.hasTagTemplateTarget) return;\n const fragment = this.tagTemplateTarget.content.cloneNode(true) as DocumentFragment;\n const tag = fragment.querySelector<HTMLElement>('[data-stimeo--tags-input-target=\"tag\"]');\n const label = fragment.querySelector<HTMLElement>('[data-tags-input-slot=\"label\"]');\n const button = fragment.querySelector<HTMLButtonElement>(\"button\");\n if (!tag || !button) return;\n tag.dataset.value = value;\n if (label) label.textContent = value;\n button.setAttribute(\"aria-label\", `Remove ${value}`);\n button.tabIndex = -1;\n this.tagsTarget.appendChild(fragment);\n }\n\n /** Removes the tag at `index`, then moves focus to a neighbor or the input. */\n #removeAt(index: number): void {\n const tag = this.tagTargets[index];\n if (!tag) return;\n const value = tag.dataset.value ?? \"\";\n tag.remove();\n this.#announce(value);\n this.#syncState();\n this.dispatch(\"change\", { detail: { tags: this.#values } });\n const remaining = this.#removeButtons;\n if (remaining.length === 0) {\n this.inputTarget.focus();\n } else {\n this.#roving.setActive(Math.min(index, remaining.length - 1), { focus: true });\n }\n }\n\n /** Handles arrow navigation and deletion within the chip list (delegated). */\n readonly #onTagKeydown = (event: KeyboardEvent): void => {\n const button = (event.target as HTMLElement).closest(\"button\");\n if (!button) return;\n const buttons = this.#removeButtons;\n const index = buttons.indexOf(button);\n if (index === -1) return;\n switch (event.key) {\n case \"ArrowLeft\":\n if (index > 0) {\n event.preventDefault();\n this.#roving.setActive(index - 1, { focus: true });\n }\n break;\n case \"ArrowRight\":\n event.preventDefault();\n if (index < buttons.length - 1) {\n this.#roving.setActive(index + 1, { focus: true });\n } else {\n this.inputTarget.focus();\n }\n break;\n case \"Delete\":\n case \"Backspace\":\n event.preventDefault();\n this.#removeAt(index);\n break;\n default:\n break;\n }\n };\n\n /** Rebuilds the hidden form fields, the `full` flag, and the roving Tab stop. */\n #syncState(): void {\n if (this.hasFieldsTarget) {\n this.fieldsTarget.replaceChildren(\n ...this.#values.map((value) => {\n const input = document.createElement(\"input\");\n input.type = \"hidden\";\n input.name = this.nameValue;\n input.value = value;\n return input;\n }),\n );\n }\n const full = this.maxValue > 0 && this.tagTargets.length >= this.maxValue;\n this.element.toggleAttribute(\"data-stimeo--tags-input-full\", full);\n // Keep exactly one remove button tabbable so the chip list is a single stop.\n if (this.#removeButtons.length > 0 && this.#roving.activeIndex === -1) {\n this.#roving.setActive(0);\n }\n }\n\n /** Mirrors the changed tag into the live region for assistive tech. */\n #announce(value: string): void {\n if (this.hasStatusTarget) this.statusTarget.textContent = value;\n }\n\n /** Reports a rejected addition via `stimeo--tags-input:reject`. */\n #reject(value: string, reason: \"duplicate\" | \"empty\" | \"max\"): void {\n this.dispatch(\"reject\", { detail: { value, reason } });\n }\n\n /** The remove buttons in document order (the roving navigation set). */\n get #removeButtons(): HTMLButtonElement[] {\n return Array.from(this.tagsTarget.querySelectorAll<HTMLButtonElement>(\"button\"));\n }\n\n /** Current tag values in order. */\n get #values(): string[] {\n return this.tagTargets.map((tag) => tag.dataset.value ?? \"\");\n }\n}\n"]}
|
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
import { Controller } from '@hotwired/stimulus';
|
|
2
2
|
|
|
3
|
+
// src/controllers/theme_controller.ts
|
|
4
|
+
|
|
5
|
+
// src/utils/safe_storage.ts
|
|
6
|
+
function readLocalStorage(key) {
|
|
7
|
+
try {
|
|
8
|
+
return window.localStorage.getItem(key);
|
|
9
|
+
} catch {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function writeLocalStorage(key, value) {
|
|
14
|
+
try {
|
|
15
|
+
window.localStorage.setItem(key, value);
|
|
16
|
+
} catch {
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
3
20
|
// src/controllers/theme_controller.ts
|
|
4
21
|
var MODES = ["light", "dark", "system"];
|
|
5
22
|
var isMode = (value) => typeof value === "string" && MODES.includes(value);
|
|
@@ -133,19 +150,12 @@ var ThemeController = class extends Controller {
|
|
|
133
150
|
}
|
|
134
151
|
/** Reads a persisted, validated mode from `localStorage` (null when absent/blocked). */
|
|
135
152
|
#readStored() {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
return isMode(value) ? value : null;
|
|
139
|
-
} catch {
|
|
140
|
-
return null;
|
|
141
|
-
}
|
|
153
|
+
const value = readLocalStorage(this.storageKeyValue);
|
|
154
|
+
return isMode(value) ? value : null;
|
|
142
155
|
}
|
|
143
156
|
/** Persists the mode, swallowing storage errors (private mode / quota). */
|
|
144
157
|
#writeStored(mode) {
|
|
145
|
-
|
|
146
|
-
window.localStorage.setItem(this.storageKeyValue, mode);
|
|
147
|
-
} catch {
|
|
148
|
-
}
|
|
158
|
+
writeLocalStorage(this.storageKeyValue, mode);
|
|
149
159
|
}
|
|
150
160
|
};
|
|
151
161
|
|