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/declared_value.ts","../../src/utils/intersection_watcher.ts","../../src/controllers/lazy_frame_controller.ts"],"names":[],"mappings":";;;;;AAuBO,SAAS,aAAA,CAAiB,GAAA,EAAa,KAAA,EAA2B,QAAA,EAAgB;AACvF,EAAA,IAAI;AACF,IAAA,OAAO,MAAM,GAAG,CAAA;AAAA,EAClB,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,QAAA;AAAA,EACT;AACF;;;ACoBA,SAAS,UAAU,QAAA,EAA8C;AAC/D,EAAA,IAAI,CAAC,UAAU,OAAO,IAAA;AACtB,EAAA,OAAO,aAAA,CAAc,UAAU,CAAC,GAAA,KAAQ,SAAS,aAAA,CAAc,GAAG,GAAG,IAAI,CAAA;AAC3E;AAiBO,IAAM,sBAAN,MAA0B;AAAA,EACtB,UAAA;AAAA,EACT,SAAA,GAAyC,IAAA;AAAA,EACzC,OAAA,GAAU,KAAA;AAAA,EACV,sBAAA,GAAyB,KAAA;AAAA,EAEzB,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,EAGA,IAAI,qBAAA,GAAiC;AACnC,IAAA,OAAO,IAAA,CAAK,sBAAA;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBA,KAAA,CAAM,OAAA,EAAuC,OAAA,GAAoC,EAAC,EAAY;AAC5F,IAAA,IAA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QAAQ,CAAA;AACzD,IAAA,IAAI,IAAA,CAAK,SAAA,EAAW,IAAA,CAAK,QAAA,CAAS,IAAA,EAAK;AAAA,EACzC;AAAA;AAAA,EAGA,OAAA,GAAgB;AACd,IAAA,MAAM,GAAA,GAAM,IAAA,CAAK,OAAA,CAAQ,YAAA,CAAa,KAAK,CAAA;AAC3C,IAAA,IAAI,IAAA,CAAK,QAAA,IAAY,IAAA,CAAK,QAAA,KAAa,GAAA,EAAK;AAG1C,MAAA,IAAA,CAAK,OAAA,CAAQ,YAAA,CAAa,KAAA,EAAO,IAAA,CAAK,QAAQ,CAAA;AAC9C,MAAA,IAAA,CAAK,QAAA,CAAS,QAAQ,EAAE,MAAA,EAAQ,EAAE,GAAA,EAAK,IAAA,CAAK,QAAA,EAAS,EAAG,CAAA;AACxD,MAAA;AAAA,IACF;AACA,IAAA,MAAM,QAAQ,IAAA,CAAK,OAAA;AAInB,IAAA,IAAI,OAAO,KAAA,CAAM,MAAA,KAAW,UAAA,EAAY;AACxC,IAAA,KAAA,CAAM,MAAA,EAAO;AACb,IAAA,IAAA,CAAK,QAAA,CAAS,QAAQ,EAAE,MAAA,EAAQ,EAAE,GAAA,EAAK,GAAA,IAAO,EAAA,EAAG,EAAG,CAAA;AAAA,EACtD;AAAA,EAEA,cAAA,GAAuB;AACrB,IAAA,IAAA,CAAK,SAAS,IAAA,EAAK;AACnB,IAAA,IAAA,CAAK,OAAA,CAAQ,mBAAA,CAAoB,SAAA,EAAW,IAAA,CAAK,QAAQ,CAAA;AAAA,EAC3D;AACF","file":"lazy_frame_controller.js","sourcesContent":["/**\n * Readers for the String Values whose text can only be checked by handing it to\n * a parser: a CSS selector, a regular-expression source, a JSON object.\n *\n * Stimulus reads each of them as an ordinary string, so the controller connects\n * and the flaw surfaces later, inside the first handler that consumes the value\n * (a `SyntaxError` from `new RegExp`, a `DOMException` from the selector engine),\n * where it takes the whole handler down on every event. Parsing here, once, in\n * the `<name>ValueChanged` callback keeps the failure local to the declaration:\n * an unreadable value falls back to its default, the element stays alive, and\n * the hot path only ever receives a value that parsed.\n *\n * Which default a broken declaration falls back to is the caller's contract, so\n * every reader takes (or returns) the fallback rather than choosing one.\n */\n\n/**\n * The result of `parse(raw)`, or `fallback` when `parse` throws.\n *\n * Any exception counts as \"does not parse\": the parsers these Values feed\n * (`RegExp`, `JSON.parse`, the selector engine) all report a malformed input by\n * throwing, and none of them throws for another reason.\n */\nexport function parseDeclared<T>(raw: string, parse: (raw: string) => T, fallback: T): T {\n try {\n return parse(raw);\n } catch {\n return fallback;\n }\n}\n\n/** What {@link validSelector} needs of the element it probes with. */\nexport interface SelectorProbe {\n matches(selector: string): boolean;\n}\n\n/**\n * `raw` when it is a non-empty selector the DOM accepts, otherwise `fallback`.\n *\n * `element.matches` is the probe: the engine parses the selector and throws for\n * one it cannot read. Whether the selector actually matches `element` plays no\n * part, so a selector aimed at another element still passes.\n *\n * The parameter names the one method the probe uses rather than `Element`, so\n * this module carries no DOM type and the readers below stay importable from\n * the Node-side Inspector, which checks the same declarations statically.\n */\nexport function validSelector(element: SelectorProbe, raw: string, fallback: string): string {\n if (raw.length === 0) return fallback;\n return parseDeclared(\n raw,\n (selector) => {\n element.matches(selector);\n return selector;\n },\n fallback,\n );\n}\n\n/** How `compileRegExp` wraps a source before compiling it. */\nexport type RegExpAnchor = \"none\" | \"exact\";\n\n/**\n * `source` compiled as a `RegExp`, or `null` when it does not compile.\n *\n * `\"exact\"` wraps the source as `^(?:source)$`, so the whole input has to match\n * and an alternation inside the source cannot escape the anchors. The source is\n * compiled on its own first, because an unbalanced source can be made to parse\n * by the wrapper's own parentheses — `0)|(1` becomes `^(?:0)|(1)$` — which would\n * accept a declaration that is not a regular expression and leave half of it\n * outside the anchors. The default that replaces a broken source is the\n * caller's, so `null` is returned rather than a fallback pattern.\n */\nexport function compileRegExp(source: string, anchor: RegExpAnchor = \"none\"): RegExp | null {\n return parseDeclared(\n source,\n (text) => {\n const bare = new RegExp(text);\n return anchor === \"exact\" ? new RegExp(`^(?:${text})$`) : bare;\n },\n null,\n );\n}\n\n/**\n * The JSON object `raw` declares, or `null` when the text does not parse or\n * parses to something other than a plain object (`null`, an array, a scalar).\n * Values are returned as parsed; narrowing them is the caller's contract.\n */\nexport function parseJsonObject(raw: string): Record<string, unknown> | null {\n const parsed = parseDeclared<unknown>(raw, (text) => JSON.parse(text), null);\n if (parsed === null || typeof parsed !== \"object\" || Array.isArray(parsed)) return null;\n return parsed as Record<string, unknown>;\n}\n","/**\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 (degrading to the viewport rather than failing), observer\n * 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 `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\nimport { parseDeclared } from \"./declared_value\";\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\n/**\n * Resolves an observation root from a selector. Every reading of \"no root\" ends\n * at the same place — absent, matching nothing, or not parsing at all (a typo in\n * a data attribute) — so the observation falls back to the viewport instead of\n * leaving the caller inert with no state hooks published at all.\n */\nfunction queryRoot(selector: string | undefined): Element | null {\n if (!selector) return null;\n return parseDeclared(selector, (raw) => document.querySelector(raw), null);\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 /**\n * Selector for the observation root; empty/omitted = viewport. A selector\n * that matches nothing or does not parse also means the viewport.\n */\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 #usingPlatformDefaults = 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 /** Whether the live observer discarded configured options after construction failed. */\n get usingPlatformDefaults(): boolean {\n return this.#usingPlatformDefaults;\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 * If initial construction with the configured options fails, the watcher\n * warns and retries once with the same root and platform defaults. A\n * `rootSelector` that does not parse resolves to the viewport (see\n * {@link IntersectionWatchOptions.rootSelector}), so a typo never fails the\n * call.\n *\n * @throws The fallback constructor error if both construction attempts fail,\n * or whatever the platform throws from `observe()`. The exception is passed\n * through unchanged, but the watcher rolls back first: every target observed\n * so far is released and `active` stays `false`, so a caller that retries\n * 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 = \"root\" in options ? (options.root ?? null) : queryRoot(options.rootSelector);\n\n let observer: IntersectionObserver | null = null;\n try {\n const onEntries = (entries: IntersectionObserverEntry[]): void => {\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 try {\n observer = new IntersectionObserver(onEntries, {\n root,\n rootMargin: options.rootMargin,\n threshold: options.threshold,\n });\n } catch (error) {\n console.warn(\n \"Stimeo UI: IntersectionObserver could not be constructed with the configured options; retrying with platform defaults.\",\n error,\n );\n observer = new IntersectionObserver(onEntries, { root });\n this.#usingPlatformDefaults = true;\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 this.#usingPlatformDefaults = 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 this.#usingPlatformDefaults = false;\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { IntersectionWatcher } from \"../utils/intersection_watcher\";\n\n/**\n * Headless **lazy frame**: defers a `<turbo-frame>`'s load until it nears the viewport\n * (or focus reaches it), to keep the initial render light. Turbo's own `loading=\"lazy\"`\n * observes with no margin, so the frame loads only once it is already in view; this\n * drives an explicit `IntersectionObserver` with a configurable `rootMargin`, plus a focus fallback so keyboard /\n * assistive-tech users trigger the load too (no APG pattern).\n *\n * Markup contract (identifier: `stimeo--lazy-frame`):\n * <turbo-frame id=\"comments\" data-controller=\"stimeo--lazy-frame\"\n * data-stimeo--lazy-frame-url-value=\"/posts/1/comments\"\n * data-stimeo--lazy-frame-root-margin-value=\"200px\">Loading…</turbo-frame>\n *\n * The URL is *held* in the `url` value (not on `src`) so Turbo does not load it eagerly;\n * when the frame intersects (within `rootMargin`) or focus enters it, the controller\n * writes `url` to `src` — **writing `src` is what starts the fetch** — marks\n * `data-lazy-loaded`, and emits `load`. Focus is the fallback for the *first* load only;\n * once the frame has loaded, its listener is released and further focus moves inside the\n * frame change nothing.\n *\n * With `once` (default) the controller then stops observing. With `once` off it keeps\n * watching and re-fetches on a **re-entry** — the frame has to be seen inside the\n * observed area, leave it, and come back. Where a connection first finds the frame is the\n * baseline rather than a movement, so a focus-started load and a cache restore each begin\n * the visit wherever the frame sits — in view or out of it — and re-fetch nothing until it\n * leaves and returns. A re-entry serves the held `url`: when it still matches `src`, the\n * host's own `reload()` refetches it; when it has moved on, writing the new `url` to `src`\n * is the fetch.\n *\n * `load` dispatches `{ url }` — always the URL the fetch actually started for.\n *\n * @remarks\n * Behavior only — the load itself and the frame's content are Turbo's / the server's job,\n * and the loading UI (skeleton / `aria-busy`) belongs to `stimeo--frame-loading`. The trigger\n * is idempotent (`data-lazy-loaded` guards a double load and is the truth source on a\n * Turbo cache restore: a restored frame is observed again only while `once` is off, which\n * is the mode that asked to keep re-fetching). An empty `url` arms nothing and is never\n * written to `src`. The `IntersectionObserver` and focus listener are released once loaded\n * (when `once`) and on `disconnect()` (Turbo navigation included).\n */\nexport class LazyFrameController extends Controller<HTMLElement> {\n static override values = {\n url: { type: String, default: \"\" },\n rootMargin: { type: String, default: \"0px\" },\n once: { type: Boolean, default: true },\n };\n static events = [\"load\"] as const;\n\n declare urlValue: string;\n declare rootMarginValue: string;\n declare onceValue: boolean;\n\n /** Shared IO plumbing (support guard, active guard, teardown). */\n readonly #watcher = new IntersectionWatcher((entries) => this.#onIntersect(entries));\n #connected = false;\n #loaded = false;\n /**\n * Whether the observer last saw the frame inside the observed area — `null`\n * until it has reported. A re-entry needs a frame that was seen inside and\n * then left, so an unknown position is never a departure.\n */\n #inside: boolean | null = null;\n\n /**\n * Focus reaching the frame starts the FIRST load before it intersects (keyboard / AT).\n * `#load` releases this listener, so focus never reaches an already-loaded frame.\n */\n readonly #onFocus = (): void => this.#load();\n\n /**\n * Follows the held URL at runtime: one that arrives arms the frame, one that is\n * taken away disarms it, so an empty `url` holds no triggers either way.\n *\n * Stimulus runs value callbacks before `connect()`, so the connected guard keeps\n * arming in one place. A frame that already loaded keeps its held URL for the next\n * re-entry instead of fetching on the spot.\n */\n urlValueChanged(): void {\n if (!this.#connected || this.#loaded) return;\n if (this.urlValue) this.#arm();\n else this.#stopObserving();\n }\n\n /** Rebuilds the observer when the early-load margin changes at runtime. */\n rootMarginValueChanged(): void {\n if (this.#connected && this.#watcher.active) this.#observe();\n }\n\n override connect(): void {\n // `data-lazy-loaded` is the truth source across a cache restore, and `once`\n // decides whether a restored frame still has anything to watch for.\n this.#loaded = this.element.hasAttribute(\"data-lazy-loaded\");\n this.#inside = null;\n this.#connected = true;\n if (this.#loaded && this.onceValue) return;\n this.#arm();\n }\n\n override disconnect(): void {\n this.#connected = false;\n this.#stopObserving();\n }\n\n /** Attaches the triggers that still have a job to do. */\n #arm(): void {\n if (!this.urlValue) return;\n if (!this.#loaded) this.element.addEventListener(\"focusin\", this.#onFocus);\n this.#observe();\n }\n\n #observe(): void {\n this.#watcher.start(this.element, { rootMargin: this.rootMarginValue });\n }\n\n #onIntersect(entries: IntersectionObserverEntry[]): void {\n for (const entry of entries) {\n if (entry.isIntersecting) {\n const returning = this.#inside === false;\n this.#inside = true;\n this.#enter(returning);\n } else if (this.#inside) {\n // An observer reports where the frame is before it reports any movement,\n // so only a frame already seen inside can be leaving.\n this.#inside = false;\n }\n }\n }\n\n /** Applies an intersecting entry: the first one loads, a return re-fetches. */\n #enter(returning: boolean): void {\n if (!this.#loaded) {\n this.#load();\n return;\n }\n if (this.onceValue || !returning) return;\n this.#reload();\n }\n\n /** Starts the load by writing the held URL to `src`. */\n #load(): void {\n if (!this.urlValue) return;\n this.#loaded = true;\n this.element.setAttribute(\"src\", this.urlValue);\n this.element.setAttribute(\"data-lazy-loaded\", \"true\");\n this.dispatch(\"load\", { detail: { url: this.urlValue } });\n // The focus fallback exists to start the first load; it has nothing left to do.\n this.element.removeEventListener(\"focusin\", this.#onFocus);\n if (this.onceValue) this.#watcher.stop();\n }\n\n /** Re-entry while `once` is off: fetch the held URL again. */\n #reload(): void {\n const src = this.element.getAttribute(\"src\");\n if (this.urlValue && this.urlValue !== src) {\n // The held URL moved on. Writing it to `src` is the fetch, the same start\n // the first load uses, so it works on any host.\n this.element.setAttribute(\"src\", this.urlValue);\n this.dispatch(\"load\", { detail: { url: this.urlValue } });\n return;\n }\n const frame = this.element as HTMLElement & { reload?: () => void };\n // Refetching the URL already on `src` needs the host's own `reload()`. On a\n // non-`<turbo-frame>` host there is none, and firing `load` would announce a\n // fetch that never started.\n if (typeof frame.reload !== \"function\") return;\n frame.reload();\n this.dispatch(\"load\", { detail: { url: src ?? \"\" } });\n }\n\n #stopObserving(): void {\n this.#watcher.stop();\n this.element.removeEventListener(\"focusin\", this.#onFocus);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/declared_value.ts","../../src/utils/intersection_watcher.ts","../../src/controllers/lazy_frame_controller.ts"],"names":[],"mappings":";;;;;AAuBO,SAAS,aAAA,CAAiB,GAAA,EAAa,KAAA,EAA2B,QAAA,EAAgB;AACvF,EAAA,IAAI;AACF,IAAA,OAAO,MAAM,GAAG,CAAA;AAA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AA,CAAK,QAAQ,CAAA;AAC9C,MAAA,IAAA,CAAK,QAAA,CAAS,QAAQ,EAAE,MAAA,EAAQ,EAAE,GAAA,EAAK,IAAA,CAAK,QAAA,EAAS,EAAG,CAAA;AACxD,MAAA;AAAA,IACF;AACA,IAAA,MAAM,QAAQ,IAAA,CAAK,OAAA;AAInB,IAAA,IAAI,OAAO,KAAA,CAAM,MAAA,KAAW,UAAA,EAAY;AACxC,IAAA,KAAA,CAAM,MAAA,EAAO;AACb,IAAA,IAAA,CAAK,QAAA,CAAS,QAAQ,EAAE,MAAA,EAAQ,EAAE,GAAA,EAAK,GAAA,IAAO,EAAA,EAAG,EAAG,CAAA;AAAA,EACtD;AAAA,EAEA,cAAA,GAAuB;AACrB,IAAA,IAAA,CAAK,SAAS,IAAA,EAAK;AACnB,IAAA,IAAA,CAAK,OAAA,CAAQ,mBAAA,CAAoB,SAAA,EAAW,IAAA,CAAK,QAAQ,CAAA;AAAA,EAC3D;AACF","file":"lazy_frame_controller.js","sourcesContent":["/**\n * Readers for the String Values whose text can only be checked by handing it to\n * a parser: a CSS selector, a regular-expression source, a JSON object.\n *\n * Stimulus reads each of them as an ordinary string, so the controller connects\n * and the flaw surfaces later, inside the first handler that consumes the value\n * (a `SyntaxError` from `new RegExp`, a `DOMException` from the selector engine),\n * where it takes the whole handler down on every event. Parsing here, once, in\n * the `<name>ValueChanged` callback keeps the failure local to the declaration:\n * an unreadable value falls back to its default, the element stays alive, and\n * the hot path only ever receives a value that parsed.\n *\n * Which default a broken declaration falls back to is the caller's contract, so\n * every reader takes (or returns) the fallback rather than choosing one.\n */\n\n/**\n * The result of `parse(raw)`, or `fallback` when `parse` throws.\n *\n * Any exception counts as \"does not parse\": the parsers these Values feed\n * (`RegExp`, `JSON.parse`, the selector engine) all report a malformed input by\n * throwing, and none of them throws for another reason.\n */\nexport function parseDeclared<T>(raw: string, parse: (raw: string) => T, fallback: T): T {\n try {\n return parse(raw);\n } catch {\n return fallback;\n }\n}\n\n/** What {@link validSelector} needs of the element it probes with. */\nexport interface SelectorProbe {\n matches(selector: string): boolean;\n}\n\n/**\n * `raw` when it is a non-empty selector the DOM accepts, otherwise `fallback`.\n *\n * `element.matches` is the probe: the engine parses the selector and throws for\n * one it cannot read. Whether the selector actually matches `element` plays no\n * part, so a selector aimed at another element still passes.\n *\n * The parameter names the one method the probe uses rather than `Element`, so\n * this module carries no DOM type and the readers below stay importable from\n * the Node-side Inspector, which checks the same declarations statically.\n */\nexport function validSelector(element: SelectorProbe, raw: string, fallback: string): string {\n if (raw.length === 0) return fallback;\n return parseDeclared(\n raw,\n (selector) => {\n element.matches(selector);\n return selector;\n },\n fallback,\n );\n}\n\n/** How `compileRegExp` wraps a source before compiling it. */\nexport type RegExpAnchor = \"none\" | \"exact\";\n\n/**\n * `source` compiled as a `RegExp`, or `null` when it does not compile.\n *\n * `\"exact\"` wraps the source as `^(?:source)$`, so the whole input has to match\n * and an alternation inside the source cannot escape the anchors. The source is\n * compiled on its own first, because an unbalanced source can be made to parse\n * by the wrapper's own parentheses — `0)|(1` becomes `^(?:0)|(1)$` — which would\n * accept a declaration that is not a regular expression and leave half of it\n * outside the anchors. The default that replaces a broken source is the\n * caller's, so `null` is returned rather than a fallback pattern.\n */\nexport function compileRegExp(source: string, anchor: RegExpAnchor = \"none\"): RegExp | null {\n return parseDeclared(\n source,\n (text) => {\n const bare = new RegExp(text);\n return anchor === \"exact\" ? new RegExp(`^(?:${text})$`) : bare;\n },\n null,\n );\n}\n\n/**\n * The JSON object `raw` declares, or `null` when the text does not parse or\n * parses to something other than a plain object (`null`, an array, a scalar).\n * Values are returned as parsed; narrowing them is the caller's contract.\n */\nexport function parseJsonObject(raw: string): Record<string, unknown> | null {\n const parsed = parseDeclared<unknown>(raw, (text) => JSON.parse(text), null);\n if (parsed === null || typeof parsed !== \"object\" || Array.isArray(parsed)) return null;\n return parsed as Record<string, unknown>;\n}\n","/**\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 (degrading to the viewport rather than failing), observer\n * 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 `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\nimport { parseDeclared } from \"./declared_value\";\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\n/**\n * Resolves an observation root from a selector. Every reading of \"no root\" ends\n * at the same place — absent, matching nothing, or not parsing at all (a typo in\n * a data attribute) — so the observation falls back to the viewport instead of\n * leaving the caller inert with no state hooks published at all.\n */\nfunction queryRoot(selector: string | undefined): Element | null {\n if (!selector) return null;\n return parseDeclared(selector, (raw) => document.querySelector(raw), null);\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 /**\n * Selector for the observation root; empty/omitted = viewport. A selector\n * that matches nothing or does not parse also means the viewport.\n */\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 #usingPlatformDefaults = 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 /** Whether the live observer discarded configured options after construction failed. */\n get usingPlatformDefaults(): boolean {\n return this.#usingPlatformDefaults;\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 * If initial construction with the configured options fails, the watcher\n * warns and retries once with the same root and platform defaults. A\n * `rootSelector` that does not parse resolves to the viewport (see\n * {@link IntersectionWatchOptions.rootSelector}), so a typo never fails the\n * call.\n *\n * @throws The fallback constructor error if both construction attempts fail,\n * or whatever the platform throws from `observe()`. The exception is passed\n * through unchanged, but the watcher rolls back first: every target observed\n * so far is released and `active` stays `false`, so a caller that retries\n * 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 = \"root\" in options ? (options.root ?? null) : queryRoot(options.rootSelector);\n\n let observer: IntersectionObserver | null = null;\n try {\n const onEntries = (entries: IntersectionObserverEntry[]): void => {\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 try {\n observer = new IntersectionObserver(onEntries, {\n root,\n rootMargin: options.rootMargin,\n threshold: options.threshold,\n });\n } catch (error) {\n console.warn(\n \"Stimeo UI: IntersectionObserver could not be constructed with the configured options; retrying with platform defaults.\",\n error,\n );\n observer = new IntersectionObserver(onEntries, { root });\n this.#usingPlatformDefaults = true;\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 this.#usingPlatformDefaults = 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 this.#usingPlatformDefaults = false;\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { IntersectionWatcher } from \"../utils/intersection_watcher\";\n\n/**\n * Headless **lazy frame**: defers a `<turbo-frame>`'s load until it nears the viewport\n * (or focus reaches it), to keep the initial render light. Turbo's own `loading=\"lazy\"`\n * observes with no margin, so the frame loads only once it is already in view; this\n * drives an explicit `IntersectionObserver` with a configurable `rootMargin`, plus a focus fallback so keyboard /\n * assistive-tech users trigger the load too (no APG pattern).\n *\n * Markup contract (identifier: `stimeo--lazy-frame`):\n * <turbo-frame id=\"comments\" data-controller=\"stimeo--lazy-frame\"\n * data-stimeo--lazy-frame-url-value=\"/posts/1/comments\"\n * data-stimeo--lazy-frame-root-margin-value=\"200px\">Loading…</turbo-frame>\n *\n * The URL is *held* in the `url` value (not on `src`) so Turbo does not load it eagerly;\n * when the frame intersects (within `rootMargin`) or focus enters it, the controller\n * writes `url` to `src` — **writing `src` is what starts the fetch** — marks\n * `data-lazy-loaded`, and emits `load`. Focus is the fallback for the *first* load only;\n * once the frame has loaded, its listener is released and further focus moves inside the\n * frame change nothing.\n *\n * With `once` (default) the controller then stops observing. With `once` off it keeps\n * watching and re-fetches on a **re-entry** — the frame has to be seen inside the\n * observed area, leave it, and come back. Where a connection first finds the frame is the\n * baseline rather than a movement, so a focus-started load and a cache restore each begin\n * the visit wherever the frame sits — in view or out of it — and re-fetch nothing until it\n * leaves and returns. A re-entry serves the held `url`: when it still matches `src`, the\n * host's own `reload()` refetches it; when it has moved on, writing the new `url` to `src`\n * is the fetch.\n *\n * `load` dispatches `{ url }` — always the URL the fetch actually started for.\n *\n * @remarks\n * Behavior only — the load itself and the frame's content are Turbo's / the server's job,\n * and the loading UI (skeleton / `aria-busy`) belongs to `stimeo--frame-loading`. The trigger\n * is idempotent (`data-lazy-loaded` guards a double load and is the truth source on a\n * Turbo cache restore: a restored frame is observed again only while `once` is off, which\n * is the mode that asked to keep re-fetching). An empty `url` arms nothing and is never\n * written to `src`. The `IntersectionObserver` and focus listener are released once loaded\n * (when `once`) and on `disconnect()` (Turbo navigation included).\n */\nexport class LazyFrameController extends Controller<HTMLElement> {\n static override values = {\n url: { type: String, default: \"\" },\n rootMargin: { type: String, default: \"0px\" },\n once: { type: Boolean, default: true },\n };\n static events = [\"load\"] as const;\n\n declare urlValue: string;\n declare rootMarginValue: string;\n declare onceValue: boolean;\n\n /** Shared IO plumbing (support guard, active guard, teardown). */\n readonly #watcher = new IntersectionWatcher((entries) => this.#onIntersect(entries));\n #connected = false;\n #loaded = false;\n /**\n * Whether the observer last saw the frame inside the observed area — `null`\n * until it has reported. A re-entry needs a frame that was seen inside and\n * then left, so an unknown position is never a departure.\n */\n #inside: boolean | null = null;\n\n /**\n * Focus reaching the frame starts the FIRST load before it intersects (keyboard / AT).\n * `#load` releases this listener, so focus never reaches an already-loaded frame.\n */\n readonly #onFocus = (): void => this.#load();\n\n /**\n * Follows the held URL at runtime: one that arrives arms the frame, one that is\n * taken away disarms it, so an empty `url` holds no triggers either way.\n *\n * Stimulus runs value callbacks before `connect()`, so the connected guard keeps\n * arming in one place. A frame that already loaded keeps its held URL for the next\n * re-entry instead of fetching on the spot.\n */\n urlValueChanged(): void {\n if (!this.#connected || this.#loaded) return;\n if (this.urlValue) this.#arm();\n else this.#stopObserving();\n }\n\n /** Rebuilds the observer when the early-load margin changes at runtime. */\n rootMarginValueChanged(): void {\n if (this.#connected && this.#watcher.active) this.#observe();\n }\n\n override connect(): void {\n // `data-lazy-loaded` is the truth source across a cache restore, and `once`\n // decides whether a restored frame still has anything to watch for.\n this.#loaded = this.element.hasAttribute(\"data-lazy-loaded\");\n this.#inside = null;\n this.#connected = true;\n if (this.#loaded && this.onceValue) return;\n this.#arm();\n }\n\n override disconnect(): void {\n this.#connected = false;\n this.#stopObserving();\n }\n\n /** Attaches the triggers that still have a job to do. */\n #arm(): void {\n if (!this.urlValue) return;\n if (!this.#loaded) this.element.addEventListener(\"focusin\", this.#onFocus);\n this.#observe();\n }\n\n #observe(): void {\n this.#watcher.start(this.element, { rootMargin: this.rootMarginValue });\n }\n\n #onIntersect(entries: IntersectionObserverEntry[]): void {\n for (const entry of entries) {\n if (entry.isIntersecting) {\n const returning = this.#inside === false;\n this.#inside = true;\n this.#enter(returning);\n } else if (this.#inside) {\n // An observer reports where the frame is before it reports any movement,\n // so only a frame already seen inside can be leaving.\n this.#inside = false;\n }\n }\n }\n\n /** Applies an intersecting entry: the first one loads, a return re-fetches. */\n #enter(returning: boolean): void {\n if (!this.#loaded) {\n this.#load();\n return;\n }\n if (this.onceValue || !returning) return;\n this.#reload();\n }\n\n /**\n * Starts the load by writing the held URL to `src`.\n *\n * @stimeoRuntimeOnly `url` is the address this one load fetches and `once` decides whether it\n * stops the watcher.\n */\n #load(): void {\n if (!this.urlValue) return;\n this.#loaded = true;\n this.element.setAttribute(\"src\", this.urlValue);\n this.element.setAttribute(\"data-lazy-loaded\", \"true\");\n this.dispatch(\"load\", { detail: { url: this.urlValue } });\n // The focus fallback exists to start the first load; it has nothing left to do.\n this.element.removeEventListener(\"focusin\", this.#onFocus);\n if (this.onceValue) this.#watcher.stop();\n }\n\n /**\n * Re-entry while `once` is off: fetch the held URL again.\n *\n * @stimeoRuntimeOnly `url` is the address this one re-entry reloads.\n */\n #reload(): void {\n const src = this.element.getAttribute(\"src\");\n if (this.urlValue && this.urlValue !== src) {\n // The held URL moved on. Writing it to `src` is the fetch, the same start\n // the first load uses, so it works on any host.\n this.element.setAttribute(\"src\", this.urlValue);\n this.dispatch(\"load\", { detail: { url: this.urlValue } });\n return;\n }\n const frame = this.element as HTMLElement & { reload?: () => void };\n // Refetching the URL already on `src` needs the host's own `reload()`. On a\n // non-`<turbo-frame>` host there is none, and firing `load` would announce a\n // fetch that never started.\n if (typeof frame.reload !== \"function\") return;\n frame.reload();\n this.dispatch(\"load\", { detail: { url: src ?? \"\" } });\n }\n\n #stopObserving(): void {\n this.#watcher.stop();\n this.element.removeEventListener(\"focusin\", this.#onFocus);\n }\n}\n"]}
|
|
@@ -28,9 +28,12 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
28
28
|
* (Select-Only Combobox) form. Focus stays on the trigger; the active option is
|
|
29
29
|
* tracked with `aria-activedescendant` rather than by moving DOM focus. For a
|
|
30
30
|
* text-filtered popup use {@link ComboboxController | Combobox}; for multiple
|
|
31
|
-
* selection use Multi-Select.
|
|
31
|
+
* selection use {@link MultiSelectController | Multi-Select}.
|
|
32
32
|
*
|
|
33
|
-
* `change` dispatches `{ value: string, option: HTMLElement }
|
|
33
|
+
* `change` dispatches `{ value: string, option: HTMLElement }` when the user
|
|
34
|
+
* selects. `reconcile` dispatches `{ value: string, option: HTMLElement | null }`
|
|
35
|
+
* — the shape of `change`, with `option: null` and `value: ""` once nothing is
|
|
36
|
+
* selected — when the page moves the selection instead.
|
|
34
37
|
*
|
|
35
38
|
* @remarks
|
|
36
39
|
* Behavior only. Static placement is the consumer's CSS; dynamic placement is
|
|
@@ -50,14 +53,34 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
50
53
|
* Making the field a validatable mirror (`<input type="text" hidden required>`
|
|
51
54
|
* instead of `type="hidden"`) lets `stimeo--form-validation` enforce native
|
|
52
55
|
* constraints on the committed value with no extra JavaScript.
|
|
56
|
+
* - With nothing selected the trigger value shows `placeholder` when it is set,
|
|
57
|
+
* else the text it held before the controller first wrote into it; it keeps no
|
|
58
|
+
* text of an option that is not selected. A value the page rewrote, or added an
|
|
59
|
+
* element to, after the controller wrote into it is the page's instead, and stays
|
|
60
|
+
* exactly as the page left it until the next selection.
|
|
61
|
+
* - A selection the page moves — the selected option removed or dropped from the
|
|
62
|
+
* targets, a morph or a script writing an option's `aria-selected` or the
|
|
63
|
+
* selected option's `data-value`, a selected option that arrives ahead of the
|
|
64
|
+
* selection — updates the label and the field silently and dispatches
|
|
65
|
+
* `stimeo--listbox:reconcile`: once per batch, and only when the selected
|
|
66
|
+
* option or its value differs from the selection last settled (on connect, by
|
|
67
|
+
* the user, or by the previous `reconcile`). Connecting reports nothing. While
|
|
68
|
+
* connected a `MutationObserver` watches the options' `aria-selected` and
|
|
69
|
+
* `data-value`; `disconnect()` releases it.
|
|
53
70
|
* - `Enter`/`Space` select and close; `Escape` and outside click / `Tab` close;
|
|
54
71
|
* closing via select/Escape returns focus to the trigger.
|
|
55
72
|
*/
|
|
56
73
|
declare class ListboxController extends Controller<HTMLElement> {
|
|
57
74
|
#private;
|
|
58
75
|
static targets: string[];
|
|
76
|
+
static values: {
|
|
77
|
+
placeholder: {
|
|
78
|
+
type: StringConstructor;
|
|
79
|
+
default: string;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
59
82
|
static actions: readonly ["close", "onTriggerKeydown", "open", "select", "toggle"];
|
|
60
|
-
static events: readonly ["change"];
|
|
83
|
+
static events: readonly ["change", "reconcile"];
|
|
61
84
|
readonly triggerTarget: HTMLElement;
|
|
62
85
|
readonly valueTarget: HTMLElement;
|
|
63
86
|
readonly listTarget: HTMLElement;
|
|
@@ -67,16 +90,35 @@ declare class ListboxController extends Controller<HTMLElement> {
|
|
|
67
90
|
readonly hasValueTarget: boolean;
|
|
68
91
|
readonly hasListTarget: boolean;
|
|
69
92
|
readonly hasFieldTarget: boolean;
|
|
70
|
-
|
|
93
|
+
placeholderValue: string;
|
|
94
|
+
/**
|
|
95
|
+
* Establishes the ARIA baseline, settles the selection without reporting it,
|
|
96
|
+
* starts closed, and listens for outside clicks.
|
|
97
|
+
*/
|
|
71
98
|
connect(): void;
|
|
72
99
|
/**
|
|
73
|
-
* Establishes an inactive baseline for a late option, re-
|
|
74
|
-
*
|
|
100
|
+
* Establishes an inactive baseline for a late option, then re-applies the
|
|
101
|
+
* selection baseline and re-resolves active identity once the batch is in.
|
|
75
102
|
*/
|
|
76
103
|
optionTargetConnected(option: HTMLElement): void;
|
|
77
|
-
/**
|
|
104
|
+
/**
|
|
105
|
+
* Removes controller-owned active state, then settles the selection and the
|
|
106
|
+
* active option among the surviving targets once the batch is in.
|
|
107
|
+
*/
|
|
78
108
|
optionTargetDisconnected(option: HTMLElement): void;
|
|
79
|
-
/**
|
|
109
|
+
/** Fills a form field inserted or replaced at runtime with the current selection. */
|
|
110
|
+
fieldTargetConnected(): void;
|
|
111
|
+
/** Writes the current selection into a trigger value inserted or replaced at runtime. */
|
|
112
|
+
valueTargetConnected(): void;
|
|
113
|
+
/**
|
|
114
|
+
* Re-renders the empty-selection label when application code (or a Turbo morph)
|
|
115
|
+
* changes `placeholder` at runtime.
|
|
116
|
+
*/
|
|
117
|
+
placeholderValueChanged(): void;
|
|
118
|
+
/**
|
|
119
|
+
* Releases the outside-click listener and the option observer, drops a queued
|
|
120
|
+
* pass, and clears the typeahead timer.
|
|
121
|
+
*/
|
|
80
122
|
disconnect(): void;
|
|
81
123
|
/**
|
|
82
124
|
* Toggles the list on a real mouse click. Keyboard activation of the
|
|
@@ -8,6 +8,16 @@ function isReservedArrowChord(event, allow = []) {
|
|
|
8
8
|
return event.altKey && !allow.includes("alt") || event.ctrlKey && !allow.includes("ctrl") || event.metaKey && !allow.includes("meta") || event.shiftKey && !allow.includes("shift");
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
// src/utils/field_mirror.ts
|
|
12
|
+
function writeField(field, value) {
|
|
13
|
+
if (field.value === value) return false;
|
|
14
|
+
field.value = value;
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
function commitField(target) {
|
|
18
|
+
target.dispatchEvent(new Event("change", { bubbles: true }));
|
|
19
|
+
}
|
|
20
|
+
|
|
11
21
|
// src/utils/microtask_coalescer.ts
|
|
12
22
|
var MicrotaskCoalescer = class {
|
|
13
23
|
#run;
|
|
@@ -165,45 +175,79 @@ function findTypeaheadMatch(items, from, query, label = (item) => typeaheadLabel
|
|
|
165
175
|
}
|
|
166
176
|
|
|
167
177
|
// src/controllers/listbox_controller.ts
|
|
178
|
+
var OBSERVED_ATTRIBUTES = ["aria-selected", "data-value"];
|
|
179
|
+
function setAttributeIfChanged(element, name, value) {
|
|
180
|
+
if (element.getAttribute(name) !== value) element.setAttribute(name, value);
|
|
181
|
+
}
|
|
168
182
|
var ListboxController = class extends Controller {
|
|
169
183
|
static targets = ["trigger", "value", "list", "option", "field"];
|
|
184
|
+
static values = {
|
|
185
|
+
placeholder: { type: String, default: "" }
|
|
186
|
+
};
|
|
170
187
|
static actions = ["close", "onTriggerKeydown", "open", "select", "toggle"];
|
|
171
|
-
static events = ["change"];
|
|
188
|
+
static events = ["change", "reconcile"];
|
|
172
189
|
/** Stable ID of the active option; DOM targets are resolved afresh before use. */
|
|
173
190
|
#activeId = null;
|
|
174
191
|
/** Target ID order captured while an option is active, used only for removal fallback. */
|
|
175
192
|
#activeOrder = [];
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
193
|
+
/**
|
|
194
|
+
* Collapses the target callbacks, Value changes and observed option writes of
|
|
195
|
+
* one DOM mutation into a single pass; refused before `connect()` and after
|
|
196
|
+
* `disconnect()`.
|
|
197
|
+
*/
|
|
198
|
+
#reconcile = new MicrotaskCoalescer(() => this.#reconcileOptions());
|
|
199
|
+
/** Watches the option attributes a page can rewrite in place; set while connected. */
|
|
200
|
+
#observer = null;
|
|
201
|
+
/** The selection last settled: on connect, by the user, or by a reported pass. */
|
|
202
|
+
#settled = { option: null, value: "" };
|
|
179
203
|
/** Accumulated typeahead query and its idle-reset timer. */
|
|
180
204
|
#typeahead = new Typeahead();
|
|
181
|
-
/**
|
|
205
|
+
/**
|
|
206
|
+
* Establishes the ARIA baseline, settles the selection without reporting it,
|
|
207
|
+
* starts closed, and listens for outside clicks.
|
|
208
|
+
*/
|
|
182
209
|
connect() {
|
|
183
210
|
this.#normalizeSelection();
|
|
184
211
|
this.close();
|
|
185
212
|
document.addEventListener("click", this.#onOutsideClick, true);
|
|
186
|
-
this.#
|
|
213
|
+
this.#settled = this.#selection();
|
|
187
214
|
this.#reconcile.activate();
|
|
215
|
+
this.#observeOptions();
|
|
188
216
|
}
|
|
189
217
|
/**
|
|
190
|
-
* Establishes an inactive baseline for a late option, re-
|
|
191
|
-
*
|
|
218
|
+
* Establishes an inactive baseline for a late option, then re-applies the
|
|
219
|
+
* selection baseline and re-resolves active identity once the batch is in.
|
|
192
220
|
*/
|
|
193
221
|
optionTargetConnected(option) {
|
|
194
222
|
option.removeAttribute("data-active");
|
|
195
|
-
|
|
196
|
-
this.#normalizeSelection();
|
|
197
|
-
this.#queueOptionReconciliation();
|
|
223
|
+
this.#reconcile.schedule();
|
|
198
224
|
}
|
|
199
|
-
/**
|
|
225
|
+
/**
|
|
226
|
+
* Removes controller-owned active state, then settles the selection and the
|
|
227
|
+
* active option among the surviving targets once the batch is in.
|
|
228
|
+
*/
|
|
200
229
|
optionTargetDisconnected(option) {
|
|
201
230
|
option.removeAttribute("data-active");
|
|
202
|
-
|
|
231
|
+
this.#reconcile.schedule();
|
|
232
|
+
}
|
|
233
|
+
/** Fills a form field inserted or replaced at runtime with the current selection. */
|
|
234
|
+
fieldTargetConnected() {
|
|
235
|
+
this.#reconcile.schedule();
|
|
236
|
+
}
|
|
237
|
+
/** Writes the current selection into a trigger value inserted or replaced at runtime. */
|
|
238
|
+
valueTargetConnected() {
|
|
239
|
+
this.#reconcile.schedule();
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Re-renders the empty-selection label when application code (or a Turbo morph)
|
|
243
|
+
* changes `placeholder` at runtime.
|
|
244
|
+
*/
|
|
245
|
+
placeholderValueChanged() {
|
|
246
|
+
this.#reconcile.schedule();
|
|
203
247
|
}
|
|
204
248
|
/**
|
|
205
249
|
* Brings the authored DOM to the shape the APG requires, and derives the state
|
|
206
|
-
* that follows from the
|
|
250
|
+
* that follows from the selection.
|
|
207
251
|
*
|
|
208
252
|
* Three things happen, and only these three — which option is chosen is the
|
|
209
253
|
* author's, and is never changed:
|
|
@@ -212,27 +256,59 @@ var ListboxController = class extends Controller {
|
|
|
212
256
|
* selectable" in ARIA, so a forgotten attribute hides a selectable option
|
|
213
257
|
* from assistive technology.
|
|
214
258
|
* 2. At most one stays `true`. The first in DOM order wins, since that is the
|
|
215
|
-
* only deterministic reading of "which one did the author mean"
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
259
|
+
* only deterministic reading of "which one did the author mean"; an option
|
|
260
|
+
* the page inserts ahead of the selection, already selected, takes it over.
|
|
261
|
+
* 3. The trigger label and the hidden field are derived from that selection,
|
|
262
|
+
* an empty one included. Without this the widget announces a choice it does
|
|
263
|
+
* not submit: the popup says "Banana", the trigger still says "Choose…", and
|
|
264
|
+
* the form posts "".
|
|
219
265
|
*
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
* target
|
|
266
|
+
* Nothing is reported here: `connect()` describes the initial state, and a
|
|
267
|
+
* page-driven pass reports a moved selection itself. The scan is the `option`
|
|
268
|
+
* target set: a `role="option"` without the target is outside the contract and
|
|
269
|
+
* is neither counted nor written.
|
|
223
270
|
*/
|
|
224
271
|
#normalizeSelection() {
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
272
|
+
const selected = this.optionTargets.find(
|
|
273
|
+
(option) => option.getAttribute("aria-selected") === "true"
|
|
274
|
+
);
|
|
275
|
+
this.#applySelection(selected);
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* The pass the page's changes run: the selection is normalized and mirrored,
|
|
279
|
+
* the active option re-resolved, then a selection that moved is reported. The
|
|
280
|
+
* report comes last, so options a subscriber rewrites are the next pass's to
|
|
281
|
+
* settle.
|
|
282
|
+
*/
|
|
283
|
+
#reconcileOptions() {
|
|
284
|
+
this.#normalizeSelection();
|
|
285
|
+
this.#reconcileActive();
|
|
286
|
+
this.#reportMove();
|
|
231
287
|
}
|
|
232
|
-
/**
|
|
288
|
+
/**
|
|
289
|
+
* Reports the selection as `reconcile` when its option or value differs from the
|
|
290
|
+
* selection last settled. The settled selection is replaced before dispatching,
|
|
291
|
+
* so a move a subscriber makes is measured against what it was told.
|
|
292
|
+
*/
|
|
293
|
+
#reportMove() {
|
|
294
|
+
const { option, value } = this.#selection();
|
|
295
|
+
if (option === this.#settled.option && value === this.#settled.value) return;
|
|
296
|
+
this.#settled = { option, value };
|
|
297
|
+
this.dispatch("reconcile", { detail: { value, option } });
|
|
298
|
+
}
|
|
299
|
+
/** The selected option target, if any, and the value its field submits. */
|
|
300
|
+
#selection() {
|
|
301
|
+
const option = this.optionTargets.find((candidate) => candidate.getAttribute("aria-selected") === "true") ?? null;
|
|
302
|
+
return { option, value: option ? this.#optionValue(option) : "" };
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Releases the outside-click listener and the option observer, drops a queued
|
|
306
|
+
* pass, and clears the typeahead timer.
|
|
307
|
+
*/
|
|
233
308
|
disconnect() {
|
|
234
|
-
this.#connected = false;
|
|
235
309
|
this.#reconcile.cancel();
|
|
310
|
+
this.#observer?.disconnect();
|
|
311
|
+
this.#observer = null;
|
|
236
312
|
document.removeEventListener("click", this.#onOutsideClick, true);
|
|
237
313
|
this.#typeahead.reset();
|
|
238
314
|
}
|
|
@@ -354,27 +430,113 @@ var ListboxController = class extends Controller {
|
|
|
354
430
|
/** Applies selection: `aria-selected`, trigger label, hidden field, `change`. */
|
|
355
431
|
#selectOption(option) {
|
|
356
432
|
const { value, fieldChanged } = this.#applySelection(option);
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
}
|
|
433
|
+
this.#settled = { option, value };
|
|
434
|
+
if (fieldChanged) commitField(this.fieldTarget);
|
|
360
435
|
this.dispatch("change", { detail: { value, option } });
|
|
361
436
|
}
|
|
362
437
|
/**
|
|
363
|
-
* Writes `option`
|
|
364
|
-
*
|
|
365
|
-
*
|
|
438
|
+
* Writes `option` — or, when it is `undefined`, no selection — into
|
|
439
|
+
* `aria-selected`, the trigger label and the hidden field. Emits nothing: the
|
|
440
|
+
* user's commit and a page-driven pass each report it their own way, and
|
|
441
|
+
* `connect()` only describes the state it finds.
|
|
366
442
|
*/
|
|
367
443
|
#applySelection(option) {
|
|
368
444
|
for (const candidate of this.optionTargets) {
|
|
369
|
-
candidate
|
|
445
|
+
setAttributeIfChanged(candidate, "aria-selected", candidate === option ? "true" : "false");
|
|
370
446
|
}
|
|
371
|
-
|
|
372
|
-
const value = option
|
|
373
|
-
|
|
374
|
-
const fieldChanged = this.hasFieldTarget && this.fieldTarget
|
|
375
|
-
if (fieldChanged) this.fieldTarget.value = value;
|
|
447
|
+
this.#dropOwnRecords();
|
|
448
|
+
const value = option ? this.#optionValue(option) : "";
|
|
449
|
+
this.#renderLabel(option);
|
|
450
|
+
const fieldChanged = this.hasFieldTarget && writeField(this.fieldTarget, value);
|
|
376
451
|
return { value, fieldChanged };
|
|
377
452
|
}
|
|
453
|
+
/**
|
|
454
|
+
* Keeps the trigger value on the selection: the selected option's text, or, with
|
|
455
|
+
* nothing selected, `placeholder` when it is set, else the text the value held
|
|
456
|
+
* before this controller first wrote into it.
|
|
457
|
+
*
|
|
458
|
+
* The value is this controller's only while it holds the text last written into
|
|
459
|
+
* it and nothing else — the `owns-label` marker carries that text — and the text
|
|
460
|
+
* it held before is kept in the `original-label` marker. A value the page
|
|
461
|
+
* rewrote or added an element to after that — the marker is still there but no
|
|
462
|
+
* longer matches — is the page's: with nothing selected it is left exactly as it
|
|
463
|
+
* is, `placeholder` or not, and the next selection remembers its text before
|
|
464
|
+
* replacing it. A value with no marker at all — the author's, or one a morph put
|
|
465
|
+
* back without the markers — is taken over the same way by `placeholder` or by a
|
|
466
|
+
* selection. A value that only ever showed a selection has no text of its own to
|
|
467
|
+
* return to, so it is emptied rather than left naming an option that is not
|
|
468
|
+
* selected.
|
|
469
|
+
*
|
|
470
|
+
* @stimeoRenderRoot
|
|
471
|
+
*/
|
|
472
|
+
#renderLabel(option) {
|
|
473
|
+
if (!this.hasValueTarget) return;
|
|
474
|
+
const label = this.valueTarget;
|
|
475
|
+
const ownsLabel = `data-${this.identifier}-owns-label`;
|
|
476
|
+
const originalLabel = `data-${this.identifier}-original-label`;
|
|
477
|
+
const owned = label.getAttribute(ownsLabel) === label.textContent && label.childElementCount === 0;
|
|
478
|
+
if (option === void 0 && !owned && label.hasAttribute(ownsLabel)) return;
|
|
479
|
+
const text = option ? this.#optionLabel(option) : this.placeholderValue || null;
|
|
480
|
+
if (text === null) {
|
|
481
|
+
if (!owned) return;
|
|
482
|
+
label.textContent = label.getAttribute(originalLabel) ?? "";
|
|
483
|
+
label.removeAttribute(ownsLabel);
|
|
484
|
+
label.removeAttribute(originalLabel);
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
if (!owned) {
|
|
488
|
+
const current = (label.textContent ?? "").trim();
|
|
489
|
+
if (option === void 0 || current !== text) {
|
|
490
|
+
setAttributeIfChanged(label, originalLabel, current);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
if (label.textContent !== text) label.textContent = text;
|
|
494
|
+
setAttributeIfChanged(label, ownsLabel, text);
|
|
495
|
+
}
|
|
496
|
+
/** An option's visible label: its own text, trimmed. */
|
|
497
|
+
#optionLabel(option) {
|
|
498
|
+
return (option.textContent ?? "").trim();
|
|
499
|
+
}
|
|
500
|
+
/** The value an option submits: its `data-value`, else its label. */
|
|
501
|
+
#optionValue(option) {
|
|
502
|
+
return option.dataset.value ?? this.#optionLabel(option);
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Watches the options' `aria-selected` and `data-value`. The listbox's own writes
|
|
506
|
+
* to them are dropped from the queue as they happen, so each record the callback
|
|
507
|
+
* receives is the page's, and only a record on one of the listbox's own options
|
|
508
|
+
* schedules a pass.
|
|
509
|
+
*/
|
|
510
|
+
#observeOptions() {
|
|
511
|
+
const observer = new MutationObserver((records) => {
|
|
512
|
+
if (this.#concernsOptions(records)) this.#reconcile.schedule();
|
|
513
|
+
});
|
|
514
|
+
observer.observe(this.element, {
|
|
515
|
+
subtree: true,
|
|
516
|
+
attributes: true,
|
|
517
|
+
attributeFilter: OBSERVED_ATTRIBUTES
|
|
518
|
+
});
|
|
519
|
+
this.#observer = observer;
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* Whether any record is about one of this listbox's own options. A widget nested
|
|
523
|
+
* inside it writes the same attributes on its own elements, and those are no
|
|
524
|
+
* reason to reconcile the listbox.
|
|
525
|
+
*/
|
|
526
|
+
#concernsOptions(records) {
|
|
527
|
+
const options = new Set(this.optionTargets);
|
|
528
|
+
return records.some((record) => options.has(record.target));
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Drops the records the listbox's own writes just queued, so the observer never
|
|
532
|
+
* takes them for the page's. A page write queued just before goes with them and
|
|
533
|
+
* owes nothing: every such write leaves every option's `aria-selected` at the
|
|
534
|
+
* value the selection gives it, and the selection is then read back from the DOM,
|
|
535
|
+
* so it already holds what the page wrote.
|
|
536
|
+
*/
|
|
537
|
+
#dropOwnRecords() {
|
|
538
|
+
this.#observer?.takeRecords();
|
|
539
|
+
}
|
|
378
540
|
/**
|
|
379
541
|
* Marks the option at `index` active via `data-active` and the trigger's
|
|
380
542
|
* `aria-activedescendant`. Pass `-1` to clear it (the attribute is removed, not
|
|
@@ -444,10 +606,6 @@ var ListboxController = class extends Controller {
|
|
|
444
606
|
}
|
|
445
607
|
return -1;
|
|
446
608
|
}
|
|
447
|
-
/** Coalesces all target callbacks from one MutationObserver batch. */
|
|
448
|
-
#queueOptionReconciliation() {
|
|
449
|
-
this.#reconcile.schedule();
|
|
450
|
-
}
|
|
451
609
|
/**
|
|
452
610
|
* Advances the typeahead query and activates the next matching option.
|
|
453
611
|
*
|