@adia-ai/web-components 0.0.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/README.md +195 -0
- package/a2ui/dockables/action.js +152 -0
- package/a2ui/dockables/base.js +30 -0
- package/a2ui/dockables/controller.js +97 -0
- package/a2ui/dockables/data-source.js +103 -0
- package/a2ui/dockables/index.js +6 -0
- package/a2ui/dockables/lifecycle.js +84 -0
- package/a2ui/dockables/provider.js +59 -0
- package/a2ui/index.js +19 -0
- package/a2ui/manifest-runtime.js +226 -0
- package/a2ui/registry.js +200 -0
- package/a2ui/renderer.js +361 -0
- package/a2ui/root.js +152 -0
- package/a2ui/stream.js +243 -0
- package/a2ui/surface-manifest.js +294 -0
- package/a2ui/surface.js +222 -0
- package/a2ui/wire-factory.js +134 -0
- package/a2ui/wiring-engine.js +209 -0
- package/a2ui/wiring-registry.js +342 -0
- package/components/accordion/accordion.a2ui.json +129 -0
- package/components/accordion/accordion.css +133 -0
- package/components/accordion/accordion.js +125 -0
- package/components/accordion/accordion.yaml +527 -0
- package/components/action-list/action-list.a2ui.json +64 -0
- package/components/action-list/action-list.css +115 -0
- package/components/action-list/action-list.js +149 -0
- package/components/action-list/action-list.yaml +56 -0
- package/components/agent-artifact/agent-artifact.a2ui.json +99 -0
- package/components/agent-artifact/agent-artifact.css +94 -0
- package/components/agent-artifact/agent-artifact.js +169 -0
- package/components/agent-artifact/agent-artifact.yaml +71 -0
- package/components/agent-feedback-bar/agent-feedback-bar.a2ui.json +91 -0
- package/components/agent-feedback-bar/agent-feedback-bar.css +33 -0
- package/components/agent-feedback-bar/agent-feedback-bar.js +152 -0
- package/components/agent-feedback-bar/agent-feedback-bar.yaml +65 -0
- package/components/agent-questions/agent-questions.a2ui.json +89 -0
- package/components/agent-questions/agent-questions.css +146 -0
- package/components/agent-questions/agent-questions.js +189 -0
- package/components/agent-questions/agent-questions.yaml +63 -0
- package/components/agent-reasoning/agent-reasoning.a2ui.json +100 -0
- package/components/agent-reasoning/agent-reasoning.css +273 -0
- package/components/agent-reasoning/agent-reasoning.js +469 -0
- package/components/agent-reasoning/agent-reasoning.yaml +70 -0
- package/components/agent-suggestions/agent-suggestions.a2ui.json +87 -0
- package/components/agent-suggestions/agent-suggestions.css +18 -0
- package/components/agent-suggestions/agent-suggestions.js +87 -0
- package/components/agent-suggestions/agent-suggestions.yaml +59 -0
- package/components/agent-trace/agent-trace.a2ui.json +78 -0
- package/components/agent-trace/agent-trace.css +275 -0
- package/components/agent-trace/agent-trace.js +216 -0
- package/components/agent-trace/agent-trace.yaml +53 -0
- package/components/alert/alert.a2ui.json +211 -0
- package/components/alert/alert.css +88 -0
- package/components/alert/alert.js +96 -0
- package/components/alert/alert.yaml +205 -0
- package/components/avatar/avatar.a2ui.json +215 -0
- package/components/avatar/avatar.css +159 -0
- package/components/avatar/avatar.js +157 -0
- package/components/avatar/avatar.yaml +559 -0
- package/components/badge/badge.a2ui.json +169 -0
- package/components/badge/badge.css +78 -0
- package/components/badge/badge.js +53 -0
- package/components/badge/badge.yaml +612 -0
- package/components/block/block.a2ui.json +135 -0
- package/components/block/block.css +29 -0
- package/components/block/block.js +23 -0
- package/components/block/block.yaml +115 -0
- package/components/breadcrumb/breadcrumb.a2ui.json +86 -0
- package/components/breadcrumb/breadcrumb.css +78 -0
- package/components/breadcrumb/breadcrumb.js +44 -0
- package/components/breadcrumb/breadcrumb.yaml +84 -0
- package/components/button/button.a2ui.json +172 -0
- package/components/button/button.css +168 -0
- package/components/button/button.js +60 -0
- package/components/button/button.yaml +120 -0
- package/components/calendar-picker/calendar-picker.a2ui.json +139 -0
- package/components/calendar-picker/calendar-picker.css +321 -0
- package/components/calendar-picker/calendar-picker.js +324 -0
- package/components/calendar-picker/calendar-picker.yaml +243 -0
- package/components/canvas/canvas.a2ui.json +75 -0
- package/components/canvas/canvas.css +52 -0
- package/components/canvas/canvas.js +179 -0
- package/components/canvas/canvas.yaml +62 -0
- package/components/card/card.a2ui.json +276 -0
- package/components/card/card.css +362 -0
- package/components/card/card.js +58 -0
- package/components/card/card.yaml +527 -0
- package/components/chart/chart.a2ui.json +298 -0
- package/components/chart/chart.css +512 -0
- package/components/chart/chart.js +1075 -0
- package/components/chart/chart.yaml +540 -0
- package/components/chat/chat-input.css +141 -0
- package/components/chat/chat-input.js +242 -0
- package/components/chat/chat.a2ui.json +181 -0
- package/components/chat/chat.css +193 -0
- package/components/chat/chat.js +155 -0
- package/components/chat/chat.yaml +230 -0
- package/components/check/check.a2ui.json +134 -0
- package/components/check/check.css +126 -0
- package/components/check/check.js +58 -0
- package/components/check/check.yaml +109 -0
- package/components/code/code.a2ui.json +153 -0
- package/components/code/code.css +133 -0
- package/components/code/code.js +114 -0
- package/components/code/code.yaml +163 -0
- package/components/col/col.a2ui.json +104 -0
- package/components/col/col.css +36 -0
- package/components/col/col.js +19 -0
- package/components/col/col.yaml +364 -0
- package/components/color-picker/color-picker.a2ui.json +100 -0
- package/components/color-picker/color-picker.css +182 -0
- package/components/color-picker/color-picker.js +537 -0
- package/components/color-picker/color-picker.yaml +105 -0
- package/components/command/command.a2ui.json +221 -0
- package/components/command/command.css +251 -0
- package/components/command/command.js +284 -0
- package/components/command/command.yaml +186 -0
- package/components/description-list/description-list.a2ui.json +89 -0
- package/components/description-list/description-list.css +70 -0
- package/components/description-list/description-list.js +75 -0
- package/components/description-list/description-list.yaml +59 -0
- package/components/divider/divider.a2ui.json +126 -0
- package/components/divider/divider.css +102 -0
- package/components/divider/divider.js +47 -0
- package/components/divider/divider.yaml +366 -0
- package/components/drawer/drawer.a2ui.json +199 -0
- package/components/drawer/drawer.css +342 -0
- package/components/drawer/drawer.js +263 -0
- package/components/drawer/drawer.yaml +366 -0
- package/components/embed/embed.a2ui.json +150 -0
- package/components/embed/embed.css +28 -0
- package/components/embed/embed.js +63 -0
- package/components/embed/embed.yaml +224 -0
- package/components/empty-state/empty-state.a2ui.json +133 -0
- package/components/empty-state/empty-state.css +58 -0
- package/components/empty-state/empty-state.js +87 -0
- package/components/empty-state/empty-state.yaml +314 -0
- package/components/footer/footer.a2ui.json +79 -0
- package/components/footer/footer.yaml +239 -0
- package/components/grid/grid.a2ui.json +171 -0
- package/components/grid/grid.css +37 -0
- package/components/grid/grid.js +21 -0
- package/components/grid/grid.yaml +577 -0
- package/components/header/header.a2ui.json +76 -0
- package/components/header/header.yaml +336 -0
- package/components/heatmap/heatmap.a2ui.json +150 -0
- package/components/heatmap/heatmap.css +146 -0
- package/components/heatmap/heatmap.js +246 -0
- package/components/heatmap/heatmap.yaml +131 -0
- package/components/icon/icon.a2ui.json +79 -0
- package/components/icon/icon.css +20 -0
- package/components/icon/icon.js +26 -0
- package/components/icon/icon.yaml +233 -0
- package/components/image/image.a2ui.json +261 -0
- package/components/image/image.css +76 -0
- package/components/image/image.js +102 -0
- package/components/image/image.yaml +477 -0
- package/components/index.js +85 -0
- package/components/input/input.a2ui.json +284 -0
- package/components/input/input.css +162 -0
- package/components/input/input.js +148 -0
- package/components/input/input.yaml +496 -0
- package/components/inspector/inspector.a2ui.json +67 -0
- package/components/inspector/inspector.css +31 -0
- package/components/inspector/inspector.js +133 -0
- package/components/inspector/inspector.yaml +58 -0
- package/components/kbd/kbd.a2ui.json +96 -0
- package/components/kbd/kbd.css +62 -0
- package/components/kbd/kbd.js +24 -0
- package/components/kbd/kbd.yaml +213 -0
- package/components/list/list.a2ui.json +145 -0
- package/components/list/list.css +103 -0
- package/components/list/list.js +236 -0
- package/components/list/list.yaml +122 -0
- package/components/menu/menu.a2ui.json +146 -0
- package/components/menu/menu.css +146 -0
- package/components/menu/menu.js +296 -0
- package/components/menu/menu.yaml +123 -0
- package/components/modal/modal.a2ui.json +136 -0
- package/components/modal/modal.css +153 -0
- package/components/modal/modal.js +181 -0
- package/components/modal/modal.yaml +114 -0
- package/components/noodles/noodles.a2ui.json +145 -0
- package/components/noodles/noodles.css +118 -0
- package/components/noodles/noodles.js +470 -0
- package/components/noodles/noodles.yaml +123 -0
- package/components/otp-input/otp-input.a2ui.json +104 -0
- package/components/otp-input/otp-input.css +78 -0
- package/components/otp-input/otp-input.js +170 -0
- package/components/otp-input/otp-input.yaml +218 -0
- package/components/pagination/pagination.a2ui.json +122 -0
- package/components/pagination/pagination.css +162 -0
- package/components/pagination/pagination.js +185 -0
- package/components/pagination/pagination.yaml +165 -0
- package/components/pane/pane.a2ui.json +94 -0
- package/components/pane/pane.css +166 -0
- package/components/pane/pane.js +140 -0
- package/components/pane/pane.yaml +197 -0
- package/components/pipeline-status/pipeline-status.a2ui.json +90 -0
- package/components/pipeline-status/pipeline-status.css +162 -0
- package/components/pipeline-status/pipeline-status.js +176 -0
- package/components/pipeline-status/pipeline-status.yaml +99 -0
- package/components/popover/popover.a2ui.json +181 -0
- package/components/popover/popover.css +57 -0
- package/components/popover/popover.js +170 -0
- package/components/popover/popover.yaml +257 -0
- package/components/progress/progress.a2ui.json +199 -0
- package/components/progress/progress.css +88 -0
- package/components/progress/progress.js +64 -0
- package/components/progress/progress.yaml +342 -0
- package/components/progress-row/progress-row.a2ui.json +100 -0
- package/components/progress-row/progress-row.css +57 -0
- package/components/progress-row/progress-row.js +92 -0
- package/components/progress-row/progress-row.yaml +87 -0
- package/components/radio/radio.a2ui.json +232 -0
- package/components/radio/radio.css +102 -0
- package/components/radio/radio.js +73 -0
- package/components/radio/radio.yaml +248 -0
- package/components/range/range.a2ui.json +151 -0
- package/components/range/range.css +148 -0
- package/components/range/range.js +177 -0
- package/components/range/range.yaml +188 -0
- package/components/rating/rating.a2ui.json +105 -0
- package/components/rating/rating.css +92 -0
- package/components/rating/rating.js +138 -0
- package/components/rating/rating.yaml +74 -0
- package/components/richtext/richtext.a2ui.json +82 -0
- package/components/richtext/richtext.css +225 -0
- package/components/richtext/richtext.js +74 -0
- package/components/richtext/richtext.yaml +89 -0
- package/components/row/row.a2ui.json +102 -0
- package/components/row/row.css +51 -0
- package/components/row/row.js +39 -0
- package/components/row/row.yaml +358 -0
- package/components/search/search.a2ui.json +186 -0
- package/components/search/search.css +28 -0
- package/components/search/search.js +124 -0
- package/components/search/search.yaml +154 -0
- package/components/section/section.a2ui.json +78 -0
- package/components/section/section.yaml +338 -0
- package/components/segment/segment.a2ui.json +100 -0
- package/components/segment/segment.css +81 -0
- package/components/segment/segment.js +32 -0
- package/components/segment/segment.yaml +216 -0
- package/components/segmented/segmented.a2ui.json +106 -0
- package/components/segmented/segmented.css +67 -0
- package/components/segmented/segmented.js +149 -0
- package/components/segmented/segmented.yaml +91 -0
- package/components/select/select.a2ui.json +203 -0
- package/components/select/select.css +277 -0
- package/components/select/select.js +388 -0
- package/components/select/select.yaml +375 -0
- package/components/skeleton/skeleton.a2ui.json +120 -0
- package/components/skeleton/skeleton.css +47 -0
- package/components/skeleton/skeleton.js +43 -0
- package/components/skeleton/skeleton.yaml +153 -0
- package/components/slider/slider.a2ui.json +162 -0
- package/components/slider/slider.css +137 -0
- package/components/slider/slider.js +162 -0
- package/components/slider/slider.yaml +299 -0
- package/components/stack/stack.a2ui.json +62 -0
- package/components/stack/stack.css +28 -0
- package/components/stack/stack.js +18 -0
- package/components/stack/stack.yaml +54 -0
- package/components/stat/stat.a2ui.json +246 -0
- package/components/stat/stat.css +101 -0
- package/components/stat/stat.js +91 -0
- package/components/stat/stat.yaml +206 -0
- package/components/stepper/stepper.a2ui.json +77 -0
- package/components/stepper/stepper.css +243 -0
- package/components/stepper/stepper.js +118 -0
- package/components/stepper/stepper.yaml +73 -0
- package/components/stream/stream.a2ui.json +98 -0
- package/components/stream/stream.css +37 -0
- package/components/stream/stream.js +99 -0
- package/components/stream/stream.yaml +87 -0
- package/components/swiper/swiper.a2ui.json +140 -0
- package/components/swiper/swiper.css +267 -0
- package/components/swiper/swiper.js +285 -0
- package/components/swiper/swiper.yaml +268 -0
- package/components/switch/switch.a2ui.json +134 -0
- package/components/switch/switch.css +104 -0
- package/components/switch/switch.js +53 -0
- package/components/switch/switch.yaml +322 -0
- package/components/table/cell-types.js +296 -0
- package/components/table/table.a2ui.json +458 -0
- package/components/table/table.css +531 -0
- package/components/table/table.js +1392 -0
- package/components/table/table.yaml +528 -0
- package/components/tabs/tab.js +34 -0
- package/components/tabs/tabs.a2ui.json +174 -0
- package/components/tabs/tabs.css +162 -0
- package/components/tabs/tabs.js +226 -0
- package/components/tabs/tabs.yaml +255 -0
- package/components/tag/tag.a2ui.json +148 -0
- package/components/tag/tag.css +118 -0
- package/components/tag/tag.js +88 -0
- package/components/tag/tag.yaml +125 -0
- package/components/text/text.a2ui.json +99 -0
- package/components/text/text.css +65 -0
- package/components/text/text.js +35 -0
- package/components/text/text.yaml +360 -0
- package/components/textarea/textarea.a2ui.json +91 -0
- package/components/textarea/textarea.css +93 -0
- package/components/textarea/textarea.js +114 -0
- package/components/textarea/textarea.yaml +79 -0
- package/components/timeline/timeline.a2ui.json +82 -0
- package/components/timeline/timeline.css +389 -0
- package/components/timeline/timeline.js +171 -0
- package/components/timeline/timeline.yaml +185 -0
- package/components/toast/toast.a2ui.json +199 -0
- package/components/toast/toast.css +211 -0
- package/components/toast/toast.js +146 -0
- package/components/toast/toast.yaml +184 -0
- package/components/toggle-group/toggle-group.a2ui.json +126 -0
- package/components/toggle-group/toggle-group.css +102 -0
- package/components/toggle-group/toggle-group.js +147 -0
- package/components/toggle-group/toggle-group.yaml +98 -0
- package/components/toolbar/toolbar.a2ui.json +131 -0
- package/components/toolbar/toolbar.css +132 -0
- package/components/toolbar/toolbar.js +366 -0
- package/components/toolbar/toolbar.yaml +238 -0
- package/components/tooltip/tooltip.a2ui.json +148 -0
- package/components/tooltip/tooltip.css +39 -0
- package/components/tooltip/tooltip.js +96 -0
- package/components/tooltip/tooltip.yaml +201 -0
- package/components/tree/tree.a2ui.json +119 -0
- package/components/tree/tree.css +133 -0
- package/components/tree/tree.js +253 -0
- package/components/tree/tree.yaml +92 -0
- package/components/upload/upload.a2ui.json +185 -0
- package/components/upload/upload.css +115 -0
- package/components/upload/upload.js +189 -0
- package/components/upload/upload.yaml +302 -0
- package/core/anchor.js +187 -0
- package/core/controller.js +182 -0
- package/core/element.js +257 -0
- package/core/form.js +217 -0
- package/core/icons.js +180 -0
- package/core/markdown.js +95 -0
- package/core/polyfills.js +23 -0
- package/core/provider.js +262 -0
- package/core/signals.js +113 -0
- package/core/template.js +226 -0
- package/core/transport.js +77 -0
- package/package.json +38 -0
- package/patterns/adia-chat/adia-chat.a2ui.json +149 -0
- package/patterns/adia-chat/adia-chat.css +10 -0
- package/patterns/adia-chat/adia-chat.js +297 -0
- package/patterns/adia-chat/adia-chat.yaml +118 -0
- package/patterns/adia-chat/css/adia-chat.empty.css +12 -0
- package/patterns/adia-chat/css/adia-chat.layout.css +60 -0
- package/patterns/adia-chat/css/adia-chat.markdown.css +74 -0
- package/patterns/adia-chat/css/adia-chat.messages.css +87 -0
- package/patterns/adia-chat/css/adia-chat.streaming.css +30 -0
- package/patterns/adia-chat/css/adia-chat.tokens.css +95 -0
- package/patterns/adia-chat/index.html +93 -0
- package/patterns/adia-editor/adia-editor.a2ui.json +58 -0
- package/patterns/adia-editor/adia-editor.css +6 -0
- package/patterns/adia-editor/adia-editor.js +56 -0
- package/patterns/adia-editor/adia-editor.yaml +36 -0
- package/patterns/adia-editor/css/adia-editor.layout.css +86 -0
- package/patterns/adia-editor/css/adia-editor.tokens.css +28 -0
- package/patterns/adia-editor/index.html +179 -0
- package/patterns/app-nav/app-nav.a2ui.json +89 -0
- package/patterns/app-nav/app-nav.css +92 -0
- package/patterns/app-nav/app-nav.js +99 -0
- package/patterns/app-nav/app-nav.yaml +54 -0
- package/patterns/app-nav-group/app-nav-group.a2ui.json +82 -0
- package/patterns/app-nav-group/app-nav-group.css +261 -0
- package/patterns/app-nav-group/app-nav-group.js +116 -0
- package/patterns/app-nav-group/app-nav-group.yaml +59 -0
- package/patterns/app-nav-item/app-nav-item.a2ui.json +83 -0
- package/patterns/app-nav-item/app-nav-item.css +156 -0
- package/patterns/app-nav-item/app-nav-item.js +42 -0
- package/patterns/app-nav-item/app-nav-item.yaml +62 -0
- package/patterns/app-shell/app-shell.a2ui.json +114 -0
- package/patterns/app-shell/app-shell.css +14 -0
- package/patterns/app-shell/app-shell.js +251 -0
- package/patterns/app-shell/app-shell.yaml +66 -0
- package/patterns/app-shell/css/app-shell.collapsed.css +86 -0
- package/patterns/app-shell/css/app-shell.helpers.css +42 -0
- package/patterns/app-shell/css/app-shell.main.css +58 -0
- package/patterns/app-shell/css/app-shell.shell.css +44 -0
- package/patterns/app-shell/css/app-shell.sidebar.css +116 -0
- package/patterns/app-shell/css/app-shell.templates.css +214 -0
- package/patterns/app-shell/css/app-shell.tokens.css +116 -0
- package/patterns/app-shell/index.html +112 -0
- package/patterns/gen-ui/gen-ui.a2ui.json +72 -0
- package/patterns/gen-ui/gen-ui.css +83 -0
- package/patterns/gen-ui/gen-ui.js +136 -0
- package/patterns/gen-ui/gen-ui.yaml +43 -0
- package/patterns/index.js +10 -0
- package/patterns/section-nav/section-nav.a2ui.json +91 -0
- package/patterns/section-nav/section-nav.css +59 -0
- package/patterns/section-nav/section-nav.js +42 -0
- package/patterns/section-nav/section-nav.yaml +58 -0
- package/patterns/section-nav-group/section-nav-group.a2ui.json +95 -0
- package/patterns/section-nav-group/section-nav-group.css +74 -0
- package/patterns/section-nav-group/section-nav-group.js +84 -0
- package/patterns/section-nav-group/section-nav-group.yaml +66 -0
- package/patterns/section-nav-item/section-nav-item.a2ui.json +97 -0
- package/patterns/section-nav-item/section-nav-item.css +96 -0
- package/patterns/section-nav-item/section-nav-item.js +66 -0
- package/patterns/section-nav-item/section-nav-item.yaml +70 -0
- package/styles/colors/index.css +6 -0
- package/styles/colors/parameters.css +52 -0
- package/styles/colors/primitives-accent.css +89 -0
- package/styles/colors/primitives-brand.css +89 -0
- package/styles/colors/primitives-danger.css +89 -0
- package/styles/colors/primitives-info.css +89 -0
- package/styles/colors/primitives-neutral.css +91 -0
- package/styles/colors/primitives-shared.css +57 -0
- package/styles/colors/primitives-success.css +89 -0
- package/styles/colors/primitives-warning.css +89 -0
- package/styles/colors/primitives.css +17 -0
- package/styles/colors/scrims.css +182 -0
- package/styles/colors/semantics.css +595 -0
- package/styles/colors/surfaces.css +43 -0
- package/styles/fonts.css +99 -0
- package/styles/layouts/admin.css +7 -0
- package/styles/prose.css +186 -0
- package/styles/styles.css +193 -0
- package/styles/themes.css +155 -0
- package/styles/tokens.css +304 -0
- package/styles/typography.css +853 -0
- package/traits/active-state.js +24 -0
- package/traits/anchor-positioning.js +66 -0
- package/traits/attention-pulse.js +30 -0
- package/traits/confetti-burst.js +65 -0
- package/traits/confetti.js +57 -0
- package/traits/count-up.js +42 -0
- package/traits/define.js +76 -0
- package/traits/dirty-state.js +38 -0
- package/traits/drag-ghost.js +38 -0
- package/traits/draggable.js +73 -0
- package/traits/fade-presence.js +52 -0
- package/traits/focus-trap.js +63 -0
- package/traits/focusable.js +38 -0
- package/traits/glow-focus.js +33 -0
- package/traits/gradient-shift.js +32 -0
- package/traits/haptic-feedback.js +28 -0
- package/traits/hotkey.js +62 -0
- package/traits/hoverable.js +26 -0
- package/traits/index.js +55 -0
- package/traits/inertia-drag.js +133 -0
- package/traits/intersection-observer.js +33 -0
- package/traits/keyboard-nav.js +36 -0
- package/traits/magnetic-hover.js +37 -0
- package/traits/noise-texture.js +30 -0
- package/traits/parallax.js +42 -0
- package/traits/portal.js +27 -0
- package/traits/pressable.js +75 -0
- package/traits/resizable.js +100 -0
- package/traits/resize-observer.js +31 -0
- package/traits/ripple.js +53 -0
- package/traits/roving-tabindex.js +67 -0
- package/traits/scale-press.js +43 -0
- package/traits/scroll-lock.js +27 -0
- package/traits/shimmer-loading.js +44 -0
- package/traits/snap-to-grid.js +28 -0
- package/traits/sound-feedback.js +30 -0
- package/traits/spring-animate.js +56 -0
- package/traits/tilt-hover.js +37 -0
- package/traits/tossable.js +178 -0
- package/traits/typeahead.js +63 -0
- package/traits/typewriter.js +35 -0
- package/traits/validation.js +118 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
@scope (select-ui) {
|
|
2
|
+
:where(:scope) {
|
|
3
|
+
/* ── Layout ── */
|
|
4
|
+
--select-gap: var(--a-space-2);
|
|
5
|
+
--select-trigger-gap: var(--a-space-1);
|
|
6
|
+
--select-height: var(--a-size);
|
|
7
|
+
--select-px: var(--a-ui-px);
|
|
8
|
+
--select-radius: var(--a-radius);
|
|
9
|
+
--select-leading-radius: var(--a-radius-full);
|
|
10
|
+
|
|
11
|
+
/* ── Typography ── */
|
|
12
|
+
--select-font-size: var(--a-ui-size);
|
|
13
|
+
--select-label-size: var(--a-label-size);
|
|
14
|
+
|
|
15
|
+
/* ── Colors ── */
|
|
16
|
+
--select-bg: var(--a-ui-bg);
|
|
17
|
+
--select-bg-selected: var(--a-ui-bg-selected);
|
|
18
|
+
--select-bg-hover: var(--a-ui-bg-hover);
|
|
19
|
+
--select-border: var(--a-ui-border);
|
|
20
|
+
--select-border-hover: var(--a-ui-border-hover);
|
|
21
|
+
--select-border-focus: var(--a-ui-border-active);
|
|
22
|
+
--select-label-fg: var(--a-ui-text-muted);
|
|
23
|
+
--select-placeholder-fg: var(--a-ui-text-placeholder);
|
|
24
|
+
--select-caret-fg: var(--a-ui-text-muted);
|
|
25
|
+
--select-fg: var(--a-ui-text);
|
|
26
|
+
--select-fg-selected: var(--a-ui-text-selected);
|
|
27
|
+
--select-fg-subtle: var(--a-ui-text-subtle);
|
|
28
|
+
--select-fg-muted: var(--a-ui-text-muted);
|
|
29
|
+
--select-fg-disabled: var(--a-ui-text-disabled);
|
|
30
|
+
--select-ghost-bg-hover: var(--a-bg-muted);
|
|
31
|
+
|
|
32
|
+
/* ── Transition ── */
|
|
33
|
+
--select-duration: var(--a-duration-fast);
|
|
34
|
+
--select-easing: var(--a-easing);
|
|
35
|
+
|
|
36
|
+
/* ── Listbox ── */
|
|
37
|
+
--select-option-px: var(--a-ui-px);
|
|
38
|
+
--select-option-py: var(--a-ui-py);
|
|
39
|
+
--select-option-bg-hover: var(--a-bg-hover);
|
|
40
|
+
--select-option-fg-active: var(--a-fg);
|
|
41
|
+
--select-option-fg-disabled: var(--a-ui-text-disabled);
|
|
42
|
+
--select-group-label-size: var(--a-ui-size);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
:scope {
|
|
46
|
+
/* ── Base ── */
|
|
47
|
+
box-sizing: border-box;
|
|
48
|
+
position: relative;
|
|
49
|
+
display: flex;
|
|
50
|
+
flex-direction: column;
|
|
51
|
+
gap: var(--select-gap);
|
|
52
|
+
min-width: 0;
|
|
53
|
+
font-size: var(--select-font-size);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
:scope[data-direction="row"] {
|
|
57
|
+
display: grid;
|
|
58
|
+
grid-template-columns: 1fr 1fr;
|
|
59
|
+
align-items: center;
|
|
60
|
+
}
|
|
61
|
+
:scope[disabled] { pointer-events: none; color: var(--select-fg-disabled); }
|
|
62
|
+
|
|
63
|
+
/* Label */
|
|
64
|
+
:scope::before {
|
|
65
|
+
content: attr(label);
|
|
66
|
+
font-size: var(--select-label-size);
|
|
67
|
+
color: var(--select-label-fg);
|
|
68
|
+
}
|
|
69
|
+
:scope:not([label])::before,
|
|
70
|
+
:scope[label=""]::before { display: none; }
|
|
71
|
+
|
|
72
|
+
/* Trigger */
|
|
73
|
+
[slot="trigger"] {
|
|
74
|
+
display: flex;
|
|
75
|
+
align-items: center;
|
|
76
|
+
justify-content: space-between;
|
|
77
|
+
gap: var(--select-trigger-gap);
|
|
78
|
+
min-width: 0;
|
|
79
|
+
min-height: var(--select-height);
|
|
80
|
+
padding: 0 var(--select-px);
|
|
81
|
+
border: 1px solid var(--select-border);
|
|
82
|
+
border-radius: var(--select-radius);
|
|
83
|
+
background: var(--select-bg);
|
|
84
|
+
line-height: 1;
|
|
85
|
+
cursor: pointer;
|
|
86
|
+
transition:
|
|
87
|
+
border-color var(--select-duration) var(--select-easing),
|
|
88
|
+
background var(--select-duration) var(--select-easing);
|
|
89
|
+
}
|
|
90
|
+
[slot="trigger"]:hover {
|
|
91
|
+
border-color: var(--select-border-hover);
|
|
92
|
+
background: var(--select-bg-hover);
|
|
93
|
+
color: var(--select-fg);
|
|
94
|
+
}
|
|
95
|
+
[slot="trigger"]:hover [slot="caret"] {
|
|
96
|
+
color: var(--select-fg-subtle);
|
|
97
|
+
}
|
|
98
|
+
:scope:focus-visible { outline: none; }
|
|
99
|
+
:scope:focus-visible [slot="trigger"] {
|
|
100
|
+
border-color: var(--select-border-focus);
|
|
101
|
+
color: var(--select-fg);
|
|
102
|
+
}
|
|
103
|
+
:scope:focus-visible::before {
|
|
104
|
+
color: var(--select-fg-subtle);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/* Leading icon / avatar */
|
|
108
|
+
[slot="leading"] {
|
|
109
|
+
flex-shrink: 0;
|
|
110
|
+
--a-icon-size: var(--select-font-size);
|
|
111
|
+
color: var(--select-fg-muted);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
img[slot="leading"] {
|
|
115
|
+
width: var(--select-leading-size, calc(var(--select-height) - var(--select-gap)));
|
|
116
|
+
height: var(--select-leading-size, calc(var(--select-height) - var(--select-gap)));
|
|
117
|
+
border-radius: var(--select-leading-radius);
|
|
118
|
+
object-fit: cover;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
[slot="display"] {
|
|
122
|
+
flex: 1;
|
|
123
|
+
overflow: hidden;
|
|
124
|
+
text-overflow: ellipsis;
|
|
125
|
+
white-space: nowrap;
|
|
126
|
+
color: var(--select-fg);
|
|
127
|
+
}
|
|
128
|
+
input[slot="display"] {
|
|
129
|
+
border: none;
|
|
130
|
+
outline: none;
|
|
131
|
+
background: transparent;
|
|
132
|
+
padding: 0;
|
|
133
|
+
margin: 0;
|
|
134
|
+
font: inherit;
|
|
135
|
+
color: var(--select-fg);
|
|
136
|
+
min-width: 0;
|
|
137
|
+
width: 100%;
|
|
138
|
+
}
|
|
139
|
+
input[slot="display"]::placeholder {
|
|
140
|
+
color: var(--select-placeholder-fg);
|
|
141
|
+
}
|
|
142
|
+
:scope:not([value]) [slot="display"],
|
|
143
|
+
:scope[value=""] [slot="display"] {
|
|
144
|
+
color: var(--select-placeholder-fg);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
[slot="caret"] {
|
|
148
|
+
color: var(--select-caret-fg) !important;
|
|
149
|
+
flex-shrink: 0;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/* Size handled by universal [size] attribute system. */
|
|
153
|
+
|
|
154
|
+
/* Ghost variant */
|
|
155
|
+
:scope[variant="ghost"] {
|
|
156
|
+
--select-bg: transparent;
|
|
157
|
+
--select-border: transparent;
|
|
158
|
+
--select-border-hover: transparent;
|
|
159
|
+
--select-border-focus: transparent;
|
|
160
|
+
}
|
|
161
|
+
:scope[variant="ghost"] [slot="trigger"]:hover {
|
|
162
|
+
background: var(--select-ghost-bg-hover);
|
|
163
|
+
color: var(--select-fg);
|
|
164
|
+
}
|
|
165
|
+
:scope[variant="ghost"] [slot="trigger"]:hover [slot="caret"] {
|
|
166
|
+
color: var(--select-fg-subtle) !important;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/* ── Top-layer: cannot inherit component tokens ── */
|
|
171
|
+
|
|
172
|
+
select-ui [slot="listbox"] {
|
|
173
|
+
margin: 0;
|
|
174
|
+
padding: var(--a-space-1);
|
|
175
|
+
border: 1px solid var(--a-ui-border);
|
|
176
|
+
border-radius: var(--a-radius);
|
|
177
|
+
background: var(--a-bg-subtle);
|
|
178
|
+
box-shadow: var(--a-shadow-lg);
|
|
179
|
+
max-height: 15rem;
|
|
180
|
+
overflow-y: auto;
|
|
181
|
+
font-family: inherit;
|
|
182
|
+
font-size: var(--a-ui-size);
|
|
183
|
+
color: var(--a-fg);
|
|
184
|
+
|
|
185
|
+
/* Positioned by JS (#positionListbox) — fixed to viewport */
|
|
186
|
+
width: max-content;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
select-ui [role="option"] {
|
|
190
|
+
padding: var(--a-space-1) var(--a-ui-px);
|
|
191
|
+
border-radius: var(--a-radius-sm);
|
|
192
|
+
white-space: nowrap;
|
|
193
|
+
color: var(--a-fg-subtle);
|
|
194
|
+
cursor: pointer;
|
|
195
|
+
transition:
|
|
196
|
+
background var(--a-duration-fast) var(--a-easing),
|
|
197
|
+
color var(--a-duration-fast) var(--a-easing);
|
|
198
|
+
}
|
|
199
|
+
select-ui [role="option"]:hover,
|
|
200
|
+
select-ui [role="option"][data-focused] {
|
|
201
|
+
background: var(--a-bg-hover);
|
|
202
|
+
color: var(--a-fg);
|
|
203
|
+
}
|
|
204
|
+
select-ui [role="option"][aria-selected="true"] {
|
|
205
|
+
color: var(--select-fg-selected);
|
|
206
|
+
background: var(--select-bg-selected);
|
|
207
|
+
font-weight: var(--a-ui-weight);
|
|
208
|
+
}
|
|
209
|
+
select-ui [role="option"][aria-disabled="true"] {
|
|
210
|
+
color: var(--a-fg-muted);
|
|
211
|
+
cursor: not-allowed;
|
|
212
|
+
}
|
|
213
|
+
select-ui [role="option"][aria-disabled="true"]:hover {
|
|
214
|
+
background: transparent;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/* Option with icon */
|
|
218
|
+
select-ui [role="option"] icon-ui {
|
|
219
|
+
--a-icon-size: var(--a-ui-size);
|
|
220
|
+
color: var(--a-fg-muted);
|
|
221
|
+
margin-inline-end: var(--a-space-1);
|
|
222
|
+
vertical-align: -0.125em;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/* Separator */
|
|
226
|
+
select-ui [data-separator] {
|
|
227
|
+
height: 1px;
|
|
228
|
+
background: var(--a-border-subtle);
|
|
229
|
+
margin: var(--a-space-1) 0;
|
|
230
|
+
border: none;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/* Menu header (avatar + name + description) */
|
|
234
|
+
select-ui [data-menu-header] {
|
|
235
|
+
display: flex;
|
|
236
|
+
align-items: center;
|
|
237
|
+
gap: var(--a-space-2);
|
|
238
|
+
padding: var(--a-space-2) var(--a-ui-px);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
select-ui [data-menu-header] img {
|
|
242
|
+
width: 2rem;
|
|
243
|
+
height: 2rem;
|
|
244
|
+
border-radius: var(--a-radius-full);
|
|
245
|
+
object-fit: cover;
|
|
246
|
+
flex-shrink: 0;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
select-ui [data-menu-header] strong {
|
|
250
|
+
display: block;
|
|
251
|
+
font-weight: var(--a-weight-medium);
|
|
252
|
+
color: var(--a-fg);
|
|
253
|
+
font-size: var(--a-ui-size);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
select-ui [data-menu-header] span {
|
|
257
|
+
display: block;
|
|
258
|
+
font-size: var(--a-ui-sm);
|
|
259
|
+
color: var(--a-fg-muted);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
select-ui [role="group"] [slot="group-label"] {
|
|
263
|
+
padding: var(--a-space-1) var(--a-ui-px);
|
|
264
|
+
font-size: var(--a-ui-tiny);
|
|
265
|
+
font-weight: var(--a-ui-weight);
|
|
266
|
+
color: var(--a-fg-muted);
|
|
267
|
+
text-transform: uppercase;
|
|
268
|
+
letter-spacing: 0.05em;
|
|
269
|
+
white-space: nowrap;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/* Divider between groups — enabled by <select-ui divider>. */
|
|
273
|
+
select-ui[divider] [role="group"] + [role="group"] {
|
|
274
|
+
border-top: 1px solid var(--a-border-subtle);
|
|
275
|
+
margin-top: var(--a-space-1);
|
|
276
|
+
padding-top: var(--a-space-1);
|
|
277
|
+
}
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
import { AdiaFormElement } from '@core/form.js';
|
|
2
|
+
import { anchorPopover } from '@core/anchor.js';
|
|
3
|
+
|
|
4
|
+
function escapeHTML(s) {
|
|
5
|
+
return s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
class AdiaSelect extends AdiaFormElement {
|
|
9
|
+
static properties = {
|
|
10
|
+
...AdiaFormElement.properties,
|
|
11
|
+
placeholder: { type: String, default: 'Select...', reflect: true },
|
|
12
|
+
open: { type: Boolean, default: false, reflect: true },
|
|
13
|
+
label: { type: String, default: '', reflect: true },
|
|
14
|
+
icon: { type: String, default: '', reflect: true },
|
|
15
|
+
avatar: { type: String, default: '', reflect: true },
|
|
16
|
+
multiple: { type: Boolean, default: false, reflect: true },
|
|
17
|
+
searchable: { type: Boolean, default: false, reflect: true },
|
|
18
|
+
freeText: { type: Boolean, default: false, reflect: true, attribute: 'free-text' },
|
|
19
|
+
divider: { type: Boolean, default: false, reflect: true },
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
static template = () => null;
|
|
23
|
+
|
|
24
|
+
#options = [];
|
|
25
|
+
#listbox = null;
|
|
26
|
+
#anchorCleanup = null;
|
|
27
|
+
#query = '';
|
|
28
|
+
#searchInput = null;
|
|
29
|
+
|
|
30
|
+
#onSearchFocus = () => { if (!this.disabled) this.open = true; };
|
|
31
|
+
#onSearchClick = (e) => { e.stopPropagation(); if (!this.disabled) this.open = true; };
|
|
32
|
+
|
|
33
|
+
#onOptionClick = (e) => {
|
|
34
|
+
const el = e.currentTarget;
|
|
35
|
+
e.stopPropagation();
|
|
36
|
+
const opt = el.__adiaOption;
|
|
37
|
+
if (!opt) return;
|
|
38
|
+
if (opt.disabled) return;
|
|
39
|
+
if (opt.action) {
|
|
40
|
+
this.open = false;
|
|
41
|
+
this.dispatchEvent(new CustomEvent('action', { bubbles: true, detail: { action: opt.action } }));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
this.value = opt.value;
|
|
45
|
+
this.open = false;
|
|
46
|
+
this.#query = '';
|
|
47
|
+
this.syncValue(opt.value);
|
|
48
|
+
this.dispatchEvent(new Event('change', { bubbles: true }));
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
connected() {
|
|
52
|
+
super.connected();
|
|
53
|
+
this.setAttribute('role', 'combobox');
|
|
54
|
+
this.setAttribute('tabindex', '0');
|
|
55
|
+
this.addEventListener('click', this.#onClick);
|
|
56
|
+
this.addEventListener('keydown', this.#onKey);
|
|
57
|
+
// Only parse declarative <option>/<optgroup> children if options
|
|
58
|
+
// weren't already set programmatically (e.g. via .options = [...])
|
|
59
|
+
if (this.#options.length === 0) {
|
|
60
|
+
this.#parseOptions();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
render() {
|
|
65
|
+
// Stamp default trigger if none provided
|
|
66
|
+
if (!this.querySelector('[slot="trigger"]')) {
|
|
67
|
+
// Detach listbox before innerHTML wipe so it isn't destroyed
|
|
68
|
+
const lb = this.#listbox;
|
|
69
|
+
if (lb?.parentNode === this) this.removeChild(lb);
|
|
70
|
+
|
|
71
|
+
const leading = this.avatar
|
|
72
|
+
? `<img slot="leading" src="${this.avatar}" alt="" />`
|
|
73
|
+
: this.icon
|
|
74
|
+
? `<icon-ui slot="leading" name="${this.icon}"></icon-ui>`
|
|
75
|
+
: '';
|
|
76
|
+
const displayMarkup = this.searchable
|
|
77
|
+
? `<input slot="display" type="text" role="combobox" aria-autocomplete="list" autocomplete="off" placeholder="${escapeHTML(this.placeholder || '')}" value="${escapeHTML(this.#displayText() === this.placeholder ? '' : this.#displayText())}" />`
|
|
78
|
+
: `<span slot="display">${escapeHTML(this.#displayText())}</span>`;
|
|
79
|
+
this.innerHTML = `
|
|
80
|
+
<span slot="trigger">
|
|
81
|
+
${leading}
|
|
82
|
+
${displayMarkup}
|
|
83
|
+
<icon-ui name="caret-up-down" slot="caret"></icon-ui>
|
|
84
|
+
</span>
|
|
85
|
+
`;
|
|
86
|
+
|
|
87
|
+
if (this.searchable) {
|
|
88
|
+
// Detach from previous search input if any
|
|
89
|
+
if (this.#searchInput) {
|
|
90
|
+
this.#searchInput.removeEventListener('input', this.#onSearchInput);
|
|
91
|
+
this.#searchInput.removeEventListener('focus', this.#onSearchFocus);
|
|
92
|
+
this.#searchInput.removeEventListener('click', this.#onSearchClick);
|
|
93
|
+
}
|
|
94
|
+
this.#searchInput = this.querySelector('input[slot="display"]');
|
|
95
|
+
if (this.#searchInput) {
|
|
96
|
+
this.#searchInput.addEventListener('input', this.#onSearchInput);
|
|
97
|
+
this.#searchInput.addEventListener('focus', this.#onSearchFocus);
|
|
98
|
+
this.#searchInput.addEventListener('click', this.#onSearchClick);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Re-attach listbox after trigger is stamped
|
|
103
|
+
if (lb) this.appendChild(lb);
|
|
104
|
+
} else {
|
|
105
|
+
const display = this.querySelector('[slot="display"]');
|
|
106
|
+
if (display) {
|
|
107
|
+
if (display.tagName === 'INPUT') {
|
|
108
|
+
// Only update value when not actively editing (no active query)
|
|
109
|
+
if (!this.#query) display.value = this.#displayText() === this.placeholder ? '' : this.#displayText();
|
|
110
|
+
} else {
|
|
111
|
+
display.textContent = this.#displayText();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Ensure listbox exists (regardless of trigger source)
|
|
117
|
+
if (!this.#listbox) {
|
|
118
|
+
this.#listbox = this.querySelector('[slot="listbox"]');
|
|
119
|
+
if (!this.#listbox) {
|
|
120
|
+
this.#listbox = document.createElement('div');
|
|
121
|
+
this.#listbox.setAttribute('slot', 'listbox');
|
|
122
|
+
this.#listbox.setAttribute('role', 'listbox');
|
|
123
|
+
this.#listbox.setAttribute('popover', 'manual');
|
|
124
|
+
this.appendChild(this.#listbox);
|
|
125
|
+
}
|
|
126
|
+
this.#renderOptions();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Sync aria-selected when value changes
|
|
130
|
+
if (this.#listbox) {
|
|
131
|
+
for (const opt of this.#listbox.querySelectorAll('[role="option"]')) {
|
|
132
|
+
const selected = opt.getAttribute('data-value') === this.value;
|
|
133
|
+
if (selected) opt.setAttribute('aria-selected', 'true');
|
|
134
|
+
else opt.removeAttribute('aria-selected');
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
this.setAttribute('aria-expanded', String(this.open));
|
|
139
|
+
|
|
140
|
+
// Toggle popover
|
|
141
|
+
if (this.open) {
|
|
142
|
+
this.#listbox?.showPopover?.();
|
|
143
|
+
const trigger = this.querySelector('[slot="trigger"]') || this;
|
|
144
|
+
this.#listbox.style.minWidth = `${trigger.getBoundingClientRect().width}px`;
|
|
145
|
+
this.#listbox.style.width = 'max-content';
|
|
146
|
+
this.#anchorCleanup = anchorPopover(trigger, this.#listbox, {
|
|
147
|
+
placement: this.getAttribute('placement') || 'bottom-start', gap: 4, matchWidth: false,
|
|
148
|
+
});
|
|
149
|
+
// Dismiss on outside click (next frame so current click doesn't trigger it)
|
|
150
|
+
requestAnimationFrame(() => {
|
|
151
|
+
document.addEventListener('pointerdown', this.#onOutside, { once: true });
|
|
152
|
+
});
|
|
153
|
+
} else {
|
|
154
|
+
this.#anchorCleanup?.();
|
|
155
|
+
this.#anchorCleanup = null;
|
|
156
|
+
this.#listbox?.hidePopover?.();
|
|
157
|
+
document.removeEventListener('pointerdown', this.#onOutside);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** Parse <option> and <optgroup> children into internal model. */
|
|
162
|
+
#parseOptions() {
|
|
163
|
+
this.#options = [];
|
|
164
|
+
for (const child of this.children) {
|
|
165
|
+
if (child.tagName === 'OPTGROUP') {
|
|
166
|
+
const group = { label: child.label || child.getAttribute('label') || '', options: [] };
|
|
167
|
+
for (const opt of child.querySelectorAll('option')) {
|
|
168
|
+
group.options.push({ value: opt.value, label: opt.textContent.trim(), disabled: opt.disabled });
|
|
169
|
+
}
|
|
170
|
+
this.#options.push(group);
|
|
171
|
+
} else if (child.tagName === 'OPTION') {
|
|
172
|
+
this.#options.push({ value: child.value, label: child.textContent.trim(), disabled: child.disabled });
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
for (const child of [...this.querySelectorAll('option, optgroup')]) child.remove();
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
set options(list) {
|
|
179
|
+
this.#options = list;
|
|
180
|
+
// Ensure listbox exists before rendering (may be called before first render)
|
|
181
|
+
if (!this.#listbox) {
|
|
182
|
+
this.#listbox = this.querySelector('[slot="listbox"]');
|
|
183
|
+
if (!this.#listbox) {
|
|
184
|
+
this.#listbox = document.createElement('div');
|
|
185
|
+
this.#listbox.setAttribute('slot', 'listbox');
|
|
186
|
+
this.#listbox.setAttribute('role', 'listbox');
|
|
187
|
+
this.#listbox.setAttribute('popover', 'manual');
|
|
188
|
+
this.appendChild(this.#listbox);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
this.#renderOptions();
|
|
192
|
+
const display = this.querySelector('[slot="display"]');
|
|
193
|
+
if (display) display.textContent = this.#displayText();
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
get options() { return this.#options; }
|
|
197
|
+
|
|
198
|
+
#renderOptions() {
|
|
199
|
+
if (!this.#listbox) return;
|
|
200
|
+
this.#listbox.innerHTML = '';
|
|
201
|
+
|
|
202
|
+
const renderOpt = (opt) => {
|
|
203
|
+
if (opt.separator) {
|
|
204
|
+
const hr = document.createElement('hr');
|
|
205
|
+
hr.setAttribute('data-separator', '');
|
|
206
|
+
return hr;
|
|
207
|
+
}
|
|
208
|
+
const el = document.createElement('div');
|
|
209
|
+
el.setAttribute('role', 'option');
|
|
210
|
+
el.setAttribute('data-value', opt.value || '');
|
|
211
|
+
if (opt.icon) el.innerHTML = `<icon-ui name="${escapeHTML(opt.icon)}"></icon-ui>${escapeHTML(opt.label)}`;
|
|
212
|
+
else el.textContent = opt.label;
|
|
213
|
+
if (opt.value === this.value) el.setAttribute('aria-selected', 'true');
|
|
214
|
+
if (opt.disabled) el.setAttribute('aria-disabled', 'true');
|
|
215
|
+
if (opt.action) el.dataset.action = opt.action;
|
|
216
|
+
el.__adiaOption = opt;
|
|
217
|
+
el.addEventListener('click', this.#onOptionClick);
|
|
218
|
+
return el;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
for (const item of this.#options) {
|
|
222
|
+
if (item.separator) {
|
|
223
|
+
this.#listbox.appendChild(renderOpt(item));
|
|
224
|
+
} else if (item.header) {
|
|
225
|
+
const hdr = document.createElement('div');
|
|
226
|
+
hdr.setAttribute('data-menu-header', '');
|
|
227
|
+
hdr.innerHTML = item.avatar
|
|
228
|
+
? `<img src="${item.avatar}" alt="" /><div><strong>${escapeHTML(item.label)}</strong><span>${escapeHTML(item.description || '')}</span></div>`
|
|
229
|
+
: `<div><strong>${escapeHTML(item.label)}</strong><span>${escapeHTML(item.description || '')}</span></div>`;
|
|
230
|
+
this.#listbox.appendChild(hdr);
|
|
231
|
+
} else if (item.options) {
|
|
232
|
+
const group = document.createElement('div');
|
|
233
|
+
group.setAttribute('role', 'group');
|
|
234
|
+
group.innerHTML = `<div slot="group-label">${escapeHTML(item.label)}</div>`;
|
|
235
|
+
for (const opt of item.options) group.appendChild(renderOpt(opt));
|
|
236
|
+
this.#listbox.appendChild(group);
|
|
237
|
+
} else {
|
|
238
|
+
this.#listbox.appendChild(renderOpt(item));
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (this.#query) this.#applyFilter();
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
#displayText() {
|
|
245
|
+
const flat = this.#options.flatMap(o => o.options || [o]);
|
|
246
|
+
const selected = flat.find(o => o.value === this.value || (o.header && o.label === this.value));
|
|
247
|
+
return selected?.label || this.value || this.placeholder;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
#onClick = (e) => {
|
|
251
|
+
if (this.disabled) return;
|
|
252
|
+
// Ignore clicks inside the popover listbox
|
|
253
|
+
if (this.#listbox && e.composedPath().includes(this.#listbox)) return;
|
|
254
|
+
this.open = !this.open;
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
#onOutside = (e) => {
|
|
258
|
+
// Close if click is outside the select and outside the popover
|
|
259
|
+
if (!this.contains(e.target) && !(this.#listbox && e.composedPath().includes(this.#listbox))) {
|
|
260
|
+
this.open = false;
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
#onKey = (e) => {
|
|
265
|
+
if (e.key === 'Escape') {
|
|
266
|
+
if (this.searchable && this.#query) {
|
|
267
|
+
// First Escape: clear query
|
|
268
|
+
this.#query = '';
|
|
269
|
+
const input = this.querySelector('input[slot="display"]');
|
|
270
|
+
if (input) input.value = '';
|
|
271
|
+
this.#applyFilter();
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
this.open = false;
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
if (e.key === 'Enter') {
|
|
278
|
+
e.preventDefault();
|
|
279
|
+
if (this.open) {
|
|
280
|
+
const focused = this.#listbox?.querySelector('[role="option"][data-focused]:not([data-filtered-out])');
|
|
281
|
+
if (focused) {
|
|
282
|
+
focused.click();
|
|
283
|
+
} else if (this.searchable && this.freeText && this.#query) {
|
|
284
|
+
// Commit free-text
|
|
285
|
+
const q = this.#query;
|
|
286
|
+
this.value = q;
|
|
287
|
+
this.#query = '';
|
|
288
|
+
this.open = false;
|
|
289
|
+
this.syncValue?.(q);
|
|
290
|
+
this.dispatchEvent(new Event('change', { bubbles: true }));
|
|
291
|
+
} else {
|
|
292
|
+
this.open = false;
|
|
293
|
+
}
|
|
294
|
+
} else {
|
|
295
|
+
this.open = true;
|
|
296
|
+
}
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
if (e.key === ' ' && !this.searchable) {
|
|
300
|
+
e.preventDefault();
|
|
301
|
+
if (this.open) {
|
|
302
|
+
const focused = this.#listbox?.querySelector('[role="option"][data-focused]');
|
|
303
|
+
if (focused) focused.click();
|
|
304
|
+
else this.open = false;
|
|
305
|
+
} else {
|
|
306
|
+
this.open = true;
|
|
307
|
+
}
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
if (e.key === 'ArrowDown' && this.open) {
|
|
311
|
+
e.preventDefault();
|
|
312
|
+
this.#focusOption(1);
|
|
313
|
+
}
|
|
314
|
+
if (e.key === 'ArrowUp' && this.open) {
|
|
315
|
+
e.preventDefault();
|
|
316
|
+
this.#focusOption(-1);
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
#onSearchInput = (e) => {
|
|
321
|
+
this.#query = e.target.value || '';
|
|
322
|
+
if (!this.open) this.open = true;
|
|
323
|
+
this.#applyFilter();
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
#applyFilter() {
|
|
327
|
+
if (!this.#listbox) return;
|
|
328
|
+
const q = this.#query.toLowerCase();
|
|
329
|
+
const opts = this.#listbox.querySelectorAll('[role="option"]');
|
|
330
|
+
let anyVisible = false;
|
|
331
|
+
for (const opt of opts) {
|
|
332
|
+
const label = (opt.textContent || '').toLowerCase();
|
|
333
|
+
const match = !q || label.includes(q);
|
|
334
|
+
if (match) {
|
|
335
|
+
opt.removeAttribute('data-filtered-out');
|
|
336
|
+
opt.style.display = '';
|
|
337
|
+
anyVisible = true;
|
|
338
|
+
} else {
|
|
339
|
+
opt.setAttribute('data-filtered-out', '');
|
|
340
|
+
opt.style.display = 'none';
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
// Hide empty groups
|
|
344
|
+
for (const grp of this.#listbox.querySelectorAll('[role="group"]')) {
|
|
345
|
+
const visible = grp.querySelectorAll('[role="option"]:not([data-filtered-out])').length;
|
|
346
|
+
grp.style.display = visible ? '' : 'none';
|
|
347
|
+
}
|
|
348
|
+
// Clear focus if filtered-out
|
|
349
|
+
const focused = this.#listbox.querySelector('[role="option"][data-focused]');
|
|
350
|
+
if (focused && focused.hasAttribute('data-filtered-out')) {
|
|
351
|
+
focused.removeAttribute('data-focused');
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
#focusOption(dir) {
|
|
356
|
+
if (!this.#listbox) return;
|
|
357
|
+
const opts = [...this.#listbox.querySelectorAll('[role="option"]:not([aria-disabled]):not([data-filtered-out])')];
|
|
358
|
+
if (!opts.length) return;
|
|
359
|
+
const current = this.#listbox.querySelector('[role="option"][data-focused]');
|
|
360
|
+
const i = current ? opts.indexOf(current) : -1;
|
|
361
|
+
const next = opts[(i + dir + opts.length) % opts.length];
|
|
362
|
+
if (current) current.removeAttribute('data-focused');
|
|
363
|
+
if (next) {
|
|
364
|
+
next.setAttribute('data-focused', '');
|
|
365
|
+
next.scrollIntoView({ block: 'nearest' });
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
disconnected() {
|
|
370
|
+
super.disconnected();
|
|
371
|
+
this.removeEventListener('click', this.#onClick);
|
|
372
|
+
this.removeEventListener('keydown', this.#onKey);
|
|
373
|
+
document.removeEventListener('pointerdown', this.#onOutside);
|
|
374
|
+
if (this.#searchInput) {
|
|
375
|
+
this.#searchInput.removeEventListener('input', this.#onSearchInput);
|
|
376
|
+
this.#searchInput.removeEventListener('focus', this.#onSearchFocus);
|
|
377
|
+
this.#searchInput.removeEventListener('click', this.#onSearchClick);
|
|
378
|
+
this.#searchInput = null;
|
|
379
|
+
}
|
|
380
|
+
this.#anchorCleanup?.();
|
|
381
|
+
this.#anchorCleanup = null;
|
|
382
|
+
this.#listbox?.hidePopover?.();
|
|
383
|
+
this.#listbox = null;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
customElements.define('select-ui', AdiaSelect);
|
|
387
|
+
|
|
388
|
+
export { AdiaSelect };
|