@lilydesignsystem/alpine-headless 0.0.0-stage → 0.1.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/LICENSE.md +64 -0
- package/README.md +52 -2
- package/components/accordion-checkbox.html +37 -0
- package/components/accordion-link.html +18 -0
- package/components/accordion-list-item.html +19 -0
- package/components/accordion-list.html +17 -0
- package/components/accordion-nav.html +47 -0
- package/components/action-bar-button.html +18 -0
- package/components/action-bar.html +28 -0
- package/components/action-group.html +55 -0
- package/components/action-link.html +18 -0
- package/components/address-input.html +18 -0
- package/components/addressograph-box.html +18 -0
- package/components/affix.html +18 -0
- package/components/age-view.html +16 -0
- package/components/ai-label.html +18 -0
- package/components/alba-community-health-index-input.html +18 -0
- package/components/alba-community-health-index-view.html +14 -0
- package/components/alert-dialog.html +33 -0
- package/components/alert.html +21 -0
- package/components/allergy-record-list-item.html +38 -0
- package/components/allergy-record-list.html +38 -0
- package/components/angle-slider-range-input.html +19 -0
- package/components/announcement-banner.html +18 -0
- package/components/answer.html +18 -0
- package/components/aotearoa-national-health-index-input.html +18 -0
- package/components/aotearoa-national-health-index-view.html +14 -0
- package/components/area-chart.html +47 -0
- package/components/argentina-codigo-unico-de-identificacion-laboral-input.html +18 -0
- package/components/argentina-codigo-unico-de-identificacion-laboral-view.html +14 -0
- package/components/article-layout.html +17 -0
- package/components/as-saudiyah-raqm-al-huwiyah-al-wataniyah-input.html +18 -0
- package/components/as-saudiyah-raqm-al-huwiyah-al-wataniyah-view.html +14 -0
- package/components/aspect-ratio-container.html +14 -0
- package/components/australia-individual-healthcare-identifier-input.html +18 -0
- package/components/australia-individual-healthcare-identifier-view.html +14 -0
- package/components/australia-tax-file-number-input.html +18 -0
- package/components/australia-tax-file-number-view.html +14 -0
- package/components/autosuggest.html +32 -0
- package/components/avatar-group.html +18 -0
- package/components/avatar-image.html +17 -0
- package/components/avatar-text.html +17 -0
- package/components/avatar.html +18 -0
- package/components/back-link.html +18 -0
- package/components/badge.html +19 -0
- package/components/banner-box.html +18 -0
- package/components/banner.html +19 -0
- package/components/bar-chart.html +47 -0
- package/components/barcode-image.html +16 -0
- package/components/beach-ball.html +21 -0
- package/components/belgique-numero-de-registre-national-input.html +18 -0
- package/components/belgique-numero-de-registre-national-view.html +14 -0
- package/components/bharat-aadhaar-input.html +18 -0
- package/components/bharat-aadhaar-view.html +12 -0
- package/components/blockquote.html +21 -0
- package/components/body-map.html +60 -0
- package/components/body-text.html +14 -0
- package/components/brasil-cartao-nacional-de-saude-input.html +18 -0
- package/components/brasil-cartao-nacional-de-saude-view.html +14 -0
- package/components/breadcrumb-link.html +18 -0
- package/components/breadcrumb-list-item.html +19 -0
- package/components/breadcrumb-list.html +17 -0
- package/components/breadcrumb-nav.html +17 -0
- package/components/bulgaria-edinen-grazhdanski-nomer-input.html +18 -0
- package/components/bulgaria-edinen-grazhdanski-nomer-view.html +14 -0
- package/components/button-group.html +18 -0
- package/components/button-input.html +16 -0
- package/components/button.html +17 -0
- package/components/byline.html +19 -0
- package/components/calendar-day-table.html +30 -0
- package/components/calendar-month-table.html +30 -0
- package/components/calendar-range-picker.html +18 -0
- package/components/calendar-table-body.html +19 -0
- package/components/calendar-table-foot.html +19 -0
- package/components/calendar-table-head.html +19 -0
- package/components/calendar-table-row.html +19 -0
- package/components/calendar-table-td.html +22 -0
- package/components/calendar-table-th.html +23 -0
- package/components/calendar-table.html +19 -0
- package/components/calendar-week-table.html +30 -0
- package/components/calendar-year-table.html +30 -0
- package/components/call-to-action.html +17 -0
- package/components/canada-social-insurance-number-input.html +18 -0
- package/components/canada-social-insurance-number-view.html +14 -0
- package/components/candlestick-chart.html +47 -0
- package/components/caption.html +16 -0
- package/components/card.html +18 -0
- package/components/care-card.html +19 -0
- package/components/carousel.html +54 -0
- package/components/cascader.html +89 -0
- package/components/cesko-cestovni-pas-input.html +18 -0
- package/components/cesko-cestovni-pas-view.html +12 -0
- package/components/cesko-rodne-cislo-input.html +18 -0
- package/components/cesko-rodne-cislo-view.html +14 -0
- package/components/character-counter.html +30 -0
- package/components/character.html +18 -0
- package/components/chat-composer.html +44 -0
- package/components/chat-list-item.html +17 -0
- package/components/chat-list.html +17 -0
- package/components/chat-message.html +17 -0
- package/components/chat-nav.html +17 -0
- package/components/check-list-item.html +19 -0
- package/components/check-list.html +18 -0
- package/components/checkbox-group.html +18 -0
- package/components/checkbox-input.html +16 -0
- package/components/chile-rol-unico-nacional-input.html +18 -0
- package/components/chile-rol-unico-nacional-view.html +14 -0
- package/components/choropleth-chart.html +47 -0
- package/components/citation.html +14 -0
- package/components/clamp-text.html +20 -0
- package/components/clipboard-copy-button.html +19 -0
- package/components/coachmark.html +40 -0
- package/components/code-block.html +18 -0
- package/components/code.html +14 -0
- package/components/collapsible.html +19 -0
- package/components/collection-list-item.html +31 -0
- package/components/collection-list.html +17 -0
- package/components/colombia-cedula-de-ciudadania-input.html +18 -0
- package/components/colombia-cedula-de-ciudadania-view.html +14 -0
- package/components/color-input.html +16 -0
- package/components/color-picker-button.html +19 -0
- package/components/color-picker.html +19 -0
- package/components/column-chart.html +47 -0
- package/components/combobox.html +49 -0
- package/components/command.html +51 -0
- package/components/comment.html +18 -0
- package/components/composed-chart.html +47 -0
- package/components/container-with-fixed-width.html +18 -0
- package/components/container-with-fluid-width.html +18 -0
- package/components/container.html +14 -0
- package/components/content-block.html +17 -0
- package/components/contents-link.html +29 -0
- package/components/contents-list-item.html +19 -0
- package/components/contents-list.html +17 -0
- package/components/contents-nav.html +17 -0
- package/components/context-menu-item.html +19 -0
- package/components/context-menu.html +41 -0
- package/components/contextual-help.html +43 -0
- package/components/convert-div.html +18 -0
- package/components/convert-from-div.html +14 -0
- package/components/convert-from-unit-div.html +14 -0
- package/components/convert-from-value-div.html +14 -0
- package/components/convert-into-div.html +14 -0
- package/components/convert-into-unit-div.html +14 -0
- package/components/convert-into-value-div.html +14 -0
- package/components/currency-input.html +18 -0
- package/components/cymru-rhif-y-gwasanaeth-iechyd-gwladol-input.html +18 -0
- package/components/cymru-rhif-y-gwasanaeth-iechyd-gwladol-view.html +14 -0
- package/components/danmark-personnummer-input.html +18 -0
- package/components/danmark-personnummer-view.html +14 -0
- package/components/data-filter-form.html +26 -0
- package/components/data-table-body.html +19 -0
- package/components/data-table-foot.html +19 -0
- package/components/data-table-head.html +19 -0
- package/components/data-table-row.html +19 -0
- package/components/data-table-td.html +22 -0
- package/components/data-table-th.html +23 -0
- package/components/data-table.html +19 -0
- package/components/date-field.html +38 -0
- package/components/date-input.html +16 -0
- package/components/date-range.html +26 -0
- package/components/date-time-local-input.html +16 -0
- package/components/date-time-now-input.html +37 -0
- package/components/date-time-view.html +18 -0
- package/components/decision-support-card.html +52 -0
- package/components/description-list-item.html +14 -0
- package/components/description-list.html +17 -0
- package/components/details.html +15 -0
- package/components/deutschland-krankenversichertennummer-input.html +18 -0
- package/components/deutschland-krankenversichertennummer-view.html +14 -0
- package/components/device-record-list-item.html +29 -0
- package/components/device-record-list.html +29 -0
- package/components/dial-group.html +18 -0
- package/components/dial.html +19 -0
- package/components/dialog.html +32 -0
- package/components/diff.html +18 -0
- package/components/digital-object-identifier-link.html +18 -0
- package/components/do-list-item.html +20 -0
- package/components/do-list.html +18 -0
- package/components/document-list-item.html +14 -0
- package/components/document-list.html +17 -0
- package/components/dont-list-item.html +20 -0
- package/components/dont-list.html +18 -0
- package/components/download-button.html +21 -0
- package/components/draft.html +19 -0
- package/components/drawer.html +36 -0
- package/components/dropdown-menu.html +56 -0
- package/components/early-warning-score-view.html +19 -0
- package/components/ecuador-cedula-de-identidad-input.html +18 -0
- package/components/ecuador-cedula-de-identidad-view.html +14 -0
- package/components/editable-form.html +31 -0
- package/components/editable.html +25 -0
- package/components/eesti-isikukood-input.html +18 -0
- package/components/eesti-isikukood-view.html +14 -0
- package/components/eire-individual-health-identifier-input.html +20 -0
- package/components/eire-individual-health-identifier-view.html +14 -0
- package/components/ellada-dematerialised-securities-system-input.html +18 -0
- package/components/ellada-dematerialised-securities-system-view.html +14 -0
- package/components/email-input.html +16 -0
- package/components/email-link.html +18 -0
- package/components/emoji-character-picker.html +18 -0
- package/components/emoji.html +18 -0
- package/components/empty-state.html +20 -0
- package/components/end-notes.html +17 -0
- package/components/england-national-health-service-number-input.html +18 -0
- package/components/england-national-health-service-number-view.html +14 -0
- package/components/error-message.html +18 -0
- package/components/error-summary.html +20 -0
- package/components/espana-codigo-de-identificacion-fiscal-input.html +18 -0
- package/components/espana-codigo-de-identificacion-fiscal-view.html +14 -0
- package/components/espana-tarjeta-sanitaria-individual-input.html +18 -0
- package/components/espana-tarjeta-sanitaria-individual-view.html +14 -0
- package/components/event.html +17 -0
- package/components/expander.html +33 -0
- package/components/feature-card.html +31 -0
- package/components/feature-photo.html +25 -0
- package/components/field.html +17 -0
- package/components/fieldset.html +18 -0
- package/components/figure.html +18 -0
- package/components/file-dialog.html +32 -0
- package/components/file-input.html +16 -0
- package/components/file-manager.html +18 -0
- package/components/file-tree.html +93 -0
- package/components/file-upload.html +35 -0
- package/components/five-face-rating-picker-button.html +20 -0
- package/components/five-face-rating-picker.html +69 -0
- package/components/five-face-rating-view.html +19 -0
- package/components/five-star-rating-picker-button.html +20 -0
- package/components/five-star-rating-picker.html +69 -0
- package/components/five-star-rating-view.html +19 -0
- package/components/flair.html +18 -0
- package/components/flex-stack.html +18 -0
- package/components/float-button.html +20 -0
- package/components/floating-panel.html +19 -0
- package/components/footer.html +17 -0
- package/components/footnote.html +18 -0
- package/components/form.html +17 -0
- package/components/framer.html +18 -0
- package/components/france-numero-d-identification-au-repertoire-input.html +20 -0
- package/components/france-numero-d-identification-au-repertoire-view.html +14 -0
- package/components/funnel-chart.html +47 -0
- package/components/gantt-table-tbody.html +19 -0
- package/components/gantt-table-td.html +22 -0
- package/components/gantt-table-tfoot.html +19 -0
- package/components/gantt-table-th.html +23 -0
- package/components/gantt-table-thead.html +19 -0
- package/components/gantt-table-tr.html +19 -0
- package/components/gantt-table.html +19 -0
- package/components/gauge-chart.html +50 -0
- package/components/go-to-next-section.html +16 -0
- package/components/go-to-previous-section.html +16 -0
- package/components/go-to-top.html +18 -0
- package/components/government-banner.html +35 -0
- package/components/government-identifier.html +33 -0
- package/components/grail-layout-bottom-footer.html +17 -0
- package/components/grail-layout-center-main.html +17 -0
- package/components/grail-layout-left-aside.html +17 -0
- package/components/grail-layout-right-aside.html +17 -0
- package/components/grail-layout-top-header.html +17 -0
- package/components/grail-layout.html +14 -0
- package/components/graphic-block.html +23 -0
- package/components/grid.html +22 -0
- package/components/hamburger-menu.html +33 -0
- package/components/hanguk-jumin-deungnok-beonho-input.html +18 -0
- package/components/hanguk-jumin-deungnok-beonho-view.html +14 -0
- package/components/header.html +17 -0
- package/components/headline.html +22 -0
- package/components/heatmap-chart-with-year-of-days.html +55 -0
- package/components/heatmap-chart.html +50 -0
- package/components/hero-headline.html +23 -0
- package/components/hero.html +17 -0
- package/components/hidden-input.html +17 -0
- package/components/hint.html +14 -0
- package/components/hong-kong-identity-card-input.html +18 -0
- package/components/hong-kong-identity-card-view.html +14 -0
- package/components/horizontal-scroller.html +19 -0
- package/components/hover-card.html +30 -0
- package/components/hrvatska-osobni-identifikacijski-broj-input.html +18 -0
- package/components/hrvatska-osobni-identifikacijski-broj-view.html +14 -0
- package/components/iban-input.html +17 -0
- package/components/iban-view.html +12 -0
- package/components/icon-button.html +18 -0
- package/components/icon-list-item.html +22 -0
- package/components/icon-list.html +17 -0
- package/components/icon.html +18 -0
- package/components/image-cropper.html +20 -0
- package/components/image-file-input.html +16 -0
- package/components/image-input.html +16 -0
- package/components/image.html +16 -0
- package/components/immunization-record-list-item.html +31 -0
- package/components/immunization-record-list.html +31 -0
- package/components/indonesia-nomor-induk-kependudukan-input.html +18 -0
- package/components/indonesia-nomor-induk-kependudukan-view.html +14 -0
- package/components/info-state.html +37 -0
- package/components/information-callout.html +18 -0
- package/components/input-group.html +28 -0
- package/components/input-with-mask.html +28 -0
- package/components/input.html +16 -0
- package/components/inset-text.html +18 -0
- package/components/iran-kod-e-melli-input.html +18 -0
- package/components/iran-kod-e-melli-view.html +14 -0
- package/components/island-kennitala-input.html +18 -0
- package/components/island-kennitala-view.html +14 -0
- package/components/italia-codice-fiscale-input.html +18 -0
- package/components/italia-codice-fiscale-view.html +14 -0
- package/components/kanban-table-body.html +19 -0
- package/components/kanban-table-foot.html +19 -0
- package/components/kanban-table-head.html +19 -0
- package/components/kanban-table-row.html +19 -0
- package/components/kanban-table-td.html +22 -0
- package/components/kanban-table-th.html +23 -0
- package/components/kanban-table.html +19 -0
- package/components/kbd-shortcut.html +27 -0
- package/components/kbd.html +19 -0
- package/components/kypros-national-passport-number-input.html +18 -0
- package/components/kypros-national-passport-number-view.html +14 -0
- package/components/label.html +17 -0
- package/components/latvija-personas-kods-input.html +18 -0
- package/components/latvija-personas-kods-view.html +14 -0
- package/components/liechtenstein-national-identity-card-number-input.html +18 -0
- package/components/liechtenstein-national-identity-card-number-view.html +14 -0
- package/components/liechtenstein-passport-number-input.html +18 -0
- package/components/liechtenstein-passport-number-view.html +14 -0
- package/components/lietuva-asmens-kodas-input.html +18 -0
- package/components/lietuva-asmens-kodas-view.html +14 -0
- package/components/lietuva-pasas-input.html +18 -0
- package/components/lietuva-pasas-view.html +12 -0
- package/components/line-chart.html +47 -0
- package/components/listbox.html +36 -0
- package/components/loading.html +19 -0
- package/components/luxembourg-matricule-input.html +18 -0
- package/components/luxembourg-matricule-view.html +14 -0
- package/components/magyarorszag-taj-szam-input.html +18 -0
- package/components/magyarorszag-taj-szam-view.html +14 -0
- package/components/malaysia-kad-pengenalan-input.html +18 -0
- package/components/malaysia-kad-pengenalan-view.html +14 -0
- package/components/malta-national-identification-number-input.html +18 -0
- package/components/malta-national-identification-number-view.html +14 -0
- package/components/malta-passport-number-input.html +18 -0
- package/components/malta-passport-number-view.html +14 -0
- package/components/mark.html +12 -0
- package/components/masonry.html +18 -0
- package/components/measurement-instance-input.html +16 -0
- package/components/measurement-instance-view.html +14 -0
- package/components/measurement-system-input.html +16 -0
- package/components/measurement-system-view.html +14 -0
- package/components/measurement-unit-input.html +16 -0
- package/components/measurement-unit-view.html +14 -0
- package/components/medical-banner-box-for-advice.html +19 -0
- package/components/medical-banner-box-for-danger.html +19 -0
- package/components/medical-banner-box.html +19 -0
- package/components/medical-banner.html +30 -0
- package/components/medication-record-list-item.html +29 -0
- package/components/medication-record-list.html +29 -0
- package/components/medication-view.html +19 -0
- package/components/mentions-input.html +54 -0
- package/components/menu-bar-button.html +19 -0
- package/components/menu-bar.html +37 -0
- package/components/menu-group.html +22 -0
- package/components/menu-item.html +19 -0
- package/components/menu.html +37 -0
- package/components/meter.html +20 -0
- package/components/mexico-clave-unica-de-registro-de-poblacion-input.html +18 -0
- package/components/mexico-clave-unica-de-registro-de-poblacion-view.html +14 -0
- package/components/middle-truncation.html +29 -0
- package/components/misr-al-raqm-al-qawmi-input.html +18 -0
- package/components/misr-al-raqm-al-qawmi-view.html +14 -0
- package/components/mockup-browser.html +18 -0
- package/components/mockup-laptop.html +18 -0
- package/components/mockup-phone-landscape.html +18 -0
- package/components/mockup-phone-portrait.html +18 -0
- package/components/mockup-shell.html +18 -0
- package/components/mockup-tablet-landscape.html +18 -0
- package/components/mockup-tablet-portrait.html +18 -0
- package/components/mockup-watch.html +18 -0
- package/components/mockup-window.html +18 -0
- package/components/month-input.html +16 -0
- package/components/multi-select-with-extras.html +25 -0
- package/components/multi-select.html +22 -0
- package/components/navigation-menu.html +37 -0
- package/components/nederland-burgerservice-nummer-input.html +18 -0
- package/components/nederland-burgerservice-nummer-view.html +14 -0
- package/components/nederland-identiteitskaart-nummer-input.html +18 -0
- package/components/nederland-identiteitskaart-nummer-view.html +14 -0
- package/components/nederland-paspoort-nummer-input.html +18 -0
- package/components/nederland-paspoort-nummer-view.html +14 -0
- package/components/net-promoter-score-picker-button.html +20 -0
- package/components/net-promoter-score-picker.html +129 -0
- package/components/net-promoter-score-view.html +14 -0
- package/components/newsletter-signup.html +57 -0
- package/components/nigeria-national-identification-number-input.html +18 -0
- package/components/nigeria-national-identification-number-view.html +14 -0
- package/components/nihon-kojin-bango-input.html +18 -0
- package/components/nihon-kojin-bango-view.html +14 -0
- package/components/norge-fodselsnummer-input.html +18 -0
- package/components/norge-fodselsnummer-view.html +14 -0
- package/components/notification.html +19 -0
- package/components/number-input.html +16 -0
- package/components/numeric-rating-scale-picker.html +104 -0
- package/components/observation-view.html +22 -0
- package/components/one-time-password-input.html +24 -0
- package/components/option.html +19 -0
- package/components/organization.html +17 -0
- package/components/osterreich-sozialversicherungsnummer-input.html +18 -0
- package/components/osterreich-sozialversicherungsnummer-view.html +14 -0
- package/components/overlay-container.html +18 -0
- package/components/padding-reset.html +14 -0
- package/components/pagination-link.html +18 -0
- package/components/pagination-list-item.html +19 -0
- package/components/pagination-list.html +17 -0
- package/components/pagination-nav.html +17 -0
- package/components/pakistan-computerized-national-identity-card-input.html +18 -0
- package/components/pakistan-computerized-national-identity-card-view.html +14 -0
- package/components/panel.html +18 -0
- package/components/password-input-or-text-input-div.html +29 -0
- package/components/password-input.html +16 -0
- package/components/person.html +17 -0
- package/components/phase-banner.html +18 -0
- package/components/photo-pack.html +18 -0
- package/components/pictogram.html +31 -0
- package/components/picture.html +24 -0
- package/components/pie-chart.html +47 -0
- package/components/pilipinas-philhealth-identification-number-input.html +18 -0
- package/components/pilipinas-philhealth-identification-number-view.html +14 -0
- package/components/pin-input-div.html +38 -0
- package/components/place.html +17 -0
- package/components/polska-numer-identyfikacji-podatkowej-input.html +18 -0
- package/components/polska-numer-identyfikacji-podatkowej-view.html +14 -0
- package/components/polska-pesel-input.html +18 -0
- package/components/polska-pesel-view.html +12 -0
- package/components/popconfirm-dialog.html +54 -0
- package/components/popover.html +41 -0
- package/components/popup.html +46 -0
- package/components/portugal-numero-de-identificacao-fiscal-input.html +18 -0
- package/components/portugal-numero-de-identificacao-fiscal-view.html +14 -0
- package/components/portugal-passaporte-input.html +18 -0
- package/components/portugal-passaporte-view.html +14 -0
- package/components/postal-code-input.html +16 -0
- package/components/postal-code-view.html +14 -0
- package/components/prathet-thai-lek-prajam-tua-prachachon-input.html +18 -0
- package/components/prathet-thai-lek-prajam-tua-prachachon-view.html +14 -0
- package/components/problem-record-list-item.html +37 -0
- package/components/problem-record-list.html +37 -0
- package/components/procedure-record-list-item.html +29 -0
- package/components/procedure-record-list.html +29 -0
- package/components/product-card.html +36 -0
- package/components/progress-bar.html +19 -0
- package/components/progress-circle.html +21 -0
- package/components/progress-spinner.html +19 -0
- package/components/progress.html +19 -0
- package/components/qr-code-image.html +18 -0
- package/components/question.html +18 -0
- package/components/radar-chart.html +50 -0
- package/components/radio-group.html +18 -0
- package/components/radio-input.html +16 -0
- package/components/range-input.html +16 -0
- package/components/record-list-item.html +28 -0
- package/components/record-list.html +28 -0
- package/components/red-amber-green-picker-button.html +20 -0
- package/components/red-amber-green-picker.html +49 -0
- package/components/red-amber-green-view.html +17 -0
- package/components/red-orange-yellow-green-blue-picker-button.html +20 -0
- package/components/red-orange-yellow-green-blue-picker.html +69 -0
- package/components/red-orange-yellow-green-blue-view.html +14 -0
- package/components/related-content.html +17 -0
- package/components/reset-input.html +16 -0
- package/components/resizable.html +20 -0
- package/components/review-date.html +16 -0
- package/components/ring-chart.html +47 -0
- package/components/romania-cod-numeric-personal-input.html +18 -0
- package/components/romania-cod-numeric-personal-view.html +14 -0
- package/components/romania-pasaport-input.html +18 -0
- package/components/romania-pasaport-view.html +14 -0
- package/components/rossiya-snils-input.html +18 -0
- package/components/rossiya-snils-view.html +16 -0
- package/components/sankey-chart.html +50 -0
- package/components/scatter-chart.html +47 -0
- package/components/schweiz-ahv-nummer-input.html +18 -0
- package/components/schweiz-ahv-nummer-view.html +14 -0
- package/components/screen-reader-span.html +14 -0
- package/components/scroll-area.html +19 -0
- package/components/scroll-bar.html +20 -0
- package/components/scroller-base.html +19 -0
- package/components/scroller-video.html +38 -0
- package/components/scroller.html +30 -0
- package/components/search-input.html +16 -0
- package/components/section-heading.html +22 -0
- package/components/section-link.html +18 -0
- package/components/section-list-item.html +14 -0
- package/components/section-list.html +17 -0
- package/components/section-nav.html +17 -0
- package/components/segment-group-item.html +21 -0
- package/components/segment-group.html +37 -0
- package/components/select-with-extras.html +14 -0
- package/components/select.html +17 -0
- package/components/separator.html +16 -0
- package/components/share-page.html +18 -0
- package/components/sheet.html +36 -0
- package/components/show-more.html +31 -0
- package/components/sidebar.html +17 -0
- package/components/signature-pad.html +18 -0
- package/components/singapore-national-registration-identity-card-input.html +18 -0
- package/components/singapore-national-registration-identity-card-view.html +16 -0
- package/components/skeleton.html +18 -0
- package/components/skip-link.html +18 -0
- package/components/slide-out-drawer.html +36 -0
- package/components/slider-button.html +19 -0
- package/components/slider.html +21 -0
- package/components/slovenija-emso-input.html +18 -0
- package/components/slovenija-emso-view.html +14 -0
- package/components/slovensko-pas-input.html +18 -0
- package/components/slovensko-pas-view.html +12 -0
- package/components/slovensko-rodne-cislo-input.html +18 -0
- package/components/slovensko-rodne-cislo-view.html +14 -0
- package/components/sonner.html +19 -0
- package/components/south-africa-identity-number-input.html +18 -0
- package/components/south-africa-identity-number-view.html +14 -0
- package/components/sparkline.html +18 -0
- package/components/split-button.html +59 -0
- package/components/split-view.html +36 -0
- package/components/splitter.html +20 -0
- package/components/statistic.html +36 -0
- package/components/status-light.html +22 -0
- package/components/status-tag.html +17 -0
- package/components/step-list-item.html +18 -0
- package/components/step-list.html +18 -0
- package/components/sticky-promo-banner.html +30 -0
- package/components/streaming-text.html +32 -0
- package/components/submit-input.html +16 -0
- package/components/success-panel.html +18 -0
- package/components/summary-box.html +22 -0
- package/components/summary-list-item.html +17 -0
- package/components/summary-list.html +17 -0
- package/components/sunburst-chart.html +47 -0
- package/components/suomi-henkilotunnus-input.html +18 -0
- package/components/suomi-henkilotunnus-view.html +14 -0
- package/components/super-banner.html +19 -0
- package/components/sverige-personnummer-input.html +18 -0
- package/components/sverige-personnummer-view.html +14 -0
- package/components/switch-button.html +19 -0
- package/components/tab-bar-button.html +27 -0
- package/components/tab-bar.html +59 -0
- package/components/tab-panel.html +34 -0
- package/components/table-body.html +16 -0
- package/components/table-foot.html +16 -0
- package/components/table-head.html +16 -0
- package/components/table-row.html +18 -0
- package/components/table-td.html +20 -0
- package/components/table-th.html +24 -0
- package/components/table.html +17 -0
- package/components/tag-group.html +18 -0
- package/components/tag-input-div.html +41 -0
- package/components/tag.html +15 -0
- package/components/taiwan-guomin-shenfenzheng-tongyi-bianhao-input.html +18 -0
- package/components/taiwan-guomin-shenfenzheng-tongyi-bianhao-view.html +14 -0
- package/components/task-bar-button.html +17 -0
- package/components/task-bar.html +19 -0
- package/components/task-list-item.html +20 -0
- package/components/task-list.html +18 -0
- package/components/tel-input.html +16 -0
- package/components/tel-link.html +18 -0
- package/components/text-area-input-with-character-counter.html +32 -0
- package/components/text-area-input.html +17 -0
- package/components/text-input-with-search.html +30 -0
- package/components/text-input.html +16 -0
- package/components/theme-provider.html +18 -0
- package/components/theme-select-option.html +19 -0
- package/components/theme-select.html +17 -0
- package/components/theme-view.html +14 -0
- package/components/thinking.html +21 -0
- package/components/tile-map.html +21 -0
- package/components/tile.html +18 -0
- package/components/time-input.html +16 -0
- package/components/time-picker-input.html +19 -0
- package/components/timeline-list-item.html +19 -0
- package/components/timeline-list.html +17 -0
- package/components/timeout-dialog.html +18 -0
- package/components/timer-button.html +20 -0
- package/components/timer.html +19 -0
- package/components/toast.html +19 -0
- package/components/toggle-button.html +19 -0
- package/components/toggle-group.html +30 -0
- package/components/tool-bar-button.html +17 -0
- package/components/tool-bar.html +19 -0
- package/components/tool-call-error.html +17 -0
- package/components/tool-call-input.html +18 -0
- package/components/tool-call-name.html +12 -0
- package/components/tool-call-output.html +18 -0
- package/components/tool-call-status.html +16 -0
- package/components/tool-call.html +58 -0
- package/components/tooltip.html +30 -0
- package/components/tour-list-item.html +20 -0
- package/components/tour-list.html +19 -0
- package/components/tour.html +59 -0
- package/components/transfer-list.html +37 -0
- package/components/tree-link.html +18 -0
- package/components/tree-list-item.html +21 -0
- package/components/tree-list.html +71 -0
- package/components/tree-menu.html +71 -0
- package/components/tree-nav.html +76 -0
- package/components/tree-select.html +89 -0
- package/components/tuaisceart-eireann-health-and-care-number-input.html +20 -0
- package/components/tuaisceart-eireann-health-and-care-number-view.html +14 -0
- package/components/turkiye-tc-kimlik-numarasi-input.html +18 -0
- package/components/turkiye-tc-kimlik-numarasi-view.html +14 -0
- package/components/ukrayina-reyestratsiyniy-nomer-oblikovoyi-kartky-platnyka-podatkiv-input.html +18 -0
- package/components/ukrayina-reyestratsiyniy-nomer-oblikovoyi-kartky-platnyka-podatkiv-view.html +16 -0
- package/components/united-kingdom-national-health-service-number-input.html +18 -0
- package/components/united-kingdom-national-health-service-number-view.html +14 -0
- package/components/united-kingdom-national-insurance-number-input.html +18 -0
- package/components/united-kingdom-national-insurance-number-view.html +14 -0
- package/components/united-states-social-security-number-input.html +18 -0
- package/components/united-states-social-security-number-view.html +14 -0
- package/components/url-input.html +16 -0
- package/components/uruguay-cedula-de-identidad-input.html +18 -0
- package/components/uruguay-cedula-de-identidad-view.html +14 -0
- package/components/validation-list-item.html +18 -0
- package/components/validation-list.html +18 -0
- package/components/video-player.html +25 -0
- package/components/viet-nam-can-cuoc-cong-dan-input.html +18 -0
- package/components/viet-nam-can-cuoc-cong-dan-view.html +14 -0
- package/components/visible.html +17 -0
- package/components/warning-callout.html +18 -0
- package/components/warning-text.html +22 -0
- package/components/watermark.html +26 -0
- package/components/week-input.html +16 -0
- package/components/wheel-picker.html +46 -0
- package/components/yisrael-teudat-zehut-input.html +18 -0
- package/components/yisrael-teudat-zehut-view.html +14 -0
- package/components/zhongguo-jumin-shenfenzheng-haoma-input.html +18 -0
- package/components/zhongguo-jumin-shenfenzheng-haoma-view.html +14 -0
- package/index.js +27 -0
- package/index.md +53 -0
- package/lily-alpine.js +2979 -0
- package/middle-truncation.js +74 -0
- package/overflow-navigation.js +141 -0
- package/package.json +57 -4
- package/page-check.js +102 -0
- package/wheel-picker.js +219 -0
package/lily-alpine.js
ADDED
|
@@ -0,0 +1,2979 @@
|
|
|
1
|
+
// Lily Design System — Alpine.js headless plugin.
|
|
2
|
+
//
|
|
3
|
+
// Registers the Alpine.data() behaviours the component snippets in
|
|
4
|
+
// components/*.html use. The snippets own the markup, ARIA and class
|
|
5
|
+
// hooks; this plugin owns state and keyboard handling only. It ships no
|
|
6
|
+
// CSS, no text and no icons. Every behaviour exposes its bindings as
|
|
7
|
+
// x-bind objects so a consumer can reuse them on their own elements.
|
|
8
|
+
//
|
|
9
|
+
// import Alpine from "alpinejs";
|
|
10
|
+
// import lily from "@lilydesignsystem/alpine-headless/plugin";
|
|
11
|
+
// Alpine.plugin(lily);
|
|
12
|
+
// Alpine.start();
|
|
13
|
+
|
|
14
|
+
import { menuKeydown } from "./menu-keys.js";
|
|
15
|
+
import { attachCropper, attachGrid, attachSplitView, attachToolbar } from "./widget-keys.js";
|
|
16
|
+
import { truncateMiddle } from "./middle-truncation.js";
|
|
17
|
+
import { setupOverflowNavigation } from "./overflow-navigation.js";
|
|
18
|
+
import {
|
|
19
|
+
isWheelRtl,
|
|
20
|
+
isWheelTypeaheadKey,
|
|
21
|
+
nextWheelIndex,
|
|
22
|
+
nextWheelPrefix,
|
|
23
|
+
watchWheelScroll,
|
|
24
|
+
wheelMoveKey,
|
|
25
|
+
wheelTypeaheadIndex,
|
|
26
|
+
} from "./wheel-picker.js";
|
|
27
|
+
|
|
28
|
+
/** What focus may land on when an overlay opens. */
|
|
29
|
+
const FOCUSABLE =
|
|
30
|
+
'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
31
|
+
|
|
32
|
+
/** Roving-focus keys shared by every composite widget (APG). */
|
|
33
|
+
function rovingIndex(key, index, count) {
|
|
34
|
+
if (key === "ArrowRight" || key === "ArrowDown") return (index + 1) % count;
|
|
35
|
+
if (key === "ArrowLeft" || key === "ArrowUp") return (index - 1 + count) % count;
|
|
36
|
+
if (key === "Home") return 0;
|
|
37
|
+
if (key === "End") return count - 1;
|
|
38
|
+
return -1;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Focus-move for menu-like widgets: returns the item to focus, or null. */
|
|
42
|
+
function menuTarget(key, items, from, horizontal) {
|
|
43
|
+
const next = horizontal ? "ArrowRight" : "ArrowDown";
|
|
44
|
+
const prev = horizontal ? "ArrowLeft" : "ArrowUp";
|
|
45
|
+
if (!items.length) return null;
|
|
46
|
+
if (key === next) return items[(from + 1) % items.length];
|
|
47
|
+
if (key === prev) return items[(from - 1 + items.length) % items.length];
|
|
48
|
+
if (key === "Home") return items[0];
|
|
49
|
+
if (key === "End") return items[items.length - 1];
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** How many descendants carry an x-bind starting with `prefix` (counts parts before they initialise). */
|
|
54
|
+
function boundCount(root, prefix) {
|
|
55
|
+
return Array.from(root.querySelectorAll("[x-bind]")).filter((e) =>
|
|
56
|
+
e.getAttribute("x-bind").startsWith(prefix),
|
|
57
|
+
).length;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const MENU_ITEMS = '[role="menuitem"]:not([disabled])';
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Shared APG tree-view behaviour for lilyTree, lilyTreeSelect and lilyCascader.
|
|
64
|
+
* Items are role="treeitem" carrying data-item; a branch has aria-expanded and
|
|
65
|
+
* owns a role="group". Visibility is read from the ancestors' aria-expanded.
|
|
66
|
+
*/
|
|
67
|
+
function treeCore({ wrap = false, exclusive = false, expanded = [] } = {}) {
|
|
68
|
+
let buffer = "";
|
|
69
|
+
let timer;
|
|
70
|
+
const parentOf = (item) => item.parentElement?.closest('[role="treeitem"]') ?? null;
|
|
71
|
+
const ownText = (item) =>
|
|
72
|
+
Array.from(item.childNodes)
|
|
73
|
+
.filter(
|
|
74
|
+
(n) =>
|
|
75
|
+
n.nodeType !== 8 && !(n.nodeType === 1 && n.getAttribute("role") === "group"),
|
|
76
|
+
)
|
|
77
|
+
.map((n) => n.textContent || "")
|
|
78
|
+
.join("")
|
|
79
|
+
.trim()
|
|
80
|
+
.toLowerCase();
|
|
81
|
+
return {
|
|
82
|
+
expanded: [...expanded],
|
|
83
|
+
selected: [],
|
|
84
|
+
current: "",
|
|
85
|
+
allItems() {
|
|
86
|
+
return Array.from(this.$root.querySelectorAll('[role="treeitem"]'));
|
|
87
|
+
},
|
|
88
|
+
visibleItems() {
|
|
89
|
+
return this.allItems().filter((item) => {
|
|
90
|
+
for (let p = parentOf(item); p; p = parentOf(p)) {
|
|
91
|
+
if (p.getAttribute("aria-expanded") === "false") return false;
|
|
92
|
+
}
|
|
93
|
+
return true;
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
itemFor(id) {
|
|
97
|
+
return this.allItems().find((i) => i.dataset.item === id);
|
|
98
|
+
},
|
|
99
|
+
pathOf(id) {
|
|
100
|
+
const path = [];
|
|
101
|
+
for (let item = this.itemFor(id); item; item = parentOf(item))
|
|
102
|
+
path.unshift(item.dataset.item);
|
|
103
|
+
return path;
|
|
104
|
+
},
|
|
105
|
+
focusItem(item) {
|
|
106
|
+
if (!item) return;
|
|
107
|
+
this.current = item.dataset.item;
|
|
108
|
+
item.focus();
|
|
109
|
+
},
|
|
110
|
+
toggle(id) {
|
|
111
|
+
if (this.expanded.includes(id)) {
|
|
112
|
+
this.expanded = this.expanded.filter((e) => e !== id);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
let next = [...this.expanded, id];
|
|
116
|
+
if (exclusive) {
|
|
117
|
+
const item = this.itemFor(id);
|
|
118
|
+
const siblings = this.allItems().filter(
|
|
119
|
+
(i) => i !== item && parentOf(i) === parentOf(item),
|
|
120
|
+
);
|
|
121
|
+
next = next.filter((e) => !siblings.some((s) => s.dataset.item === e));
|
|
122
|
+
}
|
|
123
|
+
this.expanded = next;
|
|
124
|
+
},
|
|
125
|
+
choose(id) {
|
|
126
|
+
this.selected = [id];
|
|
127
|
+
this.$dispatch("lily:select", { selected: id, path: this.pathOf(id) });
|
|
128
|
+
},
|
|
129
|
+
activate(id, branch) {
|
|
130
|
+
if (branch) this.toggle(id);
|
|
131
|
+
else this.choose(id);
|
|
132
|
+
},
|
|
133
|
+
treeKey(event) {
|
|
134
|
+
const target = event.target;
|
|
135
|
+
const item = target.closest('[role="treeitem"]');
|
|
136
|
+
if (!item || !this.$root.contains(item)) return;
|
|
137
|
+
if (event.ctrlKey || event.metaKey || event.altKey) return;
|
|
138
|
+
if (event.key.length !== 1) buffer = "";
|
|
139
|
+
const visible = this.visibleItems();
|
|
140
|
+
const index = visible.indexOf(item);
|
|
141
|
+
const expandedState = item.getAttribute("aria-expanded");
|
|
142
|
+
const go = (to) => {
|
|
143
|
+
event.preventDefault();
|
|
144
|
+
this.focusItem(to);
|
|
145
|
+
};
|
|
146
|
+
switch (event.key) {
|
|
147
|
+
case "ArrowDown":
|
|
148
|
+
return go(
|
|
149
|
+
visible[
|
|
150
|
+
wrap
|
|
151
|
+
? (index + 1) % visible.length
|
|
152
|
+
: Math.min(index + 1, visible.length - 1)
|
|
153
|
+
],
|
|
154
|
+
);
|
|
155
|
+
case "ArrowUp":
|
|
156
|
+
return go(
|
|
157
|
+
visible[
|
|
158
|
+
wrap
|
|
159
|
+
? (index - 1 + visible.length) % visible.length
|
|
160
|
+
: Math.max(index - 1, 0)
|
|
161
|
+
],
|
|
162
|
+
);
|
|
163
|
+
case "Home":
|
|
164
|
+
return go(visible[0]);
|
|
165
|
+
case "End":
|
|
166
|
+
return go(visible[visible.length - 1]);
|
|
167
|
+
case "ArrowRight":
|
|
168
|
+
if (target !== item) return;
|
|
169
|
+
event.preventDefault();
|
|
170
|
+
if (expandedState === "false") this.toggle(item.dataset.item);
|
|
171
|
+
else if (expandedState === "true")
|
|
172
|
+
this.focusItem(item.querySelector('[role="group"] [role="treeitem"]'));
|
|
173
|
+
return;
|
|
174
|
+
case "ArrowLeft":
|
|
175
|
+
if (target !== item) return;
|
|
176
|
+
event.preventDefault();
|
|
177
|
+
if (expandedState === "true") this.toggle(item.dataset.item);
|
|
178
|
+
else this.focusItem(parentOf(item));
|
|
179
|
+
return;
|
|
180
|
+
case "Enter":
|
|
181
|
+
case " ":
|
|
182
|
+
if (target !== item) return;
|
|
183
|
+
event.preventDefault();
|
|
184
|
+
item.click(); // Its @click activates, so a key and a pointer tell the page the same thing.
|
|
185
|
+
return;
|
|
186
|
+
case "*":
|
|
187
|
+
event.preventDefault();
|
|
188
|
+
this.allItems()
|
|
189
|
+
.filter(
|
|
190
|
+
(i) =>
|
|
191
|
+
parentOf(i) === parentOf(item) &&
|
|
192
|
+
i.getAttribute("aria-expanded") === "false",
|
|
193
|
+
)
|
|
194
|
+
.forEach((i) => this.toggle(i.dataset.item));
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (event.key.length !== 1) return;
|
|
198
|
+
event.preventDefault();
|
|
199
|
+
buffer += event.key.toLowerCase();
|
|
200
|
+
clearTimeout(timer);
|
|
201
|
+
timer = setTimeout(() => {
|
|
202
|
+
buffer = "";
|
|
203
|
+
}, 500);
|
|
204
|
+
const cycle = buffer.length === 1 || [...buffer].every((c) => c === buffer[0]);
|
|
205
|
+
const needle = cycle ? buffer[0] : buffer;
|
|
206
|
+
const cut = index + (cycle ? 1 : 0);
|
|
207
|
+
const ordered = visible.slice(cut).concat(visible.slice(0, cut));
|
|
208
|
+
this.focusItem(ordered.find((i) => ownText(i).startsWith(needle)));
|
|
209
|
+
},
|
|
210
|
+
tree: {
|
|
211
|
+
"@keydown"(event) {
|
|
212
|
+
this.treeKey(event);
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
group(id) {
|
|
216
|
+
return {
|
|
217
|
+
role: "group",
|
|
218
|
+
":hidden"() {
|
|
219
|
+
return !this.expanded.includes(id);
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
},
|
|
223
|
+
item(id, branch = false) {
|
|
224
|
+
return {
|
|
225
|
+
role: "treeitem",
|
|
226
|
+
"data-item": id,
|
|
227
|
+
":tabindex"() {
|
|
228
|
+
return (this.current ||
|
|
229
|
+
this.selected[0] ||
|
|
230
|
+
this.allItems()[0]?.dataset.item) === id
|
|
231
|
+
? "0"
|
|
232
|
+
: "-1";
|
|
233
|
+
},
|
|
234
|
+
":aria-selected"() {
|
|
235
|
+
return String(this.selected.includes(id));
|
|
236
|
+
},
|
|
237
|
+
...(branch
|
|
238
|
+
? {
|
|
239
|
+
":aria-expanded"() {
|
|
240
|
+
return String(this.expanded.includes(id));
|
|
241
|
+
},
|
|
242
|
+
}
|
|
243
|
+
: {}),
|
|
244
|
+
"@focus"() {
|
|
245
|
+
this.current = id;
|
|
246
|
+
},
|
|
247
|
+
"@click"(event) {
|
|
248
|
+
if (event.target.closest('[role="treeitem"]') === this.$el)
|
|
249
|
+
this.activate(id, branch);
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
},
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export default function lily(Alpine) {
|
|
257
|
+
// An image cropper, on its root: the crop rectangle's keys.
|
|
258
|
+
Alpine.directive("lily-cropper", (el, _, { cleanup }) => {
|
|
259
|
+
cleanup(attachCropper(el));
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
// A split view, on its root: the divider's keys, and data-split-percent kept in step.
|
|
263
|
+
Alpine.directive("lily-split-view", (el, _, { cleanup }) => {
|
|
264
|
+
cleanup(attachSplitView(el));
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
// A toolbar, on any element: x-lily-toolbar, with an optional selector for the button Escape clicks.
|
|
268
|
+
// KanbanTable, DataTable, GanttTable and the calendar tables: <table role="grid">. The grid keys, over the cells the
|
|
269
|
+
// consumer renders.
|
|
270
|
+
Alpine.directive("lily-grid", (el, _, { cleanup }) => {
|
|
271
|
+
cleanup(attachGrid(el));
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
Alpine.directive("lily-toolbar", (el, { expression }, { cleanup }) => {
|
|
275
|
+
cleanup(attachToolbar(el, expression ? { dismiss: expression } : {}));
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
// ToggleButton: <button aria-pressed>
|
|
279
|
+
Alpine.data("lilyToggleButton", (pressed = false) => ({
|
|
280
|
+
pressed,
|
|
281
|
+
button: {
|
|
282
|
+
type: "button",
|
|
283
|
+
":aria-pressed"() {
|
|
284
|
+
return String(this.pressed);
|
|
285
|
+
},
|
|
286
|
+
"@click"() {
|
|
287
|
+
this.pressed = !this.pressed;
|
|
288
|
+
},
|
|
289
|
+
},
|
|
290
|
+
}));
|
|
291
|
+
|
|
292
|
+
// SwitchButton: <button role="switch" aria-checked>
|
|
293
|
+
Alpine.data("lilySwitchButton", (checked = false) => ({
|
|
294
|
+
checked,
|
|
295
|
+
button: {
|
|
296
|
+
type: "button",
|
|
297
|
+
role: "switch",
|
|
298
|
+
":aria-checked"() {
|
|
299
|
+
return String(this.checked);
|
|
300
|
+
},
|
|
301
|
+
"@click"() {
|
|
302
|
+
this.checked = !this.checked;
|
|
303
|
+
},
|
|
304
|
+
},
|
|
305
|
+
}));
|
|
306
|
+
|
|
307
|
+
// Collapsible: a trigger button controlling one content region.
|
|
308
|
+
Alpine.data("lilyCollapsible", (expanded = false) => ({
|
|
309
|
+
expanded,
|
|
310
|
+
root: {
|
|
311
|
+
":data-expanded"() {
|
|
312
|
+
return String(this.expanded);
|
|
313
|
+
},
|
|
314
|
+
},
|
|
315
|
+
trigger: {
|
|
316
|
+
type: "button",
|
|
317
|
+
":aria-expanded"() {
|
|
318
|
+
return String(this.expanded);
|
|
319
|
+
},
|
|
320
|
+
"@click"() {
|
|
321
|
+
this.expanded = !this.expanded;
|
|
322
|
+
},
|
|
323
|
+
},
|
|
324
|
+
content: {
|
|
325
|
+
":hidden"() {
|
|
326
|
+
return !this.expanded;
|
|
327
|
+
},
|
|
328
|
+
},
|
|
329
|
+
}));
|
|
330
|
+
|
|
331
|
+
// ShowMore: like Collapsible; the labels are the consumer's.
|
|
332
|
+
Alpine.data("lilyShowMore", (expanded = false) => ({
|
|
333
|
+
expanded,
|
|
334
|
+
root: {
|
|
335
|
+
":data-expanded"() {
|
|
336
|
+
return String(this.expanded);
|
|
337
|
+
},
|
|
338
|
+
},
|
|
339
|
+
button: {
|
|
340
|
+
type: "button",
|
|
341
|
+
":aria-expanded"() {
|
|
342
|
+
return String(this.expanded);
|
|
343
|
+
},
|
|
344
|
+
"@click"() {
|
|
345
|
+
this.expanded = !this.expanded;
|
|
346
|
+
},
|
|
347
|
+
},
|
|
348
|
+
content: {
|
|
349
|
+
":data-expanded"() {
|
|
350
|
+
return String(this.expanded);
|
|
351
|
+
},
|
|
352
|
+
},
|
|
353
|
+
}));
|
|
354
|
+
|
|
355
|
+
// The Popover API helpers lilyPopover, lilyDropdownMenu and lilyContextMenu share (tasks.md P18-T8, P18-T11).
|
|
356
|
+
function popoverNative() {
|
|
357
|
+
return (
|
|
358
|
+
typeof HTMLElement !== "undefined" &&
|
|
359
|
+
typeof HTMLElement.prototype.showPopover === "function"
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
function syncPopover(node, open, native) {
|
|
363
|
+
if (!node || !native) return;
|
|
364
|
+
try {
|
|
365
|
+
if (open) node.showPopover();
|
|
366
|
+
else node.hidePopover();
|
|
367
|
+
} catch {
|
|
368
|
+
// Already in that state (older engines throw): nothing to do.
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// P16-T4: a popup that is popover="manual" (top layer) and shown from the component's `open`. With the Popover
|
|
373
|
+
// API the browser's UA style hides it while closed and the effect shows or hides it; without (jsdom, older
|
|
374
|
+
// engines) the popover attribute is dropped, which would otherwise keep it hidden, and `hidden` is bound.
|
|
375
|
+
function manualPopover(isOpen) {
|
|
376
|
+
return {
|
|
377
|
+
":popover"() {
|
|
378
|
+
return popoverNative() ? "manual" : false;
|
|
379
|
+
},
|
|
380
|
+
":hidden"() {
|
|
381
|
+
return !popoverNative() && !isOpen(this);
|
|
382
|
+
},
|
|
383
|
+
"x-effect"() {
|
|
384
|
+
syncPopover(this.$el, Boolean(isOpen(this)), popoverNative());
|
|
385
|
+
},
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// Popover (popover, popup, contextual-help): non-modal. The panel is
|
|
390
|
+
// popover="auto" and the trigger names it with command="toggle-popover"
|
|
391
|
+
// commandfor (and popovertarget), so the browser opens it and closes it
|
|
392
|
+
// on Escape and on a click outside (light dismiss), with no script; the
|
|
393
|
+
// panel's `toggle` event keeps `open` in step. Where the Popover API is
|
|
394
|
+
// missing (jsdom, engines before Chrome 114, Firefox 125, Safari 17) the
|
|
395
|
+
// panel falls back to `hidden` (dropping `popover`, which jsdom's UA
|
|
396
|
+
// stylesheet would otherwise keep hidden), the trigger toggles it, and
|
|
397
|
+
// Escape and an outside click close it. `focus: true` moves focus into
|
|
398
|
+
// the panel on open (popup).
|
|
399
|
+
Alpine.data("lilyPopover", (open = false, { focus = false } = {}) => ({
|
|
400
|
+
open,
|
|
401
|
+
init() {
|
|
402
|
+
// Native only: the fallback is the :hidden binding on the panel.
|
|
403
|
+
this.$nextTick(() => this.sync());
|
|
404
|
+
this.$watch("open", (value) => {
|
|
405
|
+
this.sync();
|
|
406
|
+
if (value && focus) this.$nextTick(() => this.focusIn());
|
|
407
|
+
});
|
|
408
|
+
},
|
|
409
|
+
native: popoverNative,
|
|
410
|
+
sync() {
|
|
411
|
+
syncPopover(this.$refs.panel, this.open, this.native());
|
|
412
|
+
},
|
|
413
|
+
focusIn() {
|
|
414
|
+
const panel = this.$refs.panel;
|
|
415
|
+
if (!panel) return;
|
|
416
|
+
(panel.querySelector(FOCUSABLE) || panel).focus();
|
|
417
|
+
},
|
|
418
|
+
close() {
|
|
419
|
+
this.open = false;
|
|
420
|
+
this.$refs.trigger?.focus();
|
|
421
|
+
},
|
|
422
|
+
root: {
|
|
423
|
+
":data-open"() {
|
|
424
|
+
return String(this.open);
|
|
425
|
+
},
|
|
426
|
+
"@keydown.escape"() {
|
|
427
|
+
if (this.open) this.close();
|
|
428
|
+
},
|
|
429
|
+
// Not `.outside`: Alpine skips elements with no layout box, so it
|
|
430
|
+
// would never fire in a layout-less test DOM. Fallback only: with
|
|
431
|
+
// the Popover API the browser light-dismisses.
|
|
432
|
+
"@click.document"(event) {
|
|
433
|
+
if (this.open && !this.native() && !this.$el.contains(event.target))
|
|
434
|
+
this.open = false;
|
|
435
|
+
},
|
|
436
|
+
},
|
|
437
|
+
trigger: {
|
|
438
|
+
type: "button",
|
|
439
|
+
"x-ref": "trigger",
|
|
440
|
+
"aria-haspopup": "dialog",
|
|
441
|
+
":aria-expanded"() {
|
|
442
|
+
return String(this.open);
|
|
443
|
+
},
|
|
444
|
+
"@click"(event) {
|
|
445
|
+
// With the Popover API the browser toggles the panel (command / popovertarget).
|
|
446
|
+
if (!event.defaultPrevented && !this.native()) this.open = !this.open;
|
|
447
|
+
},
|
|
448
|
+
},
|
|
449
|
+
panel: {
|
|
450
|
+
"x-ref": "panel",
|
|
451
|
+
":data-open"() {
|
|
452
|
+
return String(this.open);
|
|
453
|
+
},
|
|
454
|
+
// Without the Popover API: no popover attribute (jsdom's UA stylesheet hides any [popover] it cannot
|
|
455
|
+
// open) and `hidden` instead. With it, the browser's UA style hides the closed popover.
|
|
456
|
+
":popover"() {
|
|
457
|
+
return this.native() ? "auto" : false;
|
|
458
|
+
},
|
|
459
|
+
":hidden"() {
|
|
460
|
+
return !this.native() && !this.open;
|
|
461
|
+
},
|
|
462
|
+
"@toggle"(event) {
|
|
463
|
+
this.open = event.newState === "open";
|
|
464
|
+
},
|
|
465
|
+
},
|
|
466
|
+
closer: {
|
|
467
|
+
type: "button",
|
|
468
|
+
"@click"() {
|
|
469
|
+
this.close();
|
|
470
|
+
},
|
|
471
|
+
},
|
|
472
|
+
}));
|
|
473
|
+
|
|
474
|
+
// Tooltip: shows on hover and keyboard focus, Escape dismisses (WCAG 1.4.13).
|
|
475
|
+
Alpine.data("lilyTooltip", () => ({
|
|
476
|
+
visible: false,
|
|
477
|
+
trigger: {
|
|
478
|
+
"@mouseenter"() {
|
|
479
|
+
this.visible = true;
|
|
480
|
+
},
|
|
481
|
+
"@mouseleave"() {
|
|
482
|
+
this.visible = false;
|
|
483
|
+
},
|
|
484
|
+
"@focus"() {
|
|
485
|
+
this.visible = true;
|
|
486
|
+
},
|
|
487
|
+
"@blur"() {
|
|
488
|
+
this.visible = false;
|
|
489
|
+
},
|
|
490
|
+
"@keydown.escape"() {
|
|
491
|
+
this.visible = false;
|
|
492
|
+
},
|
|
493
|
+
},
|
|
494
|
+
tooltip: {
|
|
495
|
+
role: "tooltip",
|
|
496
|
+
":aria-hidden"() {
|
|
497
|
+
return String(!this.visible);
|
|
498
|
+
},
|
|
499
|
+
":hidden"() {
|
|
500
|
+
return !this.visible;
|
|
501
|
+
},
|
|
502
|
+
"@mouseenter"() {
|
|
503
|
+
this.visible = true;
|
|
504
|
+
},
|
|
505
|
+
"@mouseleave"() {
|
|
506
|
+
this.visible = false;
|
|
507
|
+
},
|
|
508
|
+
},
|
|
509
|
+
}));
|
|
510
|
+
|
|
511
|
+
// ClipboardCopyButton: the text to copy is the consumer's.
|
|
512
|
+
Alpine.data("lilyClipboardCopy", (text = "") => ({
|
|
513
|
+
copied: false,
|
|
514
|
+
async copy() {
|
|
515
|
+
if (!globalThis.navigator?.clipboard) return;
|
|
516
|
+
await navigator.clipboard.writeText(text);
|
|
517
|
+
this.copied = true;
|
|
518
|
+
},
|
|
519
|
+
button: {
|
|
520
|
+
type: "button",
|
|
521
|
+
":data-copied"() {
|
|
522
|
+
return String(this.copied);
|
|
523
|
+
},
|
|
524
|
+
"@click"() {
|
|
525
|
+
return this.copy();
|
|
526
|
+
},
|
|
527
|
+
},
|
|
528
|
+
}));
|
|
529
|
+
|
|
530
|
+
// ToggleGroup: independent toggle buttons in one role="group".
|
|
531
|
+
Alpine.data("lilyToggleGroup", (pressed = []) => ({
|
|
532
|
+
pressed: [...pressed],
|
|
533
|
+
isPressed(id) {
|
|
534
|
+
return this.pressed.includes(id);
|
|
535
|
+
},
|
|
536
|
+
toggleItem(id) {
|
|
537
|
+
this.pressed = this.isPressed(id)
|
|
538
|
+
? this.pressed.filter((p) => p !== id)
|
|
539
|
+
: [...this.pressed, id];
|
|
540
|
+
},
|
|
541
|
+
item(id) {
|
|
542
|
+
return {
|
|
543
|
+
type: "button",
|
|
544
|
+
":aria-pressed"() {
|
|
545
|
+
return String(this.isPressed(id));
|
|
546
|
+
},
|
|
547
|
+
"@click"() {
|
|
548
|
+
this.toggleItem(id);
|
|
549
|
+
},
|
|
550
|
+
};
|
|
551
|
+
},
|
|
552
|
+
}));
|
|
553
|
+
|
|
554
|
+
// Tabs: TabBar + TabBarButton + TabPanel with automatic activation,
|
|
555
|
+
// roving tabindex and Arrow / Home / End keys (APG tabs pattern).
|
|
556
|
+
Alpine.data("lilyTabs", (selected = "") => ({
|
|
557
|
+
selected,
|
|
558
|
+
tabIds() {
|
|
559
|
+
return Array.from(this.$el.querySelectorAll('[role="tab"]')).map((t) => t.dataset.tab);
|
|
560
|
+
},
|
|
561
|
+
tablist: {
|
|
562
|
+
"@keydown"(event) {
|
|
563
|
+
const tabs = Array.from(this.$el.querySelectorAll('[role="tab"]'));
|
|
564
|
+
const index = tabs.indexOf(document.activeElement);
|
|
565
|
+
if (index < 0) return;
|
|
566
|
+
const next = rovingIndex(event.key, index, tabs.length);
|
|
567
|
+
if (next < 0) return;
|
|
568
|
+
event.preventDefault();
|
|
569
|
+
tabs[next].focus();
|
|
570
|
+
this.selected = tabs[next].dataset.tab;
|
|
571
|
+
},
|
|
572
|
+
},
|
|
573
|
+
tab(id) {
|
|
574
|
+
return {
|
|
575
|
+
role: "tab",
|
|
576
|
+
type: "button",
|
|
577
|
+
"data-tab": id,
|
|
578
|
+
":id"() {
|
|
579
|
+
return `${id}-tab`;
|
|
580
|
+
},
|
|
581
|
+
":aria-controls"() {
|
|
582
|
+
return `${id}-panel`;
|
|
583
|
+
},
|
|
584
|
+
":aria-selected"() {
|
|
585
|
+
return String(this.selected === id);
|
|
586
|
+
},
|
|
587
|
+
":tabindex"() {
|
|
588
|
+
return this.selected === id ? "0" : "-1";
|
|
589
|
+
},
|
|
590
|
+
"@click"() {
|
|
591
|
+
this.selected = id;
|
|
592
|
+
},
|
|
593
|
+
};
|
|
594
|
+
},
|
|
595
|
+
panel(id) {
|
|
596
|
+
return {
|
|
597
|
+
role: "tabpanel",
|
|
598
|
+
tabindex: "0",
|
|
599
|
+
":id"() {
|
|
600
|
+
return `${id}-panel`;
|
|
601
|
+
},
|
|
602
|
+
":aria-labelledby"() {
|
|
603
|
+
return `${id}-tab`;
|
|
604
|
+
},
|
|
605
|
+
":data-selected"() {
|
|
606
|
+
return String(this.selected === id);
|
|
607
|
+
},
|
|
608
|
+
":hidden"() {
|
|
609
|
+
return this.selected !== id;
|
|
610
|
+
},
|
|
611
|
+
};
|
|
612
|
+
},
|
|
613
|
+
}));
|
|
614
|
+
|
|
615
|
+
// Dialog: native <dialog>; showModal() where the browser has it.
|
|
616
|
+
Alpine.data("lilyDialog", (open = false) => ({
|
|
617
|
+
open,
|
|
618
|
+
init() {
|
|
619
|
+
this.$watch("open", (value) => this.sync(value));
|
|
620
|
+
if (open) this.$nextTick(() => this.sync(true));
|
|
621
|
+
},
|
|
622
|
+
sync(value) {
|
|
623
|
+
const dialog = this.$refs.dialog;
|
|
624
|
+
if (!dialog) return;
|
|
625
|
+
if (value && !dialog.open) {
|
|
626
|
+
typeof dialog.showModal === "function"
|
|
627
|
+
? dialog.showModal()
|
|
628
|
+
: dialog.setAttribute("open", "");
|
|
629
|
+
} else if (!value && dialog.open) {
|
|
630
|
+
typeof dialog.close === "function"
|
|
631
|
+
? dialog.close()
|
|
632
|
+
: dialog.removeAttribute("open");
|
|
633
|
+
}
|
|
634
|
+
},
|
|
635
|
+
trigger: {
|
|
636
|
+
type: "button",
|
|
637
|
+
"aria-haspopup": "dialog",
|
|
638
|
+
"@click"() {
|
|
639
|
+
this.open = true;
|
|
640
|
+
},
|
|
641
|
+
},
|
|
642
|
+
dialog: {
|
|
643
|
+
"x-ref": "dialog",
|
|
644
|
+
"aria-modal": "true",
|
|
645
|
+
"@close"() {
|
|
646
|
+
this.open = false;
|
|
647
|
+
},
|
|
648
|
+
"@cancel"() {
|
|
649
|
+
this.open = false;
|
|
650
|
+
},
|
|
651
|
+
"@keydown.escape"(event) {
|
|
652
|
+
if (!event.defaultPrevented) this.open = false;
|
|
653
|
+
},
|
|
654
|
+
},
|
|
655
|
+
closer: {
|
|
656
|
+
type: "button",
|
|
657
|
+
"@click"() {
|
|
658
|
+
this.open = false;
|
|
659
|
+
},
|
|
660
|
+
},
|
|
661
|
+
}));
|
|
662
|
+
// Dismissible: a banner the user can close. Hides with `hidden` (never an
|
|
663
|
+
// inline style) and emits a bubbling `close` event.
|
|
664
|
+
Alpine.data("lilyDismissible", (open = true) => ({
|
|
665
|
+
open,
|
|
666
|
+
root: {
|
|
667
|
+
":hidden"() {
|
|
668
|
+
return !this.open;
|
|
669
|
+
},
|
|
670
|
+
},
|
|
671
|
+
dismiss: {
|
|
672
|
+
type: "button",
|
|
673
|
+
"@click"() {
|
|
674
|
+
this.open = false;
|
|
675
|
+
this.$dispatch("close");
|
|
676
|
+
},
|
|
677
|
+
},
|
|
678
|
+
}));
|
|
679
|
+
|
|
680
|
+
// Accordion: trigger / region pairs by id; one open at a time unless `multiple`.
|
|
681
|
+
Alpine.data("lilyAccordion", (multiple = false, open = []) => ({
|
|
682
|
+
open: [...open],
|
|
683
|
+
isOpen(id) {
|
|
684
|
+
return this.open.includes(id);
|
|
685
|
+
},
|
|
686
|
+
toggle(id) {
|
|
687
|
+
if (this.isOpen(id)) this.open = this.open.filter((o) => o !== id);
|
|
688
|
+
else this.open = multiple ? [...this.open, id] : [id];
|
|
689
|
+
},
|
|
690
|
+
trigger(id) {
|
|
691
|
+
return {
|
|
692
|
+
type: "button",
|
|
693
|
+
":id"() {
|
|
694
|
+
return `${id}-trigger`;
|
|
695
|
+
},
|
|
696
|
+
":aria-controls"() {
|
|
697
|
+
return `${id}-panel`;
|
|
698
|
+
},
|
|
699
|
+
":aria-expanded"() {
|
|
700
|
+
return String(this.isOpen(id));
|
|
701
|
+
},
|
|
702
|
+
"@click"() {
|
|
703
|
+
this.toggle(id);
|
|
704
|
+
},
|
|
705
|
+
};
|
|
706
|
+
},
|
|
707
|
+
panel(id) {
|
|
708
|
+
return {
|
|
709
|
+
role: "region",
|
|
710
|
+
":id"() {
|
|
711
|
+
return `${id}-panel`;
|
|
712
|
+
},
|
|
713
|
+
":aria-labelledby"() {
|
|
714
|
+
return `${id}-trigger`;
|
|
715
|
+
},
|
|
716
|
+
":hidden"() {
|
|
717
|
+
return !this.isOpen(id);
|
|
718
|
+
},
|
|
719
|
+
};
|
|
720
|
+
},
|
|
721
|
+
}));
|
|
722
|
+
|
|
723
|
+
// CheckboxAccordion: a real checkbox is the disclosure control.
|
|
724
|
+
Alpine.data("lilyCheckboxAccordion", (checked = false) => ({
|
|
725
|
+
checked,
|
|
726
|
+
input: {
|
|
727
|
+
":checked"() {
|
|
728
|
+
return this.checked;
|
|
729
|
+
},
|
|
730
|
+
":aria-expanded"() {
|
|
731
|
+
return String(this.checked);
|
|
732
|
+
},
|
|
733
|
+
"@change"() {
|
|
734
|
+
this.checked = this.$el.checked;
|
|
735
|
+
},
|
|
736
|
+
},
|
|
737
|
+
panel: {
|
|
738
|
+
":hidden"() {
|
|
739
|
+
return !this.checked;
|
|
740
|
+
},
|
|
741
|
+
},
|
|
742
|
+
}));
|
|
743
|
+
|
|
744
|
+
// HoverCard: opens on hover or focus within, stays open while the pointer
|
|
745
|
+
// is over the card (it is inside the root), Escape dismisses (WCAG 1.4.13).
|
|
746
|
+
Alpine.data("lilyHoverCard", () => ({
|
|
747
|
+
open: false,
|
|
748
|
+
root: {
|
|
749
|
+
":data-open"() {
|
|
750
|
+
return String(this.open);
|
|
751
|
+
},
|
|
752
|
+
"@mouseenter"() {
|
|
753
|
+
this.open = true;
|
|
754
|
+
},
|
|
755
|
+
"@mouseleave"() {
|
|
756
|
+
this.open = false;
|
|
757
|
+
},
|
|
758
|
+
"@focusin"() {
|
|
759
|
+
this.open = true;
|
|
760
|
+
},
|
|
761
|
+
"@focusout"(event) {
|
|
762
|
+
if (!this.$el.contains(event.relatedTarget)) this.open = false;
|
|
763
|
+
},
|
|
764
|
+
"@keydown.escape"() {
|
|
765
|
+
this.open = false;
|
|
766
|
+
},
|
|
767
|
+
},
|
|
768
|
+
card: {
|
|
769
|
+
...manualPopover((o) => o.open),
|
|
770
|
+
},
|
|
771
|
+
}));
|
|
772
|
+
// Modal surface (tasks.md P18-T6): drawer, sheet and slide-out drawer are a
|
|
773
|
+
// <dialog> opened with showModal(), so the browser traps Tab, makes the page
|
|
774
|
+
// inert and puts the panel in the top layer. Where showModal is missing
|
|
775
|
+
// (jsdom) it falls back to the open attribute. Focus moves in on open and
|
|
776
|
+
// returns to the opener on close; Escape, the native cancel event and a
|
|
777
|
+
// native close (form method="dialog") all set `open` to false.
|
|
778
|
+
Alpine.data("lilyModalSurface", (open = false) => ({
|
|
779
|
+
open,
|
|
780
|
+
opener: null,
|
|
781
|
+
init() {
|
|
782
|
+
this.$watch("open", (value) => this.sync(value));
|
|
783
|
+
if (open) this.$nextTick(() => this.sync(true));
|
|
784
|
+
},
|
|
785
|
+
sync(value) {
|
|
786
|
+
const dialog = this.$refs.surface;
|
|
787
|
+
if (!dialog) return;
|
|
788
|
+
if (value && !dialog.open) {
|
|
789
|
+
this.opener = document.activeElement;
|
|
790
|
+
typeof dialog.showModal === "function"
|
|
791
|
+
? dialog.showModal()
|
|
792
|
+
: dialog.setAttribute("open", "");
|
|
793
|
+
if (!dialog.contains(document.activeElement)) {
|
|
794
|
+
(dialog.querySelector(FOCUSABLE) || dialog).focus();
|
|
795
|
+
}
|
|
796
|
+
} else if (!value && dialog.open) {
|
|
797
|
+
typeof dialog.close === "function"
|
|
798
|
+
? dialog.close()
|
|
799
|
+
: dialog.removeAttribute("open");
|
|
800
|
+
const back = this.opener || this.$refs.trigger;
|
|
801
|
+
this.opener = null;
|
|
802
|
+
if (back && back !== document.body && back.isConnected) back.focus();
|
|
803
|
+
}
|
|
804
|
+
},
|
|
805
|
+
trigger: {
|
|
806
|
+
type: "button",
|
|
807
|
+
"x-ref": "trigger",
|
|
808
|
+
"aria-haspopup": "dialog",
|
|
809
|
+
":aria-expanded"() {
|
|
810
|
+
return String(this.open);
|
|
811
|
+
},
|
|
812
|
+
"@click"() {
|
|
813
|
+
this.open = true;
|
|
814
|
+
},
|
|
815
|
+
},
|
|
816
|
+
surface: {
|
|
817
|
+
"x-ref": "surface",
|
|
818
|
+
"aria-modal": "true",
|
|
819
|
+
":data-open"() {
|
|
820
|
+
return String(this.open);
|
|
821
|
+
},
|
|
822
|
+
"@close"() {
|
|
823
|
+
this.open = false;
|
|
824
|
+
},
|
|
825
|
+
"@cancel.prevent"() {
|
|
826
|
+
this.open = false;
|
|
827
|
+
},
|
|
828
|
+
"@keydown.escape.prevent"() {
|
|
829
|
+
this.open = false;
|
|
830
|
+
},
|
|
831
|
+
},
|
|
832
|
+
closer: {
|
|
833
|
+
type: "button",
|
|
834
|
+
"@click"() {
|
|
835
|
+
this.open = false;
|
|
836
|
+
},
|
|
837
|
+
},
|
|
838
|
+
}));
|
|
839
|
+
// Overlay: a dialog-role surface (popup; overlay-container uses `container`)
|
|
840
|
+
// opened by a trigger. Focus moves in on open and returns to the trigger on
|
|
841
|
+
// close; Escape closes. `container` is the backdrop form (overlay-container).
|
|
842
|
+
Alpine.data("lilyOverlay", (open = false) => ({
|
|
843
|
+
open,
|
|
844
|
+
init() {
|
|
845
|
+
this.$watch("open", (value) => {
|
|
846
|
+
if (value) this.$nextTick(() => this.focusIn());
|
|
847
|
+
});
|
|
848
|
+
},
|
|
849
|
+
focusIn() {
|
|
850
|
+
const surface = this.$refs.surface;
|
|
851
|
+
if (!surface) return;
|
|
852
|
+
const first = surface.querySelector(FOCUSABLE);
|
|
853
|
+
(first || surface).focus();
|
|
854
|
+
},
|
|
855
|
+
close() {
|
|
856
|
+
this.open = false;
|
|
857
|
+
this.$refs.trigger?.focus();
|
|
858
|
+
},
|
|
859
|
+
trigger: {
|
|
860
|
+
type: "button",
|
|
861
|
+
"x-ref": "trigger",
|
|
862
|
+
"aria-haspopup": "dialog",
|
|
863
|
+
":aria-expanded"() {
|
|
864
|
+
return String(this.open);
|
|
865
|
+
},
|
|
866
|
+
"@click"() {
|
|
867
|
+
this.open = !this.open;
|
|
868
|
+
},
|
|
869
|
+
},
|
|
870
|
+
surface: {
|
|
871
|
+
"x-ref": "surface",
|
|
872
|
+
":data-open"() {
|
|
873
|
+
return String(this.open);
|
|
874
|
+
},
|
|
875
|
+
":hidden"() {
|
|
876
|
+
return !this.open;
|
|
877
|
+
},
|
|
878
|
+
"@keydown.escape"() {
|
|
879
|
+
if (this.open) this.close();
|
|
880
|
+
},
|
|
881
|
+
},
|
|
882
|
+
closer: {
|
|
883
|
+
type: "button",
|
|
884
|
+
"@click"() {
|
|
885
|
+
this.close();
|
|
886
|
+
},
|
|
887
|
+
},
|
|
888
|
+
container: {
|
|
889
|
+
role: "presentation",
|
|
890
|
+
":data-open"() {
|
|
891
|
+
return String(this.open);
|
|
892
|
+
},
|
|
893
|
+
":aria-hidden"() {
|
|
894
|
+
return String(!this.open);
|
|
895
|
+
},
|
|
896
|
+
":hidden"() {
|
|
897
|
+
return !this.open;
|
|
898
|
+
},
|
|
899
|
+
"@click"(event) {
|
|
900
|
+
if (event.target === this.$el) this.$dispatch("overlay-close");
|
|
901
|
+
},
|
|
902
|
+
},
|
|
903
|
+
}));
|
|
904
|
+
|
|
905
|
+
// Confirm: a non-modal alertdialog with confirm and cancel. Emits the
|
|
906
|
+
// bubbling `lily:confirm` / `lily:cancel` events and closes; Escape cancels.
|
|
907
|
+
Alpine.data("lilyConfirm", (open = false) => ({
|
|
908
|
+
open,
|
|
909
|
+
root: {
|
|
910
|
+
...manualPopover((o) => o.open),
|
|
911
|
+
"@keydown.escape"() {
|
|
912
|
+
if (this.open) this.cancel();
|
|
913
|
+
},
|
|
914
|
+
},
|
|
915
|
+
trigger: {
|
|
916
|
+
type: "button",
|
|
917
|
+
"aria-haspopup": "dialog",
|
|
918
|
+
":aria-expanded"() {
|
|
919
|
+
return String(this.open);
|
|
920
|
+
},
|
|
921
|
+
"@click"() {
|
|
922
|
+
this.open = !this.open;
|
|
923
|
+
},
|
|
924
|
+
},
|
|
925
|
+
confirm() {
|
|
926
|
+
this.open = false;
|
|
927
|
+
this.$dispatch("lily:confirm");
|
|
928
|
+
},
|
|
929
|
+
cancel() {
|
|
930
|
+
this.open = false;
|
|
931
|
+
this.$dispatch("lily:cancel");
|
|
932
|
+
},
|
|
933
|
+
confirmButton: {
|
|
934
|
+
type: "button",
|
|
935
|
+
"@click"() {
|
|
936
|
+
this.confirm();
|
|
937
|
+
},
|
|
938
|
+
},
|
|
939
|
+
cancelButton: {
|
|
940
|
+
type: "button",
|
|
941
|
+
"@click"() {
|
|
942
|
+
this.cancel();
|
|
943
|
+
},
|
|
944
|
+
},
|
|
945
|
+
}));
|
|
946
|
+
// Menu / MenuBar: an always-visible menu with roving tabindex. Vertical
|
|
947
|
+
// for role="menu", horizontal for role="menubar"; arrows wrap, Home/End jump.
|
|
948
|
+
Alpine.data("lilyMenu", (orientation = "vertical") => ({
|
|
949
|
+
current: "",
|
|
950
|
+
ids() {
|
|
951
|
+
// $root, not $el: this runs while an item evaluates its own :tabindex.
|
|
952
|
+
return Array.from(this.$root.querySelectorAll(MENU_ITEMS)).map((i) => i.dataset.item);
|
|
953
|
+
},
|
|
954
|
+
menu: {
|
|
955
|
+
"@keydown"(event) {
|
|
956
|
+
menuKeydown(event, orientation);
|
|
957
|
+
},
|
|
958
|
+
// A parent item toggles its submenu; the keys and the rest are menu-keys.js.
|
|
959
|
+
"@click"(event) {
|
|
960
|
+
const item = event.target.closest("[aria-controls]");
|
|
961
|
+
if (!item || !this.$el.contains(item)) return;
|
|
962
|
+
const menu = document.getElementById(item.getAttribute("aria-controls"));
|
|
963
|
+
if (menu?.getAttribute("role") !== "menu") return;
|
|
964
|
+
const open = item.getAttribute("aria-expanded") !== "true";
|
|
965
|
+
item.setAttribute("aria-expanded", String(open));
|
|
966
|
+
menu.hidden = !open;
|
|
967
|
+
},
|
|
968
|
+
},
|
|
969
|
+
item(id) {
|
|
970
|
+
return {
|
|
971
|
+
role: "menuitem",
|
|
972
|
+
"data-item": id,
|
|
973
|
+
":tabindex"() {
|
|
974
|
+
return (this.current || this.ids()[0]) === id ? "0" : "-1";
|
|
975
|
+
},
|
|
976
|
+
"@focus"() {
|
|
977
|
+
this.current = id;
|
|
978
|
+
},
|
|
979
|
+
};
|
|
980
|
+
},
|
|
981
|
+
}));
|
|
982
|
+
|
|
983
|
+
// DropdownMenu: a trigger opening a role="menu" popup (also the split-button
|
|
984
|
+
// menu and the action-group overflow). Focus moves to the first item on
|
|
985
|
+
// open and back to the trigger on close; Escape and a selection close,
|
|
986
|
+
// Tab and an outside click close without moving focus.
|
|
987
|
+
//
|
|
988
|
+
// The popup is popover="auto" (tasks.md P18-T11), as in lilyPopover: the
|
|
989
|
+
// trigger names it with command="toggle-popover" commandfor (and
|
|
990
|
+
// popovertarget), so the browser opens it and light-dismisses it with no
|
|
991
|
+
// script, and the `toggle` event keeps `open` in step. Where the Popover
|
|
992
|
+
// API is missing the popup falls back to `hidden` and the trigger and an
|
|
993
|
+
// outside click toggle it. The arrow-key focus code has no native
|
|
994
|
+
// equivalent and stays.
|
|
995
|
+
Alpine.data("lilyDropdownMenu", (open = false) => ({
|
|
996
|
+
open,
|
|
997
|
+
init() {
|
|
998
|
+
this.$nextTick(() => this.sync());
|
|
999
|
+
this.$watch("open", (value) => {
|
|
1000
|
+
this.sync();
|
|
1001
|
+
if (value) this.$nextTick(() => this.items()[0]?.focus());
|
|
1002
|
+
});
|
|
1003
|
+
},
|
|
1004
|
+
native: popoverNative,
|
|
1005
|
+
sync() {
|
|
1006
|
+
syncPopover(this.$refs.menu, this.open, this.native());
|
|
1007
|
+
},
|
|
1008
|
+
items() {
|
|
1009
|
+
return Array.from(this.$refs.menu?.querySelectorAll(MENU_ITEMS) ?? []);
|
|
1010
|
+
},
|
|
1011
|
+
close(returnFocus = true) {
|
|
1012
|
+
this.open = false;
|
|
1013
|
+
if (returnFocus) this.$refs.trigger?.focus();
|
|
1014
|
+
},
|
|
1015
|
+
root: {
|
|
1016
|
+
":data-open"() {
|
|
1017
|
+
return String(this.open);
|
|
1018
|
+
},
|
|
1019
|
+
// Fallback only: with the Popover API the browser light-dismisses.
|
|
1020
|
+
"@click.document"(event) {
|
|
1021
|
+
if (this.open && !this.native() && !this.$el.contains(event.target))
|
|
1022
|
+
this.open = false;
|
|
1023
|
+
},
|
|
1024
|
+
},
|
|
1025
|
+
trigger: {
|
|
1026
|
+
type: "button",
|
|
1027
|
+
"x-ref": "trigger",
|
|
1028
|
+
"aria-haspopup": "menu",
|
|
1029
|
+
":aria-expanded"() {
|
|
1030
|
+
return String(this.open);
|
|
1031
|
+
},
|
|
1032
|
+
"@click"(event) {
|
|
1033
|
+
// With the Popover API the browser toggles the popup (command / popovertarget).
|
|
1034
|
+
if (!event.defaultPrevented && !this.native()) this.open = !this.open;
|
|
1035
|
+
},
|
|
1036
|
+
"@keydown.arrow-down.prevent"() {
|
|
1037
|
+
this.open = true;
|
|
1038
|
+
},
|
|
1039
|
+
},
|
|
1040
|
+
menu: {
|
|
1041
|
+
role: "menu",
|
|
1042
|
+
"x-ref": "menu",
|
|
1043
|
+
":popover"() {
|
|
1044
|
+
return this.native() ? "auto" : false;
|
|
1045
|
+
},
|
|
1046
|
+
":hidden"() {
|
|
1047
|
+
return !this.native() && !this.open;
|
|
1048
|
+
},
|
|
1049
|
+
"@toggle"(event) {
|
|
1050
|
+
this.open = event.newState === "open";
|
|
1051
|
+
},
|
|
1052
|
+
"@keydown"(event) {
|
|
1053
|
+
if (event.key === "Escape") return this.close();
|
|
1054
|
+
if (event.key === "Tab") return this.close(false);
|
|
1055
|
+
const items = this.items();
|
|
1056
|
+
const target = menuTarget(
|
|
1057
|
+
event.key,
|
|
1058
|
+
items,
|
|
1059
|
+
items.indexOf(document.activeElement),
|
|
1060
|
+
false,
|
|
1061
|
+
);
|
|
1062
|
+
if (!target) return;
|
|
1063
|
+
event.preventDefault();
|
|
1064
|
+
target.focus();
|
|
1065
|
+
},
|
|
1066
|
+
},
|
|
1067
|
+
item: {
|
|
1068
|
+
role: "menuitem",
|
|
1069
|
+
tabindex: "-1",
|
|
1070
|
+
"@click"() {
|
|
1071
|
+
this.close();
|
|
1072
|
+
},
|
|
1073
|
+
},
|
|
1074
|
+
}));
|
|
1075
|
+
|
|
1076
|
+
// ContextMenu: opens on the right button, or the ContextMenu key / Shift+F10
|
|
1077
|
+
// on the focusable target. The pointer position is exposed as the CSS
|
|
1078
|
+
// custom properties --context-menu-x / --context-menu-y.
|
|
1079
|
+
//
|
|
1080
|
+
// The menu is popover="auto" (tasks.md P18-T11): opening shows it with
|
|
1081
|
+
// showPopover(), in the top layer, and the browser closes it on Escape and
|
|
1082
|
+
// on a click outside; the `toggle` event keeps `open` in step. Where the
|
|
1083
|
+
// Popover API is missing it falls back to `hidden` and an outside click.
|
|
1084
|
+
Alpine.data("lilyContextMenu", () => ({
|
|
1085
|
+
open: false,
|
|
1086
|
+
x: 0,
|
|
1087
|
+
y: 0,
|
|
1088
|
+
init() {
|
|
1089
|
+
this.$nextTick(() => this.sync());
|
|
1090
|
+
this.$watch("open", (value) => {
|
|
1091
|
+
this.sync();
|
|
1092
|
+
if (value) this.$nextTick(() => this.items()[0]?.focus());
|
|
1093
|
+
});
|
|
1094
|
+
},
|
|
1095
|
+
native: popoverNative,
|
|
1096
|
+
sync() {
|
|
1097
|
+
syncPopover(this.$refs.menu, this.open, this.native());
|
|
1098
|
+
},
|
|
1099
|
+
items() {
|
|
1100
|
+
return Array.from(this.$refs.menu?.querySelectorAll(MENU_ITEMS) ?? []);
|
|
1101
|
+
},
|
|
1102
|
+
close(returnFocus = true) {
|
|
1103
|
+
this.open = false;
|
|
1104
|
+
if (returnFocus) this.$refs.target?.focus();
|
|
1105
|
+
},
|
|
1106
|
+
target: {
|
|
1107
|
+
"x-ref": "target",
|
|
1108
|
+
"@contextmenu.prevent"(event) {
|
|
1109
|
+
this.x = event.clientX;
|
|
1110
|
+
this.y = event.clientY;
|
|
1111
|
+
this.open = true;
|
|
1112
|
+
},
|
|
1113
|
+
"@keydown"(event) {
|
|
1114
|
+
if (event.key === "ContextMenu" || (event.key === "F10" && event.shiftKey)) {
|
|
1115
|
+
event.preventDefault();
|
|
1116
|
+
const box = this.$el.getBoundingClientRect();
|
|
1117
|
+
this.x = box.left;
|
|
1118
|
+
this.y = box.bottom;
|
|
1119
|
+
this.open = true;
|
|
1120
|
+
}
|
|
1121
|
+
},
|
|
1122
|
+
},
|
|
1123
|
+
menu: {
|
|
1124
|
+
role: "menu",
|
|
1125
|
+
"x-ref": "menu",
|
|
1126
|
+
":popover"() {
|
|
1127
|
+
return this.native() ? "auto" : false;
|
|
1128
|
+
},
|
|
1129
|
+
":hidden"() {
|
|
1130
|
+
return !this.native() && !this.open;
|
|
1131
|
+
},
|
|
1132
|
+
"@toggle"(event) {
|
|
1133
|
+
this.open = event.newState === "open";
|
|
1134
|
+
},
|
|
1135
|
+
":style"() {
|
|
1136
|
+
return { "--context-menu-x": `${this.x}px`, "--context-menu-y": `${this.y}px` };
|
|
1137
|
+
},
|
|
1138
|
+
// Fallback only: with the Popover API the browser light-dismisses.
|
|
1139
|
+
"@click.document"(event) {
|
|
1140
|
+
if (this.open && !this.native() && !this.$el.contains(event.target))
|
|
1141
|
+
this.open = false;
|
|
1142
|
+
},
|
|
1143
|
+
"@keydown"(event) {
|
|
1144
|
+
if (event.key === "Escape") return this.close();
|
|
1145
|
+
if (event.key === "Tab") return this.close(false);
|
|
1146
|
+
const items = this.items();
|
|
1147
|
+
const target = menuTarget(
|
|
1148
|
+
event.key,
|
|
1149
|
+
items,
|
|
1150
|
+
items.indexOf(document.activeElement),
|
|
1151
|
+
false,
|
|
1152
|
+
);
|
|
1153
|
+
if (!target) return;
|
|
1154
|
+
event.preventDefault();
|
|
1155
|
+
target.focus();
|
|
1156
|
+
},
|
|
1157
|
+
},
|
|
1158
|
+
item: {
|
|
1159
|
+
role: "menuitem",
|
|
1160
|
+
tabindex: "-1",
|
|
1161
|
+
"@click"() {
|
|
1162
|
+
this.close();
|
|
1163
|
+
},
|
|
1164
|
+
},
|
|
1165
|
+
}));
|
|
1166
|
+
|
|
1167
|
+
// Listbox: role="listbox" of role="option" items with roving focus
|
|
1168
|
+
// (arrows wrap, Home/End jump) and selection (single or multiple).
|
|
1169
|
+
Alpine.data("lilyListbox", (multiple = false, selected = []) => ({
|
|
1170
|
+
multiple,
|
|
1171
|
+
selected: [].concat(selected).filter((s) => s !== ""),
|
|
1172
|
+
current: "",
|
|
1173
|
+
ids() {
|
|
1174
|
+
// $root, not $el: this runs while an option evaluates its own :tabindex.
|
|
1175
|
+
return Array.from(this.$root.querySelectorAll('[role="option"]')).map(
|
|
1176
|
+
(o) => o.dataset.option,
|
|
1177
|
+
);
|
|
1178
|
+
},
|
|
1179
|
+
isSelected(id) {
|
|
1180
|
+
return this.selected.includes(id);
|
|
1181
|
+
},
|
|
1182
|
+
choose(id) {
|
|
1183
|
+
if (!this.multiple) this.selected = [id];
|
|
1184
|
+
else
|
|
1185
|
+
this.selected = this.isSelected(id)
|
|
1186
|
+
? this.selected.filter((s) => s !== id)
|
|
1187
|
+
: [...this.selected, id];
|
|
1188
|
+
this.$dispatch("lily:select", { selected: [...this.selected] });
|
|
1189
|
+
},
|
|
1190
|
+
listbox: {
|
|
1191
|
+
role: "listbox",
|
|
1192
|
+
":aria-multiselectable"() {
|
|
1193
|
+
return this.multiple ? "true" : null;
|
|
1194
|
+
},
|
|
1195
|
+
"@keydown"(event) {
|
|
1196
|
+
const options = Array.from(this.$el.querySelectorAll('[role="option"]'));
|
|
1197
|
+
const target = menuTarget(
|
|
1198
|
+
event.key,
|
|
1199
|
+
options,
|
|
1200
|
+
options.indexOf(document.activeElement),
|
|
1201
|
+
false,
|
|
1202
|
+
);
|
|
1203
|
+
if (!target) return;
|
|
1204
|
+
event.preventDefault();
|
|
1205
|
+
target.focus();
|
|
1206
|
+
},
|
|
1207
|
+
},
|
|
1208
|
+
option(id) {
|
|
1209
|
+
return {
|
|
1210
|
+
role: "option",
|
|
1211
|
+
"data-option": id,
|
|
1212
|
+
":aria-selected"() {
|
|
1213
|
+
return String(this.isSelected(id));
|
|
1214
|
+
},
|
|
1215
|
+
":tabindex"() {
|
|
1216
|
+
return (this.current || this.selected[0] || this.ids()[0]) === id ? "0" : "-1";
|
|
1217
|
+
},
|
|
1218
|
+
"@focus"() {
|
|
1219
|
+
this.current = id;
|
|
1220
|
+
},
|
|
1221
|
+
"@click"() {
|
|
1222
|
+
this.choose(id);
|
|
1223
|
+
},
|
|
1224
|
+
"@keydown.enter.prevent"() {
|
|
1225
|
+
this.choose(id);
|
|
1226
|
+
},
|
|
1227
|
+
"@keydown.space.prevent"() {
|
|
1228
|
+
this.choose(id);
|
|
1229
|
+
},
|
|
1230
|
+
};
|
|
1231
|
+
},
|
|
1232
|
+
}));
|
|
1233
|
+
|
|
1234
|
+
// SegmentGroup: a role="radiogroup" of role="radio" buttons. Arrow keys move
|
|
1235
|
+
// focus and select (APG radio group); one segment is in the tab order.
|
|
1236
|
+
Alpine.data("lilySegmentGroup", (selected = "") => ({
|
|
1237
|
+
selected,
|
|
1238
|
+
ids() {
|
|
1239
|
+
return Array.from(this.$root.querySelectorAll('[role="radio"]')).map(
|
|
1240
|
+
(r) => r.dataset.segment,
|
|
1241
|
+
);
|
|
1242
|
+
},
|
|
1243
|
+
group: {
|
|
1244
|
+
"@keydown"(event) {
|
|
1245
|
+
const items = Array.from(this.$el.querySelectorAll('[role="radio"]'));
|
|
1246
|
+
const from = items.indexOf(document.activeElement);
|
|
1247
|
+
if (from < 0) return;
|
|
1248
|
+
const next = rovingIndex(event.key, from, items.length);
|
|
1249
|
+
if (next < 0) return;
|
|
1250
|
+
const target = items[next];
|
|
1251
|
+
event.preventDefault();
|
|
1252
|
+
target.focus();
|
|
1253
|
+
this.selected = target.dataset.segment;
|
|
1254
|
+
this.$dispatch("lily:select", { selected: this.selected });
|
|
1255
|
+
},
|
|
1256
|
+
},
|
|
1257
|
+
segment(id) {
|
|
1258
|
+
return {
|
|
1259
|
+
role: "radio",
|
|
1260
|
+
type: "button",
|
|
1261
|
+
"data-segment": id,
|
|
1262
|
+
":aria-checked"() {
|
|
1263
|
+
return String(this.selected === id);
|
|
1264
|
+
},
|
|
1265
|
+
":tabindex"() {
|
|
1266
|
+
return (this.selected || this.ids()[0]) === id ? "0" : "-1";
|
|
1267
|
+
},
|
|
1268
|
+
"@click"() {
|
|
1269
|
+
this.selected = id;
|
|
1270
|
+
this.$dispatch("lily:select", { selected: id });
|
|
1271
|
+
},
|
|
1272
|
+
};
|
|
1273
|
+
},
|
|
1274
|
+
}));
|
|
1275
|
+
|
|
1276
|
+
// Autosuggest: a text input (role="combobox") proposing the consumer's
|
|
1277
|
+
// suggestions in a role="listbox". The consumer listens for lily:input (or
|
|
1278
|
+
// the input's own input event) and renders role="option" items into the
|
|
1279
|
+
// x-ref="list" element; a MutationObserver keeps the open state, the
|
|
1280
|
+
// option ids and the highlight in step. Choosing writes the option's
|
|
1281
|
+
// data-value (else its text) into the input and dispatches lily:select.
|
|
1282
|
+
Alpine.data("lilyAutosuggest", (value = "") => ({
|
|
1283
|
+
value,
|
|
1284
|
+
wanted: false,
|
|
1285
|
+
active: -1,
|
|
1286
|
+
count: 0,
|
|
1287
|
+
get open() {
|
|
1288
|
+
return this.wanted && this.count > 0;
|
|
1289
|
+
},
|
|
1290
|
+
init() {
|
|
1291
|
+
const list = this.$refs.list;
|
|
1292
|
+
this.refresh();
|
|
1293
|
+
new MutationObserver(() => this.refresh()).observe(list, {
|
|
1294
|
+
childList: true,
|
|
1295
|
+
subtree: true,
|
|
1296
|
+
});
|
|
1297
|
+
},
|
|
1298
|
+
options() {
|
|
1299
|
+
return Array.from(this.$refs.list.querySelectorAll('[role="option"]'));
|
|
1300
|
+
},
|
|
1301
|
+
refresh() {
|
|
1302
|
+
const options = this.options();
|
|
1303
|
+
this.count = options.length;
|
|
1304
|
+
if (this.active >= this.count) this.active = -1;
|
|
1305
|
+
this.mark();
|
|
1306
|
+
},
|
|
1307
|
+
mark() {
|
|
1308
|
+
const list = this.$refs.list;
|
|
1309
|
+
this.options().forEach((el, i) => {
|
|
1310
|
+
if (!el.id) el.id = `${list.id}-option-${i}`;
|
|
1311
|
+
el.setAttribute("aria-selected", String(this.open && i === this.active));
|
|
1312
|
+
});
|
|
1313
|
+
},
|
|
1314
|
+
move(active) {
|
|
1315
|
+
this.active = active;
|
|
1316
|
+
this.wanted = true;
|
|
1317
|
+
this.mark();
|
|
1318
|
+
},
|
|
1319
|
+
close() {
|
|
1320
|
+
this.wanted = false;
|
|
1321
|
+
this.active = -1;
|
|
1322
|
+
this.mark();
|
|
1323
|
+
},
|
|
1324
|
+
choose(el) {
|
|
1325
|
+
const chosen = el.getAttribute("data-value") ?? el.textContent.trim();
|
|
1326
|
+
this.value = chosen;
|
|
1327
|
+
this.close();
|
|
1328
|
+
this.$dispatch("lily:select", { value: chosen });
|
|
1329
|
+
},
|
|
1330
|
+
input: {
|
|
1331
|
+
role: "combobox",
|
|
1332
|
+
autocomplete: "off",
|
|
1333
|
+
"aria-autocomplete": "list",
|
|
1334
|
+
":aria-expanded"() {
|
|
1335
|
+
return String(this.open);
|
|
1336
|
+
},
|
|
1337
|
+
":aria-activedescendant"() {
|
|
1338
|
+
return this.open && this.active >= 0
|
|
1339
|
+
? (this.options()[this.active]?.id ?? null)
|
|
1340
|
+
: null;
|
|
1341
|
+
},
|
|
1342
|
+
":value"() {
|
|
1343
|
+
return this.value;
|
|
1344
|
+
},
|
|
1345
|
+
"@input"(event) {
|
|
1346
|
+
this.value = event.target.value;
|
|
1347
|
+
this.wanted = true;
|
|
1348
|
+
this.active = -1;
|
|
1349
|
+
this.mark();
|
|
1350
|
+
this.$dispatch("lily:input", { value: this.value });
|
|
1351
|
+
},
|
|
1352
|
+
"@keydown"(event) {
|
|
1353
|
+
if (event.isComposing) return;
|
|
1354
|
+
const count = this.count;
|
|
1355
|
+
const open = this.open;
|
|
1356
|
+
switch (event.key) {
|
|
1357
|
+
case "ArrowDown":
|
|
1358
|
+
if (count === 0) return;
|
|
1359
|
+
if (event.altKey) {
|
|
1360
|
+
if (open) return;
|
|
1361
|
+
this.wanted = true;
|
|
1362
|
+
this.mark();
|
|
1363
|
+
break;
|
|
1364
|
+
}
|
|
1365
|
+
this.move(open ? (this.active + 1) % count : 0);
|
|
1366
|
+
break;
|
|
1367
|
+
case "ArrowUp":
|
|
1368
|
+
if (event.altKey) {
|
|
1369
|
+
if (!open) return;
|
|
1370
|
+
this.close();
|
|
1371
|
+
break;
|
|
1372
|
+
}
|
|
1373
|
+
if (count === 0) return;
|
|
1374
|
+
this.move(open && this.active > 0 ? this.active - 1 : count - 1);
|
|
1375
|
+
break;
|
|
1376
|
+
case "Home":
|
|
1377
|
+
if (!open) return;
|
|
1378
|
+
this.move(0);
|
|
1379
|
+
break;
|
|
1380
|
+
case "End":
|
|
1381
|
+
if (!open) return;
|
|
1382
|
+
this.move(count - 1);
|
|
1383
|
+
break;
|
|
1384
|
+
case "Enter":
|
|
1385
|
+
if (!open || this.active < 0) return;
|
|
1386
|
+
this.choose(this.options()[this.active]);
|
|
1387
|
+
break;
|
|
1388
|
+
case "Escape":
|
|
1389
|
+
if (!open) return;
|
|
1390
|
+
this.close();
|
|
1391
|
+
break;
|
|
1392
|
+
default:
|
|
1393
|
+
return;
|
|
1394
|
+
}
|
|
1395
|
+
event.preventDefault();
|
|
1396
|
+
},
|
|
1397
|
+
"@blur"() {
|
|
1398
|
+
this.close();
|
|
1399
|
+
},
|
|
1400
|
+
},
|
|
1401
|
+
listbox: {
|
|
1402
|
+
role: "listbox",
|
|
1403
|
+
":hidden"() {
|
|
1404
|
+
return !this.open;
|
|
1405
|
+
},
|
|
1406
|
+
"@mousedown.prevent"() {},
|
|
1407
|
+
"@click"(event) {
|
|
1408
|
+
const el = event.target.closest('[role="option"]');
|
|
1409
|
+
if (el) this.choose(el);
|
|
1410
|
+
},
|
|
1411
|
+
},
|
|
1412
|
+
}));
|
|
1413
|
+
|
|
1414
|
+
// Combobox: a text input driving a role="listbox" popup. The input keeps
|
|
1415
|
+
// DOM focus; the highlighted option is aria-activedescendant. Options are
|
|
1416
|
+
// filtered by the typed text (case-insensitive substring); ArrowDown/Up
|
|
1417
|
+
// move (wrapping), Enter chooses, Escape closes, an outside click closes.
|
|
1418
|
+
Alpine.data("lilyCombobox", (value = "", open = false) => ({
|
|
1419
|
+
value,
|
|
1420
|
+
open,
|
|
1421
|
+
active: "",
|
|
1422
|
+
visible() {
|
|
1423
|
+
return Array.from(this.$root.querySelectorAll('[role="option"]')).filter(
|
|
1424
|
+
(o) => !o.hidden,
|
|
1425
|
+
);
|
|
1426
|
+
},
|
|
1427
|
+
matches(el) {
|
|
1428
|
+
return !this.value || el.textContent.toLowerCase().includes(this.value.toLowerCase());
|
|
1429
|
+
},
|
|
1430
|
+
choose(el) {
|
|
1431
|
+
this.value = el.textContent.trim();
|
|
1432
|
+
this.open = false;
|
|
1433
|
+
this.active = "";
|
|
1434
|
+
this.$dispatch("lily:select", { value: this.value });
|
|
1435
|
+
},
|
|
1436
|
+
root: {
|
|
1437
|
+
":data-open"() {
|
|
1438
|
+
return String(this.open);
|
|
1439
|
+
},
|
|
1440
|
+
"@click.document"(event) {
|
|
1441
|
+
if (this.open && !this.$el.contains(event.target)) this.open = false;
|
|
1442
|
+
},
|
|
1443
|
+
},
|
|
1444
|
+
input: {
|
|
1445
|
+
role: "combobox",
|
|
1446
|
+
autocomplete: "off",
|
|
1447
|
+
"aria-autocomplete": "list",
|
|
1448
|
+
":aria-expanded"() {
|
|
1449
|
+
return String(this.open);
|
|
1450
|
+
},
|
|
1451
|
+
":aria-activedescendant"() {
|
|
1452
|
+
return this.open && this.active ? this.active : null;
|
|
1453
|
+
},
|
|
1454
|
+
":value"() {
|
|
1455
|
+
return this.value;
|
|
1456
|
+
},
|
|
1457
|
+
"@input"(event) {
|
|
1458
|
+
this.value = event.target.value;
|
|
1459
|
+
this.open = true;
|
|
1460
|
+
this.active = "";
|
|
1461
|
+
},
|
|
1462
|
+
"@keydown"(event) {
|
|
1463
|
+
if (event.isComposing) return;
|
|
1464
|
+
const close = () => {
|
|
1465
|
+
event.preventDefault();
|
|
1466
|
+
this.open = false;
|
|
1467
|
+
this.active = "";
|
|
1468
|
+
};
|
|
1469
|
+
const options = this.visible().filter(
|
|
1470
|
+
(o) => o.getAttribute("aria-disabled") !== "true",
|
|
1471
|
+
);
|
|
1472
|
+
if (event.key === "Escape") {
|
|
1473
|
+
if (this.open) close();
|
|
1474
|
+
return;
|
|
1475
|
+
}
|
|
1476
|
+
if (event.key === "Enter") {
|
|
1477
|
+
const el = options.find((o) => o.id === this.active);
|
|
1478
|
+
if (this.open && el) {
|
|
1479
|
+
event.preventDefault();
|
|
1480
|
+
this.choose(el);
|
|
1481
|
+
}
|
|
1482
|
+
return;
|
|
1483
|
+
}
|
|
1484
|
+
if (event.altKey && event.key === "ArrowUp") {
|
|
1485
|
+
if (this.open) close();
|
|
1486
|
+
return;
|
|
1487
|
+
}
|
|
1488
|
+
if (event.altKey && event.key === "ArrowDown") {
|
|
1489
|
+
if (this.open || !options.length) return;
|
|
1490
|
+
event.preventDefault();
|
|
1491
|
+
this.open = true;
|
|
1492
|
+
return;
|
|
1493
|
+
}
|
|
1494
|
+
const arrow = event.key === "ArrowDown" || event.key === "ArrowUp";
|
|
1495
|
+
const jump = this.open && (event.key === "Home" || event.key === "End");
|
|
1496
|
+
if ((!arrow && !jump) || !options.length) return;
|
|
1497
|
+
event.preventDefault();
|
|
1498
|
+
const target = !this.open
|
|
1499
|
+
? options[event.key === "ArrowDown" ? 0 : options.length - 1]
|
|
1500
|
+
: menuTarget(
|
|
1501
|
+
event.key,
|
|
1502
|
+
options,
|
|
1503
|
+
options.findIndex((o) => o.id === this.active),
|
|
1504
|
+
false,
|
|
1505
|
+
);
|
|
1506
|
+
this.open = true;
|
|
1507
|
+
this.active = target.id;
|
|
1508
|
+
target.scrollIntoView?.({ block: "nearest" });
|
|
1509
|
+
},
|
|
1510
|
+
"@blur"() {
|
|
1511
|
+
this.open = false;
|
|
1512
|
+
this.active = "";
|
|
1513
|
+
},
|
|
1514
|
+
},
|
|
1515
|
+
listbox: {
|
|
1516
|
+
role: "listbox",
|
|
1517
|
+
...manualPopover((o) => o.open),
|
|
1518
|
+
},
|
|
1519
|
+
option(id) {
|
|
1520
|
+
return {
|
|
1521
|
+
role: "option",
|
|
1522
|
+
id,
|
|
1523
|
+
":hidden"() {
|
|
1524
|
+
return !this.matches(this.$el);
|
|
1525
|
+
},
|
|
1526
|
+
":aria-selected"() {
|
|
1527
|
+
return String(this.active === id);
|
|
1528
|
+
},
|
|
1529
|
+
":data-active"() {
|
|
1530
|
+
return String(this.active === id);
|
|
1531
|
+
},
|
|
1532
|
+
"@mousedown.prevent"() {},
|
|
1533
|
+
"@click"() {
|
|
1534
|
+
this.choose(this.$el);
|
|
1535
|
+
},
|
|
1536
|
+
};
|
|
1537
|
+
},
|
|
1538
|
+
}));
|
|
1539
|
+
|
|
1540
|
+
// Command: a role="search" palette. A search input filters the role="option"
|
|
1541
|
+
// results (case-insensitive substring); arrows move the active result
|
|
1542
|
+
// (aria-activedescendant, wrapping) and Enter activates it with a click.
|
|
1543
|
+
Alpine.data("lilyCommand", (value = "") => ({
|
|
1544
|
+
value,
|
|
1545
|
+
active: "",
|
|
1546
|
+
visible() {
|
|
1547
|
+
return Array.from(this.$root.querySelectorAll('[role="option"]')).filter(
|
|
1548
|
+
(o) => !o.hidden,
|
|
1549
|
+
);
|
|
1550
|
+
},
|
|
1551
|
+
matches(el) {
|
|
1552
|
+
return !this.value || el.textContent.toLowerCase().includes(this.value.toLowerCase());
|
|
1553
|
+
},
|
|
1554
|
+
input: {
|
|
1555
|
+
":aria-activedescendant"() {
|
|
1556
|
+
return this.active || null;
|
|
1557
|
+
},
|
|
1558
|
+
":value"() {
|
|
1559
|
+
return this.value;
|
|
1560
|
+
},
|
|
1561
|
+
"@input"(event) {
|
|
1562
|
+
this.value = event.target.value;
|
|
1563
|
+
this.active = "";
|
|
1564
|
+
},
|
|
1565
|
+
"@keydown"(event) {
|
|
1566
|
+
if (event.isComposing) return;
|
|
1567
|
+
const options = this.visible().filter(
|
|
1568
|
+
(o) => o.getAttribute("aria-disabled") !== "true",
|
|
1569
|
+
);
|
|
1570
|
+
if (!options.length) return;
|
|
1571
|
+
const index = options.findIndex((o) => o.id === this.active);
|
|
1572
|
+
const arrow = event.key === "ArrowDown" || event.key === "ArrowUp";
|
|
1573
|
+
if (arrow || (index >= 0 && (event.key === "Home" || event.key === "End"))) {
|
|
1574
|
+
event.preventDefault();
|
|
1575
|
+
const target = menuTarget(event.key, options, index, false);
|
|
1576
|
+
this.active = target.id;
|
|
1577
|
+
target.scrollIntoView?.({ block: "nearest" });
|
|
1578
|
+
} else if (index >= 0 && event.key === "Enter") {
|
|
1579
|
+
event.preventDefault();
|
|
1580
|
+
options[index].click();
|
|
1581
|
+
} else if (index >= 0 && event.key === "Escape") {
|
|
1582
|
+
event.preventDefault();
|
|
1583
|
+
this.active = "";
|
|
1584
|
+
}
|
|
1585
|
+
},
|
|
1586
|
+
},
|
|
1587
|
+
option(id) {
|
|
1588
|
+
return {
|
|
1589
|
+
role: "option",
|
|
1590
|
+
id,
|
|
1591
|
+
":hidden"() {
|
|
1592
|
+
return !this.matches(this.$el);
|
|
1593
|
+
},
|
|
1594
|
+
":aria-selected"() {
|
|
1595
|
+
return String(this.active === id);
|
|
1596
|
+
},
|
|
1597
|
+
":data-active"() {
|
|
1598
|
+
return String(this.active === id);
|
|
1599
|
+
},
|
|
1600
|
+
};
|
|
1601
|
+
},
|
|
1602
|
+
}));
|
|
1603
|
+
|
|
1604
|
+
// Tree (tree-nav, tree-menu, file-tree): a role="tree" with roving tabindex
|
|
1605
|
+
// and the APG keys. `wrap` makes the arrows wrap (tree-menu); the others stop
|
|
1606
|
+
// at the ends.
|
|
1607
|
+
Alpine.data("lilyTree", (wrap = false, expanded = []) => ({
|
|
1608
|
+
...treeCore({ wrap, expanded }),
|
|
1609
|
+
}));
|
|
1610
|
+
|
|
1611
|
+
// TreeSelect / Cascader: a role="combobox" trigger and a panel
|
|
1612
|
+
// with a tree. Opening moves focus into the tree; Escape returns it to the
|
|
1613
|
+
// trigger; choosing a leaf sets the selection and (single mode) closes.
|
|
1614
|
+
// `exclusive` opens one branch per level, which is the cascader.
|
|
1615
|
+
let treePopupCount = 0;
|
|
1616
|
+
const popupTree = (name, exclusive) =>
|
|
1617
|
+
Alpine.data(name, (multiple = false, expanded = []) => ({
|
|
1618
|
+
...treeCore({ exclusive, expanded }),
|
|
1619
|
+
multiple,
|
|
1620
|
+
open: false,
|
|
1621
|
+
popupId: `tree-popup-${++treePopupCount}`,
|
|
1622
|
+
init() {
|
|
1623
|
+
this.$watch("open", (value) => {
|
|
1624
|
+
if (value)
|
|
1625
|
+
this.$nextTick(() =>
|
|
1626
|
+
this.focusItem(
|
|
1627
|
+
this.itemFor(this.selected[0]) ?? this.visibleItems()[0],
|
|
1628
|
+
),
|
|
1629
|
+
);
|
|
1630
|
+
});
|
|
1631
|
+
},
|
|
1632
|
+
choose(id) {
|
|
1633
|
+
if (this.multiple) {
|
|
1634
|
+
this.selected = this.selected.includes(id)
|
|
1635
|
+
? this.selected.filter((s) => s !== id)
|
|
1636
|
+
: [...this.selected, id];
|
|
1637
|
+
} else {
|
|
1638
|
+
this.selected = [id];
|
|
1639
|
+
this.open = false;
|
|
1640
|
+
this.$refs.trigger?.focus();
|
|
1641
|
+
}
|
|
1642
|
+
this.$dispatch("lily:select", {
|
|
1643
|
+
selected: [...this.selected],
|
|
1644
|
+
path: this.pathOf(id),
|
|
1645
|
+
});
|
|
1646
|
+
},
|
|
1647
|
+
root: {
|
|
1648
|
+
":data-multiple"() {
|
|
1649
|
+
return this.multiple ? "true" : null;
|
|
1650
|
+
},
|
|
1651
|
+
"@keydown.escape"() {
|
|
1652
|
+
if (!this.open) return;
|
|
1653
|
+
this.open = false;
|
|
1654
|
+
this.$refs.trigger?.focus();
|
|
1655
|
+
},
|
|
1656
|
+
"@click.document"(event) {
|
|
1657
|
+
if (this.open && !this.$el.contains(event.target)) this.open = false;
|
|
1658
|
+
},
|
|
1659
|
+
},
|
|
1660
|
+
trigger: {
|
|
1661
|
+
type: "button",
|
|
1662
|
+
role: "combobox",
|
|
1663
|
+
"aria-haspopup": "tree",
|
|
1664
|
+
"x-ref": "trigger",
|
|
1665
|
+
":aria-expanded"() {
|
|
1666
|
+
return String(this.open);
|
|
1667
|
+
},
|
|
1668
|
+
":aria-controls"() {
|
|
1669
|
+
return this.popupId;
|
|
1670
|
+
},
|
|
1671
|
+
"@click"() {
|
|
1672
|
+
this.open = !this.open;
|
|
1673
|
+
},
|
|
1674
|
+
"@keydown.arrow-down.prevent"() {
|
|
1675
|
+
this.open = true;
|
|
1676
|
+
},
|
|
1677
|
+
},
|
|
1678
|
+
panel: {
|
|
1679
|
+
...manualPopover((o) => o.open),
|
|
1680
|
+
":id"() {
|
|
1681
|
+
return this.popupId;
|
|
1682
|
+
},
|
|
1683
|
+
},
|
|
1684
|
+
// aria-multiselectable is valid on the tree, not on the combobox root.
|
|
1685
|
+
tree: {
|
|
1686
|
+
"@keydown"(event) {
|
|
1687
|
+
this.treeKey(event);
|
|
1688
|
+
},
|
|
1689
|
+
":aria-multiselectable"() {
|
|
1690
|
+
return this.multiple ? "true" : null;
|
|
1691
|
+
},
|
|
1692
|
+
},
|
|
1693
|
+
}));
|
|
1694
|
+
popupTree("lilyTreeSelect", false);
|
|
1695
|
+
popupTree("lilyCascader", true);
|
|
1696
|
+
|
|
1697
|
+
// CharacterCounter: a polite status "count / max" (or just count). Give it
|
|
1698
|
+
// `forId` to follow a field by id; otherwise set `count` yourself. Exposes
|
|
1699
|
+
// data-count, data-max, data-remaining and (only when over) data-over-limit.
|
|
1700
|
+
// A counter's root carries the data attributes; inside it the visible count is aria-hidden, and a visually hidden
|
|
1701
|
+
// role="status" takes the same text once the count has stopped changing for announceDelay ms, so a run of keystrokes
|
|
1702
|
+
// is announced once, as GOV.UK's character count does (spec/detent-lessons, P26-T9).
|
|
1703
|
+
const counterText = function () {
|
|
1704
|
+
return this.max == null ? String(this.count) : `${this.count} / ${this.max}`;
|
|
1705
|
+
};
|
|
1706
|
+
const announceCount = function () {
|
|
1707
|
+
this.announced = this.counterText;
|
|
1708
|
+
this.$watch("counterText", (next) => {
|
|
1709
|
+
clearTimeout(this._announceTimer);
|
|
1710
|
+
this._announceTimer = setTimeout(() => (this.announced = next), this.announceDelay);
|
|
1711
|
+
});
|
|
1712
|
+
};
|
|
1713
|
+
const counterShownBind = {
|
|
1714
|
+
"aria-hidden": "true",
|
|
1715
|
+
"x-text"() {
|
|
1716
|
+
return this.counterText;
|
|
1717
|
+
},
|
|
1718
|
+
};
|
|
1719
|
+
const counterStatusBind = {
|
|
1720
|
+
role: "status",
|
|
1721
|
+
"x-text"() {
|
|
1722
|
+
return this.announced;
|
|
1723
|
+
},
|
|
1724
|
+
};
|
|
1725
|
+
const counterBind = {
|
|
1726
|
+
":data-count"() {
|
|
1727
|
+
return String(this.count);
|
|
1728
|
+
},
|
|
1729
|
+
":data-max"() {
|
|
1730
|
+
return this.max == null ? null : String(this.max);
|
|
1731
|
+
},
|
|
1732
|
+
":data-remaining"() {
|
|
1733
|
+
return this.max == null ? null : String(this.max - this.count);
|
|
1734
|
+
},
|
|
1735
|
+
":data-over-limit"() {
|
|
1736
|
+
return this.max != null && this.count > this.max ? "" : null;
|
|
1737
|
+
},
|
|
1738
|
+
};
|
|
1739
|
+
|
|
1740
|
+
Alpine.data("lilyCharacterCounter", (max = null, forId = "", announceDelay = 1000) => ({
|
|
1741
|
+
count: 0,
|
|
1742
|
+
max,
|
|
1743
|
+
announceDelay,
|
|
1744
|
+
announced: "",
|
|
1745
|
+
get counterText() {
|
|
1746
|
+
return counterText.call(this);
|
|
1747
|
+
},
|
|
1748
|
+
destroy() {
|
|
1749
|
+
clearTimeout(this._announceTimer);
|
|
1750
|
+
},
|
|
1751
|
+
init() {
|
|
1752
|
+
const field = forId && document.getElementById(forId);
|
|
1753
|
+
if (field) this.count = field.value.length;
|
|
1754
|
+
announceCount.call(this);
|
|
1755
|
+
if (!field) return;
|
|
1756
|
+
field.addEventListener("input", () => {
|
|
1757
|
+
this.count = field.value.length;
|
|
1758
|
+
});
|
|
1759
|
+
},
|
|
1760
|
+
counter: counterBind,
|
|
1761
|
+
counterShown: counterShownBind,
|
|
1762
|
+
counterStatus: counterStatusBind,
|
|
1763
|
+
}));
|
|
1764
|
+
|
|
1765
|
+
// A textarea with its own counter, linked by aria-describedby.
|
|
1766
|
+
Alpine.data("lilyCountedTextarea", (max = null, value = "", announceDelay = 1000) => ({
|
|
1767
|
+
value,
|
|
1768
|
+
max,
|
|
1769
|
+
announceDelay,
|
|
1770
|
+
announced: "",
|
|
1771
|
+
get count() {
|
|
1772
|
+
return this.value.length;
|
|
1773
|
+
},
|
|
1774
|
+
get counterText() {
|
|
1775
|
+
return counterText.call(this);
|
|
1776
|
+
},
|
|
1777
|
+
init() {
|
|
1778
|
+
announceCount.call(this);
|
|
1779
|
+
},
|
|
1780
|
+
destroy() {
|
|
1781
|
+
clearTimeout(this._announceTimer);
|
|
1782
|
+
},
|
|
1783
|
+
textarea: {
|
|
1784
|
+
":value"() {
|
|
1785
|
+
return this.value;
|
|
1786
|
+
},
|
|
1787
|
+
"@input"(event) {
|
|
1788
|
+
this.value = event.target.value;
|
|
1789
|
+
},
|
|
1790
|
+
":aria-invalid"() {
|
|
1791
|
+
return this.max != null && this.count > this.max ? "true" : null;
|
|
1792
|
+
},
|
|
1793
|
+
},
|
|
1794
|
+
counter: counterBind,
|
|
1795
|
+
counterShown: counterShownBind,
|
|
1796
|
+
counterStatus: counterStatusBind,
|
|
1797
|
+
}));
|
|
1798
|
+
|
|
1799
|
+
// Password field with a show / hide toggle button (aria-pressed).
|
|
1800
|
+
Alpine.data("lilyPasswordToggle", (visible = false) => ({
|
|
1801
|
+
visible,
|
|
1802
|
+
input: {
|
|
1803
|
+
":type"() {
|
|
1804
|
+
return this.visible ? "text" : "password";
|
|
1805
|
+
},
|
|
1806
|
+
autocomplete: "current-password",
|
|
1807
|
+
spellcheck: "false",
|
|
1808
|
+
},
|
|
1809
|
+
toggle: {
|
|
1810
|
+
type: "button",
|
|
1811
|
+
":aria-pressed"() {
|
|
1812
|
+
return String(this.visible);
|
|
1813
|
+
},
|
|
1814
|
+
"@click"() {
|
|
1815
|
+
this.visible = !this.visible;
|
|
1816
|
+
},
|
|
1817
|
+
},
|
|
1818
|
+
}));
|
|
1819
|
+
|
|
1820
|
+
// PinInput: one digit per input. A digit moves focus on, Backspace on an empty
|
|
1821
|
+
// box moves back, arrows move, and a paste fills the boxes from the focused
|
|
1822
|
+
// one. Non-digits are dropped. `lily:complete` fires when every box is filled.
|
|
1823
|
+
Alpine.data("lilyPinInput", () => ({
|
|
1824
|
+
boxes() {
|
|
1825
|
+
return Array.from(this.$root.querySelectorAll("input"));
|
|
1826
|
+
},
|
|
1827
|
+
get value() {
|
|
1828
|
+
return this.boxes()
|
|
1829
|
+
.map((b) => b.value)
|
|
1830
|
+
.join("");
|
|
1831
|
+
},
|
|
1832
|
+
sync() {
|
|
1833
|
+
const value = this.value;
|
|
1834
|
+
this.$root.dataset.value = value;
|
|
1835
|
+
if (value.length === this.boxes().length) this.$dispatch("lily:complete", { value });
|
|
1836
|
+
},
|
|
1837
|
+
fill(boxes, from, digits) {
|
|
1838
|
+
digits.split("").forEach((d, k) => {
|
|
1839
|
+
if (boxes[from + k]) boxes[from + k].value = d;
|
|
1840
|
+
});
|
|
1841
|
+
boxes[Math.min(from + digits.length, boxes.length - 1)]?.focus();
|
|
1842
|
+
this.sync();
|
|
1843
|
+
},
|
|
1844
|
+
digit(i) {
|
|
1845
|
+
return {
|
|
1846
|
+
type: "text",
|
|
1847
|
+
inputmode: "numeric",
|
|
1848
|
+
maxlength: "1",
|
|
1849
|
+
autocomplete: "off",
|
|
1850
|
+
"@input"(event) {
|
|
1851
|
+
const boxes = this.boxes();
|
|
1852
|
+
const digits = event.target.value.replace(/\D/g, "");
|
|
1853
|
+
event.target.value = "";
|
|
1854
|
+
if (digits) this.fill(boxes, i, digits);
|
|
1855
|
+
else this.sync();
|
|
1856
|
+
},
|
|
1857
|
+
"@paste"(event) {
|
|
1858
|
+
event.preventDefault();
|
|
1859
|
+
this.fill(
|
|
1860
|
+
this.boxes(),
|
|
1861
|
+
i,
|
|
1862
|
+
(event.clipboardData?.getData("text") ?? "").replace(/\D/g, ""),
|
|
1863
|
+
);
|
|
1864
|
+
},
|
|
1865
|
+
"@keydown"(event) {
|
|
1866
|
+
const boxes = this.boxes();
|
|
1867
|
+
if (event.key === "Backspace" && !event.target.value && i > 0) {
|
|
1868
|
+
event.preventDefault();
|
|
1869
|
+
boxes[i - 1].value = "";
|
|
1870
|
+
boxes[i - 1].focus();
|
|
1871
|
+
this.sync();
|
|
1872
|
+
} else if (event.key === "ArrowLeft" && i > 0) {
|
|
1873
|
+
event.preventDefault();
|
|
1874
|
+
boxes[i - 1].focus();
|
|
1875
|
+
} else if (event.key === "ArrowRight" && i < boxes.length - 1) {
|
|
1876
|
+
event.preventDefault();
|
|
1877
|
+
boxes[i + 1].focus();
|
|
1878
|
+
}
|
|
1879
|
+
},
|
|
1880
|
+
};
|
|
1881
|
+
},
|
|
1882
|
+
}));
|
|
1883
|
+
|
|
1884
|
+
// TagInputDiv: Enter adds the trimmed text as a tag (duplicates ignored) and
|
|
1885
|
+
// clears the field; Backspace on an empty field removes the last tag.
|
|
1886
|
+
Alpine.data("lilyTagInputDiv", (tags = []) => ({
|
|
1887
|
+
tags: [...tags],
|
|
1888
|
+
add(text) {
|
|
1889
|
+
const tag = text.trim();
|
|
1890
|
+
if (!tag || this.tags.includes(tag)) return false;
|
|
1891
|
+
this.tags = [...this.tags, tag];
|
|
1892
|
+
this.$dispatch("lily:add", { value: tag, tags: [...this.tags] });
|
|
1893
|
+
return true;
|
|
1894
|
+
},
|
|
1895
|
+
remove(tag) {
|
|
1896
|
+
this.tags = this.tags.filter((t) => t !== tag);
|
|
1897
|
+
this.$dispatch("lily:remove", { value: tag, tags: [...this.tags] });
|
|
1898
|
+
},
|
|
1899
|
+
input: {
|
|
1900
|
+
type: "text",
|
|
1901
|
+
"@keydown"(event) {
|
|
1902
|
+
if (event.key === "Enter" && this.$el.value.trim()) {
|
|
1903
|
+
event.preventDefault();
|
|
1904
|
+
this.add(this.$el.value);
|
|
1905
|
+
this.$el.value = "";
|
|
1906
|
+
} else if (event.key === "Backspace" && !this.$el.value && this.tags.length) {
|
|
1907
|
+
this.remove(this.tags[this.tags.length - 1]);
|
|
1908
|
+
}
|
|
1909
|
+
},
|
|
1910
|
+
},
|
|
1911
|
+
}));
|
|
1912
|
+
|
|
1913
|
+
// CurrencyInput: a decimal text field that keeps only digits and one ".",
|
|
1914
|
+
// carries data-currency-code, and flags aria-invalid outside min / max.
|
|
1915
|
+
// Formatting (Intl.NumberFormat, locale) stays the consumer's.
|
|
1916
|
+
Alpine.data("lilyCurrencyInput", (currencyCode, min = null, max = null) => ({
|
|
1917
|
+
input: {
|
|
1918
|
+
type: "text",
|
|
1919
|
+
inputmode: "decimal",
|
|
1920
|
+
":data-currency-code"() {
|
|
1921
|
+
return currencyCode ?? null;
|
|
1922
|
+
},
|
|
1923
|
+
"@input"() {
|
|
1924
|
+
const [whole, ...rest] = this.$el.value.replace(/[^\d.]/g, "").split(".");
|
|
1925
|
+
this.$el.value = rest.length ? `${whole}.${rest.join("")}` : whole;
|
|
1926
|
+
const n = Number(this.$el.value);
|
|
1927
|
+
const bad =
|
|
1928
|
+
this.$el.value !== "" && ((min != null && n < min) || (max != null && n > max));
|
|
1929
|
+
if (bad) this.$el.setAttribute("aria-invalid", "true");
|
|
1930
|
+
else this.$el.removeAttribute("aria-invalid");
|
|
1931
|
+
},
|
|
1932
|
+
},
|
|
1933
|
+
}));
|
|
1934
|
+
|
|
1935
|
+
// TextInputWithSearch: Enter in the field or the button emits `lily:search`.
|
|
1936
|
+
Alpine.data("lilySearch", (value = "") => ({
|
|
1937
|
+
value,
|
|
1938
|
+
search() {
|
|
1939
|
+
this.$dispatch("lily:search", { value: this.value });
|
|
1940
|
+
},
|
|
1941
|
+
input: {
|
|
1942
|
+
type: "text",
|
|
1943
|
+
":value"() {
|
|
1944
|
+
return this.value;
|
|
1945
|
+
},
|
|
1946
|
+
"@input"(event) {
|
|
1947
|
+
this.value = event.target.value;
|
|
1948
|
+
},
|
|
1949
|
+
"@keydown.enter.prevent"() {
|
|
1950
|
+
this.search();
|
|
1951
|
+
},
|
|
1952
|
+
},
|
|
1953
|
+
button: {
|
|
1954
|
+
type: "button",
|
|
1955
|
+
"@click"() {
|
|
1956
|
+
this.search();
|
|
1957
|
+
},
|
|
1958
|
+
},
|
|
1959
|
+
}));
|
|
1960
|
+
|
|
1961
|
+
// MentionsInput: typing the trigger character opens suggestions filtered by
|
|
1962
|
+
// the text after it. Arrows move the active option (aria-activedescendant),
|
|
1963
|
+
// Enter replaces "@query" with the chosen option, Escape closes.
|
|
1964
|
+
Alpine.data("lilyMentions", (trigger = "@") => ({
|
|
1965
|
+
open: false,
|
|
1966
|
+
active: "",
|
|
1967
|
+
query: "",
|
|
1968
|
+
visible() {
|
|
1969
|
+
return Array.from(this.$root.querySelectorAll('[role="option"]')).filter(
|
|
1970
|
+
(o) => !o.hidden,
|
|
1971
|
+
);
|
|
1972
|
+
},
|
|
1973
|
+
match(el) {
|
|
1974
|
+
return el.textContent.toLowerCase().includes(this.query.toLowerCase());
|
|
1975
|
+
},
|
|
1976
|
+
scan(value) {
|
|
1977
|
+
const at = value.lastIndexOf(trigger);
|
|
1978
|
+
const tail = at < 0 ? null : value.slice(at + trigger.length);
|
|
1979
|
+
// An email address does not open it; text written without spaces does.
|
|
1980
|
+
const glued = at > 0 && /[A-Za-z0-9._-]$/.test(value.slice(0, at));
|
|
1981
|
+
this.open = tail !== null && !/\s/.test(tail) && !glued;
|
|
1982
|
+
this.query = this.open ? tail : "";
|
|
1983
|
+
this.active = "";
|
|
1984
|
+
},
|
|
1985
|
+
choose(el) {
|
|
1986
|
+
const input = this.$refs.input;
|
|
1987
|
+
const at = input.value.lastIndexOf(trigger);
|
|
1988
|
+
input.value = `${input.value.slice(0, at)}${trigger}${el.textContent.trim()} `;
|
|
1989
|
+
this.open = false;
|
|
1990
|
+
this.active = "";
|
|
1991
|
+
input.focus();
|
|
1992
|
+
this.$dispatch("lily:select", { value: el.textContent.trim() });
|
|
1993
|
+
},
|
|
1994
|
+
input: {
|
|
1995
|
+
"x-ref": "input",
|
|
1996
|
+
role: "combobox",
|
|
1997
|
+
"aria-haspopup": "listbox",
|
|
1998
|
+
"aria-autocomplete": "list",
|
|
1999
|
+
":aria-expanded"() {
|
|
2000
|
+
return String(this.open);
|
|
2001
|
+
},
|
|
2002
|
+
":aria-activedescendant"() {
|
|
2003
|
+
return this.open && this.active ? this.active : null;
|
|
2004
|
+
},
|
|
2005
|
+
"@input"(event) {
|
|
2006
|
+
this.scan(event.target.value);
|
|
2007
|
+
},
|
|
2008
|
+
"@keydown"(event) {
|
|
2009
|
+
if (event.isComposing || !this.open) return;
|
|
2010
|
+
if (event.key === "Escape") {
|
|
2011
|
+
event.preventDefault();
|
|
2012
|
+
this.open = false;
|
|
2013
|
+
this.active = "";
|
|
2014
|
+
return;
|
|
2015
|
+
}
|
|
2016
|
+
if (event.key === "Enter") {
|
|
2017
|
+
const el = this.visible().find((o) => o.id === this.active);
|
|
2018
|
+
if (el) {
|
|
2019
|
+
event.preventDefault();
|
|
2020
|
+
this.choose(el);
|
|
2021
|
+
}
|
|
2022
|
+
return;
|
|
2023
|
+
}
|
|
2024
|
+
if (event.key !== "ArrowDown" && event.key !== "ArrowUp") return;
|
|
2025
|
+
event.preventDefault();
|
|
2026
|
+
const options = this.visible();
|
|
2027
|
+
if (!options.length) return;
|
|
2028
|
+
this.active = menuTarget(
|
|
2029
|
+
event.key,
|
|
2030
|
+
options,
|
|
2031
|
+
options.findIndex((o) => o.id === this.active),
|
|
2032
|
+
false,
|
|
2033
|
+
).id;
|
|
2034
|
+
},
|
|
2035
|
+
},
|
|
2036
|
+
panel: {
|
|
2037
|
+
...manualPopover((o) => o.open),
|
|
2038
|
+
},
|
|
2039
|
+
option(id) {
|
|
2040
|
+
return {
|
|
2041
|
+
role: "option",
|
|
2042
|
+
id,
|
|
2043
|
+
":hidden"() {
|
|
2044
|
+
return !this.match(this.$el);
|
|
2045
|
+
},
|
|
2046
|
+
":aria-selected"() {
|
|
2047
|
+
return String(this.active === id);
|
|
2048
|
+
},
|
|
2049
|
+
"@mousedown.prevent"() {},
|
|
2050
|
+
"@click"() {
|
|
2051
|
+
this.choose(this.$el);
|
|
2052
|
+
},
|
|
2053
|
+
};
|
|
2054
|
+
},
|
|
2055
|
+
}));
|
|
2056
|
+
|
|
2057
|
+
// Editable: a button-like display that swaps for a text field. Enter,
|
|
2058
|
+
// Space or a click edits; Enter confirms; Escape cancels. The display's
|
|
2059
|
+
// accessible name is "value, label" so the visible text is in the name.
|
|
2060
|
+
Alpine.data("lilyEditable", (value = "", editing = false, label = "", disabled = false) => ({
|
|
2061
|
+
value,
|
|
2062
|
+
draft: value,
|
|
2063
|
+
editing,
|
|
2064
|
+
disabled,
|
|
2065
|
+
label,
|
|
2066
|
+
edit() {
|
|
2067
|
+
if (this.disabled) return;
|
|
2068
|
+
this.draft = this.value;
|
|
2069
|
+
this.editing = true;
|
|
2070
|
+
this.$nextTick(() => this.$refs.input?.focus());
|
|
2071
|
+
},
|
|
2072
|
+
confirm() {
|
|
2073
|
+
this.value = this.draft;
|
|
2074
|
+
this.editing = false;
|
|
2075
|
+
this.$dispatch("lily:change", { value: this.value });
|
|
2076
|
+
this.$nextTick(() => this.$refs.display?.focus());
|
|
2077
|
+
},
|
|
2078
|
+
cancel() {
|
|
2079
|
+
this.draft = this.value;
|
|
2080
|
+
this.editing = false;
|
|
2081
|
+
this.$nextTick(() => this.$refs.display?.focus());
|
|
2082
|
+
},
|
|
2083
|
+
// A native button: focusable, with Enter and Space, so it needs no role and no keys of its own.
|
|
2084
|
+
display: {
|
|
2085
|
+
type: "button",
|
|
2086
|
+
"x-ref": "display",
|
|
2087
|
+
":disabled"() {
|
|
2088
|
+
return this.disabled;
|
|
2089
|
+
},
|
|
2090
|
+
":aria-label"() {
|
|
2091
|
+
return this.value ? `${this.value}, ${this.label}` : this.label;
|
|
2092
|
+
},
|
|
2093
|
+
":hidden"() {
|
|
2094
|
+
return this.editing;
|
|
2095
|
+
},
|
|
2096
|
+
"x-text"() {
|
|
2097
|
+
return this.value;
|
|
2098
|
+
},
|
|
2099
|
+
"@click"() {
|
|
2100
|
+
this.edit();
|
|
2101
|
+
},
|
|
2102
|
+
},
|
|
2103
|
+
input: {
|
|
2104
|
+
type: "text",
|
|
2105
|
+
"x-ref": "input",
|
|
2106
|
+
":aria-label"() {
|
|
2107
|
+
return this.label;
|
|
2108
|
+
},
|
|
2109
|
+
":value"() {
|
|
2110
|
+
return this.draft;
|
|
2111
|
+
},
|
|
2112
|
+
":hidden"() {
|
|
2113
|
+
return !this.editing;
|
|
2114
|
+
},
|
|
2115
|
+
"@input"(event) {
|
|
2116
|
+
this.draft = event.target.value;
|
|
2117
|
+
},
|
|
2118
|
+
"@keydown.enter.prevent"() {
|
|
2119
|
+
this.confirm();
|
|
2120
|
+
},
|
|
2121
|
+
"@keydown.escape.prevent"() {
|
|
2122
|
+
this.cancel();
|
|
2123
|
+
},
|
|
2124
|
+
},
|
|
2125
|
+
}));
|
|
2126
|
+
|
|
2127
|
+
// EditableForm: a form shown only while editing. Submit saves (the consumer
|
|
2128
|
+
// handles `lily:submit`) and closes; Escape cancels and closes. The form is
|
|
2129
|
+
// tabindex -1 and takes focus when it opens.
|
|
2130
|
+
Alpine.data("lilyEditableForm", (editing = false) => ({
|
|
2131
|
+
editing,
|
|
2132
|
+
edit() {
|
|
2133
|
+
this.editing = true;
|
|
2134
|
+
this.$nextTick(() => this.$refs.form?.focus());
|
|
2135
|
+
},
|
|
2136
|
+
cancel() {
|
|
2137
|
+
this.editing = false;
|
|
2138
|
+
this.$dispatch("lily:cancel");
|
|
2139
|
+
},
|
|
2140
|
+
editButton: {
|
|
2141
|
+
type: "button",
|
|
2142
|
+
":hidden"() {
|
|
2143
|
+
return this.editing;
|
|
2144
|
+
},
|
|
2145
|
+
"@click"() {
|
|
2146
|
+
this.edit();
|
|
2147
|
+
},
|
|
2148
|
+
},
|
|
2149
|
+
form: {
|
|
2150
|
+
"x-ref": "form",
|
|
2151
|
+
tabindex: "-1",
|
|
2152
|
+
":hidden"() {
|
|
2153
|
+
return !this.editing;
|
|
2154
|
+
},
|
|
2155
|
+
"@submit.prevent"() {
|
|
2156
|
+
this.editing = false;
|
|
2157
|
+
this.$dispatch("lily:submit", {
|
|
2158
|
+
values: Object.fromEntries(new FormData(this.$el)),
|
|
2159
|
+
});
|
|
2160
|
+
},
|
|
2161
|
+
"@keydown.escape"() {
|
|
2162
|
+
this.cancel();
|
|
2163
|
+
},
|
|
2164
|
+
},
|
|
2165
|
+
}));
|
|
2166
|
+
|
|
2167
|
+
// DataFilterForm: a role="search" form that never navigates. Submit emits
|
|
2168
|
+
// `lily:filter` with the field values; reset emits `lily:reset`.
|
|
2169
|
+
Alpine.data("lilyDataFilterForm", () => ({
|
|
2170
|
+
form: {
|
|
2171
|
+
role: "search",
|
|
2172
|
+
"@submit.prevent"() {
|
|
2173
|
+
this.$dispatch("lily:filter", {
|
|
2174
|
+
values: Object.fromEntries(new FormData(this.$el)),
|
|
2175
|
+
});
|
|
2176
|
+
},
|
|
2177
|
+
"@reset"() {
|
|
2178
|
+
this.$dispatch("lily:reset");
|
|
2179
|
+
},
|
|
2180
|
+
},
|
|
2181
|
+
}));
|
|
2182
|
+
|
|
2183
|
+
// NewsletterSignup: a state machine (idle | submitting | success | error)
|
|
2184
|
+
// surfaced as data-state. While submitting the field and button are
|
|
2185
|
+
// disabled; success is a polite status, error an alert. Submit emits
|
|
2186
|
+
// `lily:submit` — the consumer moves `state` on.
|
|
2187
|
+
Alpine.data("lilyNewsletterSignup", (state = "idle") => ({
|
|
2188
|
+
state,
|
|
2189
|
+
form: {
|
|
2190
|
+
":data-state"() {
|
|
2191
|
+
return this.state;
|
|
2192
|
+
},
|
|
2193
|
+
"@submit.prevent"() {
|
|
2194
|
+
const email = this.$el.querySelector('input[type="email"]');
|
|
2195
|
+
this.$dispatch("lily:submit", { email: email?.value ?? "" });
|
|
2196
|
+
},
|
|
2197
|
+
},
|
|
2198
|
+
field: {
|
|
2199
|
+
":disabled"() {
|
|
2200
|
+
return this.state === "submitting";
|
|
2201
|
+
},
|
|
2202
|
+
},
|
|
2203
|
+
submit: {
|
|
2204
|
+
":disabled"() {
|
|
2205
|
+
return this.state === "submitting";
|
|
2206
|
+
},
|
|
2207
|
+
},
|
|
2208
|
+
success: {
|
|
2209
|
+
":hidden"() {
|
|
2210
|
+
return this.state !== "success";
|
|
2211
|
+
},
|
|
2212
|
+
},
|
|
2213
|
+
error: {
|
|
2214
|
+
":hidden"() {
|
|
2215
|
+
return this.state !== "error";
|
|
2216
|
+
},
|
|
2217
|
+
},
|
|
2218
|
+
}));
|
|
2219
|
+
|
|
2220
|
+
// DateTimeNowInput: date and time fields plus a button that fills both with
|
|
2221
|
+
// the current local date and time.
|
|
2222
|
+
Alpine.data("lilyDateTimeNow", () => ({
|
|
2223
|
+
date: "",
|
|
2224
|
+
time: "",
|
|
2225
|
+
now() {
|
|
2226
|
+
const d = new Date();
|
|
2227
|
+
const p = (n) => String(n).padStart(2, "0");
|
|
2228
|
+
this.date = `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())}`;
|
|
2229
|
+
this.time = `${p(d.getHours())}:${p(d.getMinutes())}`;
|
|
2230
|
+
this.$dispatch("lily:change", { date: this.date, time: this.time });
|
|
2231
|
+
},
|
|
2232
|
+
nowButton: {
|
|
2233
|
+
type: "button",
|
|
2234
|
+
"@click"() {
|
|
2235
|
+
this.now();
|
|
2236
|
+
},
|
|
2237
|
+
},
|
|
2238
|
+
}));
|
|
2239
|
+
|
|
2240
|
+
// Dial / slider keys (APG slider): Right/Up raise, Left/Down lower, Shift
|
|
2241
|
+
// moves ten steps, Home and End jump to the bounds.
|
|
2242
|
+
const sliderKey = (event, value, { min, max, step }) => {
|
|
2243
|
+
const big = event.shiftKey ? 10 : 1;
|
|
2244
|
+
let next = value;
|
|
2245
|
+
if (event.key === "ArrowRight" || event.key === "ArrowUp") next = value + step * big;
|
|
2246
|
+
else if (event.key === "ArrowLeft" || event.key === "ArrowDown") next = value - step * big;
|
|
2247
|
+
else if (event.key === "Home") next = min;
|
|
2248
|
+
else if (event.key === "End") next = max;
|
|
2249
|
+
else return null;
|
|
2250
|
+
return Math.min(max, Math.max(min, next));
|
|
2251
|
+
};
|
|
2252
|
+
|
|
2253
|
+
// Dial: a role="slider" div (there is no native dial). Focusable unless
|
|
2254
|
+
// disabled; aria-disabled only when disabled; data-value for CSS.
|
|
2255
|
+
Alpine.data("lilyDial", (value = 0, min = 0, max = 100, step = 1, disabled = false) => ({
|
|
2256
|
+
value: Math.min(max, Math.max(min, value)),
|
|
2257
|
+
min,
|
|
2258
|
+
max,
|
|
2259
|
+
step,
|
|
2260
|
+
disabled,
|
|
2261
|
+
dial: {
|
|
2262
|
+
role: "slider",
|
|
2263
|
+
":tabindex"() {
|
|
2264
|
+
return this.disabled ? "-1" : "0";
|
|
2265
|
+
},
|
|
2266
|
+
":aria-valuenow"() {
|
|
2267
|
+
return String(this.value);
|
|
2268
|
+
},
|
|
2269
|
+
":aria-valuemin"() {
|
|
2270
|
+
return String(this.min);
|
|
2271
|
+
},
|
|
2272
|
+
":aria-valuemax"() {
|
|
2273
|
+
return String(this.max);
|
|
2274
|
+
},
|
|
2275
|
+
":aria-disabled"() {
|
|
2276
|
+
return this.disabled ? "true" : null;
|
|
2277
|
+
},
|
|
2278
|
+
":data-value"() {
|
|
2279
|
+
return String(this.value);
|
|
2280
|
+
},
|
|
2281
|
+
"@keydown"(event) {
|
|
2282
|
+
if (this.disabled) return;
|
|
2283
|
+
const next = sliderKey(event, this.value, this);
|
|
2284
|
+
if (next === null) return;
|
|
2285
|
+
event.preventDefault();
|
|
2286
|
+
if (next === this.value) return;
|
|
2287
|
+
this.value = next;
|
|
2288
|
+
this.$dispatch("lily:change", { value: next });
|
|
2289
|
+
},
|
|
2290
|
+
},
|
|
2291
|
+
}));
|
|
2292
|
+
|
|
2293
|
+
// ScrollBar: a focusable role="scrollbar" div. Up/Left lower and
|
|
2294
|
+
// Down/Right raise by step, Page Up/Down by pageStep, Home/End jump to the
|
|
2295
|
+
// bounds. The consumer scrolls its content on lily:change and sets value
|
|
2296
|
+
// back as the content scrolls.
|
|
2297
|
+
Alpine.data("lilyScrollBar", (value = 0, min = 0, max = 100, step = 1, pageStep = 10) => ({
|
|
2298
|
+
value: Math.min(max, Math.max(min, value)),
|
|
2299
|
+
min,
|
|
2300
|
+
max,
|
|
2301
|
+
step,
|
|
2302
|
+
pageStep,
|
|
2303
|
+
bar: {
|
|
2304
|
+
role: "scrollbar",
|
|
2305
|
+
tabindex: "0",
|
|
2306
|
+
":aria-valuenow"() {
|
|
2307
|
+
return String(this.value);
|
|
2308
|
+
},
|
|
2309
|
+
":aria-valuemin"() {
|
|
2310
|
+
return String(this.min);
|
|
2311
|
+
},
|
|
2312
|
+
":aria-valuemax"() {
|
|
2313
|
+
return String(this.max);
|
|
2314
|
+
},
|
|
2315
|
+
"@keydown"(event) {
|
|
2316
|
+
const moves = {
|
|
2317
|
+
ArrowUp: this.value - this.step,
|
|
2318
|
+
ArrowLeft: this.value - this.step,
|
|
2319
|
+
ArrowDown: this.value + this.step,
|
|
2320
|
+
ArrowRight: this.value + this.step,
|
|
2321
|
+
PageUp: this.value - this.pageStep,
|
|
2322
|
+
PageDown: this.value + this.pageStep,
|
|
2323
|
+
Home: this.min,
|
|
2324
|
+
End: this.max,
|
|
2325
|
+
};
|
|
2326
|
+
if (!(event.key in moves)) return;
|
|
2327
|
+
event.preventDefault();
|
|
2328
|
+
const next = Math.min(this.max, Math.max(this.min, moves[event.key]));
|
|
2329
|
+
if (next === this.value) return;
|
|
2330
|
+
this.value = next;
|
|
2331
|
+
this.$dispatch("lily:change", { value: next });
|
|
2332
|
+
},
|
|
2333
|
+
},
|
|
2334
|
+
}));
|
|
2335
|
+
|
|
2336
|
+
// SliderButton: a slide-to-confirm <button role="slider">, position 0-100 in
|
|
2337
|
+
// aria-valuenow. ArrowRight/ArrowLeft move by `step`, Home returns to 0,
|
|
2338
|
+
// End/Enter/Space complete it; reaching 100 dispatches lily:confirm and
|
|
2339
|
+
// resets to 0. A disabled button ignores the keys.
|
|
2340
|
+
Alpine.data("lilySliderButton", (step = 10) => ({
|
|
2341
|
+
position: 0,
|
|
2342
|
+
step,
|
|
2343
|
+
button: {
|
|
2344
|
+
type: "button",
|
|
2345
|
+
role: "slider",
|
|
2346
|
+
"aria-valuemin": "0",
|
|
2347
|
+
"aria-valuemax": "100",
|
|
2348
|
+
":aria-valuenow"() {
|
|
2349
|
+
return String(this.position);
|
|
2350
|
+
},
|
|
2351
|
+
"@keydown"(event) {
|
|
2352
|
+
if (this.$el.disabled) return;
|
|
2353
|
+
const targets = {
|
|
2354
|
+
ArrowRight: this.position + this.step,
|
|
2355
|
+
ArrowLeft: this.position - this.step,
|
|
2356
|
+
Home: 0,
|
|
2357
|
+
End: 100,
|
|
2358
|
+
Enter: 100,
|
|
2359
|
+
" ": 100,
|
|
2360
|
+
};
|
|
2361
|
+
if (!(event.key in targets)) return;
|
|
2362
|
+
event.preventDefault();
|
|
2363
|
+
const next = targets[event.key];
|
|
2364
|
+
if (next >= 100) {
|
|
2365
|
+
this.position = 0;
|
|
2366
|
+
this.$dispatch("lily:confirm");
|
|
2367
|
+
} else {
|
|
2368
|
+
this.position = Math.max(0, next);
|
|
2369
|
+
}
|
|
2370
|
+
},
|
|
2371
|
+
},
|
|
2372
|
+
}));
|
|
2373
|
+
|
|
2374
|
+
// ToolBar: an APG toolbar. ArrowRight/ArrowLeft move focus among its
|
|
2375
|
+
// buttons and wrap, Home/End jump to the first and last; Tab enters and
|
|
2376
|
+
// leaves. Disabled buttons are skipped (they cannot take focus).
|
|
2377
|
+
Alpine.data("lilyToolBar", () => ({
|
|
2378
|
+
bar: {
|
|
2379
|
+
role: "toolbar",
|
|
2380
|
+
"@keydown"(event) {
|
|
2381
|
+
if (!["ArrowRight", "ArrowLeft", "Home", "End"].includes(event.key)) return;
|
|
2382
|
+
const items = Array.from(
|
|
2383
|
+
this.$el.querySelectorAll(
|
|
2384
|
+
"button:not([disabled]), [role='button'], [tabindex]:not([tabindex='-1'])",
|
|
2385
|
+
),
|
|
2386
|
+
);
|
|
2387
|
+
if (!items.length) return;
|
|
2388
|
+
event.preventDefault();
|
|
2389
|
+
const index = items.indexOf(document.activeElement);
|
|
2390
|
+
const last = items.length - 1;
|
|
2391
|
+
const next = {
|
|
2392
|
+
ArrowRight: index < last ? index + 1 : 0,
|
|
2393
|
+
ArrowLeft: index > 0 ? index - 1 : last,
|
|
2394
|
+
Home: 0,
|
|
2395
|
+
End: last,
|
|
2396
|
+
}[event.key];
|
|
2397
|
+
items[next].focus();
|
|
2398
|
+
},
|
|
2399
|
+
},
|
|
2400
|
+
}));
|
|
2401
|
+
|
|
2402
|
+
// TourList: an ordered list of tour steps, shown while `active`. Escape
|
|
2403
|
+
// inside it sets `active` to false and dispatches lily:close.
|
|
2404
|
+
Alpine.data("lilyTourList", (active = true) => ({
|
|
2405
|
+
active,
|
|
2406
|
+
list: {
|
|
2407
|
+
tabindex: "-1",
|
|
2408
|
+
":hidden"() {
|
|
2409
|
+
return !this.active;
|
|
2410
|
+
},
|
|
2411
|
+
"@keydown.escape"() {
|
|
2412
|
+
if (!this.active) return;
|
|
2413
|
+
this.active = false;
|
|
2414
|
+
this.$dispatch("lily:close");
|
|
2415
|
+
},
|
|
2416
|
+
},
|
|
2417
|
+
}));
|
|
2418
|
+
|
|
2419
|
+
// TileMap: the [data-tile] children are focusable tiles. ArrowRight/Left
|
|
2420
|
+
// step through them in order (stopping at the ends); ArrowDown/Up go to
|
|
2421
|
+
// the nearest tile in a lower or higher row, by position on screen;
|
|
2422
|
+
// Enter/Space dispatch a bubbling tile-activate on the focused tile;
|
|
2423
|
+
// Escape blurs it.
|
|
2424
|
+
Alpine.data("lilyTileMap", () => ({
|
|
2425
|
+
map: {
|
|
2426
|
+
"@keydown"(event) {
|
|
2427
|
+
const tiles = Array.from(this.$el.querySelectorAll("[data-tile]"));
|
|
2428
|
+
const focused = document.activeElement;
|
|
2429
|
+
const index = tiles.indexOf(focused);
|
|
2430
|
+
if (index === -1) return;
|
|
2431
|
+
const key = event.key;
|
|
2432
|
+
if (key === "ArrowRight" || key === "ArrowLeft") {
|
|
2433
|
+
event.preventDefault();
|
|
2434
|
+
const to = key === "ArrowRight" ? index + 1 : index - 1;
|
|
2435
|
+
tiles[Math.min(tiles.length - 1, Math.max(0, to))].focus();
|
|
2436
|
+
} else if (key === "ArrowDown" || key === "ArrowUp") {
|
|
2437
|
+
event.preventDefault();
|
|
2438
|
+
const here = focused.getBoundingClientRect();
|
|
2439
|
+
const x = here.left + here.width / 2;
|
|
2440
|
+
const below = key === "ArrowDown";
|
|
2441
|
+
const next = tiles
|
|
2442
|
+
.filter((t) => t !== focused)
|
|
2443
|
+
.map((t) => ({ t, r: t.getBoundingClientRect() }))
|
|
2444
|
+
.filter(({ r }) => (below ? r.top > here.top : r.top < here.top))
|
|
2445
|
+
.map(({ t, r }) => ({
|
|
2446
|
+
t,
|
|
2447
|
+
score: Math.abs(r.left + r.width / 2 - x) + Math.abs(r.top - here.top),
|
|
2448
|
+
}))
|
|
2449
|
+
.sort((a, b) => a.score - b.score)[0]?.t;
|
|
2450
|
+
next?.focus();
|
|
2451
|
+
} else if (key === "Enter" || key === " ") {
|
|
2452
|
+
event.preventDefault();
|
|
2453
|
+
focused.dispatchEvent(new CustomEvent("tile-activate", { bubbles: true }));
|
|
2454
|
+
} else if (key === "Escape") {
|
|
2455
|
+
event.preventDefault();
|
|
2456
|
+
focused.blur();
|
|
2457
|
+
}
|
|
2458
|
+
},
|
|
2459
|
+
},
|
|
2460
|
+
}));
|
|
2461
|
+
|
|
2462
|
+
// ColorPicker: a two-axis role="slider" over a 0–100 square. aria-valuenow
|
|
2463
|
+
// is x; data-x and data-y position the cursor. Up lowers y, Down raises it.
|
|
2464
|
+
Alpine.data("lilyColorPicker", (x = 0, y = 0, disabled = false) => ({
|
|
2465
|
+
x,
|
|
2466
|
+
y,
|
|
2467
|
+
disabled,
|
|
2468
|
+
area: {
|
|
2469
|
+
role: "slider",
|
|
2470
|
+
":tabindex"() {
|
|
2471
|
+
return this.disabled ? "-1" : "0";
|
|
2472
|
+
},
|
|
2473
|
+
"aria-valuemin": "0",
|
|
2474
|
+
"aria-valuemax": "100",
|
|
2475
|
+
":aria-valuenow"() {
|
|
2476
|
+
return String(this.x);
|
|
2477
|
+
},
|
|
2478
|
+
":aria-disabled"() {
|
|
2479
|
+
return this.disabled ? "true" : null;
|
|
2480
|
+
},
|
|
2481
|
+
":data-x"() {
|
|
2482
|
+
return String(this.x);
|
|
2483
|
+
},
|
|
2484
|
+
":data-y"() {
|
|
2485
|
+
return String(this.y);
|
|
2486
|
+
},
|
|
2487
|
+
"@keydown"(event) {
|
|
2488
|
+
if (this.disabled) return;
|
|
2489
|
+
const big = event.shiftKey ? 10 : 1;
|
|
2490
|
+
const clamp = (n) => Math.min(100, Math.max(0, n));
|
|
2491
|
+
const move = {
|
|
2492
|
+
ArrowRight: () => {
|
|
2493
|
+
this.x = clamp(this.x + big);
|
|
2494
|
+
},
|
|
2495
|
+
ArrowLeft: () => {
|
|
2496
|
+
this.x = clamp(this.x - big);
|
|
2497
|
+
},
|
|
2498
|
+
ArrowUp: () => {
|
|
2499
|
+
this.y = clamp(this.y - big);
|
|
2500
|
+
},
|
|
2501
|
+
ArrowDown: () => {
|
|
2502
|
+
this.y = clamp(this.y + big);
|
|
2503
|
+
},
|
|
2504
|
+
Home: () => {
|
|
2505
|
+
this.x = 0;
|
|
2506
|
+
},
|
|
2507
|
+
End: () => {
|
|
2508
|
+
this.x = 100;
|
|
2509
|
+
},
|
|
2510
|
+
}[event.key];
|
|
2511
|
+
if (!move) return;
|
|
2512
|
+
event.preventDefault();
|
|
2513
|
+
move();
|
|
2514
|
+
this.$dispatch("lily:change", { x: this.x, y: this.y });
|
|
2515
|
+
},
|
|
2516
|
+
},
|
|
2517
|
+
}));
|
|
2518
|
+
|
|
2519
|
+
// Splitter: a focusable role="separator" with a 0–100 position. The keys
|
|
2520
|
+
// that move it follow the orientation (Left/Right when the panes sit side by
|
|
2521
|
+
// side, Up/Down when stacked); Shift moves ten steps; Home/End jump to the
|
|
2522
|
+
// bounds. Dragging maps the pointer onto the separator's parent. The
|
|
2523
|
+
// position is also exposed as --splitter-position on the separator.
|
|
2524
|
+
Alpine.data(
|
|
2525
|
+
"lilySplitter",
|
|
2526
|
+
(value = 50, orientation = "vertical", min = 0, max = 100, step = 1) => ({
|
|
2527
|
+
value,
|
|
2528
|
+
orientation,
|
|
2529
|
+
min,
|
|
2530
|
+
max,
|
|
2531
|
+
step,
|
|
2532
|
+
set(next) {
|
|
2533
|
+
next = Math.min(this.max, Math.max(this.min, next));
|
|
2534
|
+
if (next === this.value) return;
|
|
2535
|
+
this.value = next;
|
|
2536
|
+
this.$dispatch("lily:change", { value: next });
|
|
2537
|
+
},
|
|
2538
|
+
separator: {
|
|
2539
|
+
role: "separator",
|
|
2540
|
+
tabindex: "0",
|
|
2541
|
+
":aria-orientation"() {
|
|
2542
|
+
return this.orientation;
|
|
2543
|
+
},
|
|
2544
|
+
":aria-valuenow"() {
|
|
2545
|
+
return String(this.value);
|
|
2546
|
+
},
|
|
2547
|
+
":aria-valuemin"() {
|
|
2548
|
+
return String(this.min);
|
|
2549
|
+
},
|
|
2550
|
+
":aria-valuemax"() {
|
|
2551
|
+
return String(this.max);
|
|
2552
|
+
},
|
|
2553
|
+
":data-value"() {
|
|
2554
|
+
return String(this.value);
|
|
2555
|
+
},
|
|
2556
|
+
":style"() {
|
|
2557
|
+
return { "--splitter-position": `${this.value}%` };
|
|
2558
|
+
},
|
|
2559
|
+
"@keydown"(event) {
|
|
2560
|
+
const sideBySide = this.orientation === "vertical";
|
|
2561
|
+
const keys = sideBySide
|
|
2562
|
+
? ["ArrowLeft", "ArrowRight"]
|
|
2563
|
+
: ["ArrowUp", "ArrowDown"];
|
|
2564
|
+
if (sideBySide && getComputedStyle(this.$el).direction === "rtl")
|
|
2565
|
+
keys.reverse();
|
|
2566
|
+
const big = event.shiftKey ? 10 : 1;
|
|
2567
|
+
if (event.key === keys[0]) this.set(this.value - this.step * big);
|
|
2568
|
+
else if (event.key === keys[1]) this.set(this.value + this.step * big);
|
|
2569
|
+
else if (event.key === "Home") this.set(this.min);
|
|
2570
|
+
else if (event.key === "End") this.set(this.max);
|
|
2571
|
+
else if (event.key === "Enter") {
|
|
2572
|
+
// Collapse to the minimum, and restore.
|
|
2573
|
+
if (this.value > this.min) {
|
|
2574
|
+
this.restore = this.value;
|
|
2575
|
+
this.set(this.min);
|
|
2576
|
+
} else this.set(this.restore ?? this.max);
|
|
2577
|
+
} else return;
|
|
2578
|
+
event.preventDefault();
|
|
2579
|
+
},
|
|
2580
|
+
"@pointerdown"(event) {
|
|
2581
|
+
const parent = this.$el.parentElement;
|
|
2582
|
+
const sideBySide = this.orientation === "vertical";
|
|
2583
|
+
const move = (e) => {
|
|
2584
|
+
const box = parent.getBoundingClientRect();
|
|
2585
|
+
const size = sideBySide ? box.width : box.height;
|
|
2586
|
+
if (!size) return;
|
|
2587
|
+
const at = sideBySide ? e.clientX - box.left : e.clientY - box.top;
|
|
2588
|
+
this.set(Math.round(this.min + (at / size) * (this.max - this.min)));
|
|
2589
|
+
};
|
|
2590
|
+
const stop = () => {
|
|
2591
|
+
document.removeEventListener("pointermove", move);
|
|
2592
|
+
document.removeEventListener("pointerup", stop);
|
|
2593
|
+
};
|
|
2594
|
+
event.preventDefault();
|
|
2595
|
+
document.addEventListener("pointermove", move);
|
|
2596
|
+
document.addEventListener("pointerup", stop);
|
|
2597
|
+
},
|
|
2598
|
+
},
|
|
2599
|
+
}),
|
|
2600
|
+
);
|
|
2601
|
+
|
|
2602
|
+
// Carousel: one slide shown at a time (the rest hidden), previous / next
|
|
2603
|
+
// buttons that wrap, and a numeric "n / m" slide label. It never advances
|
|
2604
|
+
// by itself.
|
|
2605
|
+
Alpine.data("lilyCarousel", (index = 0) => ({
|
|
2606
|
+
index,
|
|
2607
|
+
total: 0,
|
|
2608
|
+
init() {
|
|
2609
|
+
this.total = this.count();
|
|
2610
|
+
},
|
|
2611
|
+
count() {
|
|
2612
|
+
return boundCount(this.$root, "slide(");
|
|
2613
|
+
},
|
|
2614
|
+
go(to) {
|
|
2615
|
+
const count = this.count();
|
|
2616
|
+
if (!count) return;
|
|
2617
|
+
this.index = (to + count) % count;
|
|
2618
|
+
this.$dispatch("lily:change", { index: this.index });
|
|
2619
|
+
},
|
|
2620
|
+
root: {
|
|
2621
|
+
":data-index"() {
|
|
2622
|
+
return String(this.index);
|
|
2623
|
+
},
|
|
2624
|
+
},
|
|
2625
|
+
previous: {
|
|
2626
|
+
type: "button",
|
|
2627
|
+
"@click"() {
|
|
2628
|
+
this.go(this.index - 1);
|
|
2629
|
+
},
|
|
2630
|
+
},
|
|
2631
|
+
next: {
|
|
2632
|
+
type: "button",
|
|
2633
|
+
"@click"() {
|
|
2634
|
+
this.go(this.index + 1);
|
|
2635
|
+
},
|
|
2636
|
+
},
|
|
2637
|
+
slide(i) {
|
|
2638
|
+
return {
|
|
2639
|
+
role: "group",
|
|
2640
|
+
"aria-roledescription": "slide",
|
|
2641
|
+
":aria-label"() {
|
|
2642
|
+
return `${i + 1} / ${this.total}`;
|
|
2643
|
+
},
|
|
2644
|
+
":hidden"() {
|
|
2645
|
+
return this.index !== i;
|
|
2646
|
+
},
|
|
2647
|
+
":data-active"() {
|
|
2648
|
+
return String(this.index === i);
|
|
2649
|
+
},
|
|
2650
|
+
};
|
|
2651
|
+
},
|
|
2652
|
+
}));
|
|
2653
|
+
|
|
2654
|
+
// Tour: steps shown one at a time, the current one aria-current="step".
|
|
2655
|
+
// Next on the last step finishes; Escape and close end the tour.
|
|
2656
|
+
Alpine.data("lilyTour", (step = 0, open = true) => ({
|
|
2657
|
+
step,
|
|
2658
|
+
open,
|
|
2659
|
+
total: 0,
|
|
2660
|
+
init() {
|
|
2661
|
+
this.total = this.count();
|
|
2662
|
+
},
|
|
2663
|
+
count() {
|
|
2664
|
+
return boundCount(this.$root, "item(");
|
|
2665
|
+
},
|
|
2666
|
+
go(to) {
|
|
2667
|
+
if (to < 0) return;
|
|
2668
|
+
if (to >= this.count()) return this.end("lily:finish");
|
|
2669
|
+
this.step = to;
|
|
2670
|
+
this.$dispatch("lily:change", { step: to });
|
|
2671
|
+
},
|
|
2672
|
+
end(type = "lily:close") {
|
|
2673
|
+
this.open = false;
|
|
2674
|
+
this.$dispatch(type);
|
|
2675
|
+
},
|
|
2676
|
+
// A non-modal dialog, as in Svelte (tasks.md P18-T13): no aria-modal, the page it points at stays usable.
|
|
2677
|
+
root: {
|
|
2678
|
+
role: "dialog",
|
|
2679
|
+
tabindex: "-1",
|
|
2680
|
+
":hidden"() {
|
|
2681
|
+
return !this.open;
|
|
2682
|
+
},
|
|
2683
|
+
"@keydown.escape"() {
|
|
2684
|
+
if (this.open) this.end();
|
|
2685
|
+
},
|
|
2686
|
+
},
|
|
2687
|
+
previous: {
|
|
2688
|
+
type: "button",
|
|
2689
|
+
"@click"() {
|
|
2690
|
+
this.go(this.step - 1);
|
|
2691
|
+
},
|
|
2692
|
+
},
|
|
2693
|
+
next: {
|
|
2694
|
+
type: "button",
|
|
2695
|
+
"@click"() {
|
|
2696
|
+
this.go(this.step + 1);
|
|
2697
|
+
},
|
|
2698
|
+
},
|
|
2699
|
+
close: {
|
|
2700
|
+
type: "button",
|
|
2701
|
+
"@click"() {
|
|
2702
|
+
this.end();
|
|
2703
|
+
},
|
|
2704
|
+
},
|
|
2705
|
+
item(i) {
|
|
2706
|
+
return {
|
|
2707
|
+
":aria-label"() {
|
|
2708
|
+
return `${i + 1} / ${this.total}`;
|
|
2709
|
+
},
|
|
2710
|
+
":aria-current"() {
|
|
2711
|
+
return this.step === i ? "step" : null;
|
|
2712
|
+
},
|
|
2713
|
+
":aria-hidden"() {
|
|
2714
|
+
return this.step === i ? null : "true";
|
|
2715
|
+
},
|
|
2716
|
+
":hidden"() {
|
|
2717
|
+
return this.step !== i;
|
|
2718
|
+
},
|
|
2719
|
+
};
|
|
2720
|
+
},
|
|
2721
|
+
}));
|
|
2722
|
+
|
|
2723
|
+
// Coachmark: a non-modal dialog (aria-modal="false") with a dismiss button;
|
|
2724
|
+
// Escape dismisses. Hidden while closed.
|
|
2725
|
+
Alpine.data("lilyCoachmark", (open = true) => ({
|
|
2726
|
+
open,
|
|
2727
|
+
dismiss() {
|
|
2728
|
+
this.open = false;
|
|
2729
|
+
this.$dispatch("lily:dismiss");
|
|
2730
|
+
},
|
|
2731
|
+
root: {
|
|
2732
|
+
...manualPopover((o) => o.open),
|
|
2733
|
+
"@keydown.escape"() {
|
|
2734
|
+
if (this.open) this.dismiss();
|
|
2735
|
+
},
|
|
2736
|
+
},
|
|
2737
|
+
dismissButton: {
|
|
2738
|
+
type: "button",
|
|
2739
|
+
"@click"() {
|
|
2740
|
+
this.dismiss();
|
|
2741
|
+
},
|
|
2742
|
+
},
|
|
2743
|
+
}));
|
|
2744
|
+
|
|
2745
|
+
// FileUpload: a button opens the hidden native file input; the status
|
|
2746
|
+
// (aria-live="polite") carries the file count in data-file-count.
|
|
2747
|
+
Alpine.data("lilyFileUpload", () => ({
|
|
2748
|
+
count: 0,
|
|
2749
|
+
trigger: {
|
|
2750
|
+
type: "button",
|
|
2751
|
+
"@click"() {
|
|
2752
|
+
this.$refs.input.click();
|
|
2753
|
+
},
|
|
2754
|
+
},
|
|
2755
|
+
input: {
|
|
2756
|
+
"x-ref": "input",
|
|
2757
|
+
type: "file",
|
|
2758
|
+
"@change"(event) {
|
|
2759
|
+
const files = Array.from(event.target.files ?? []);
|
|
2760
|
+
this.count = files.length;
|
|
2761
|
+
this.$dispatch("lily:change", { files });
|
|
2762
|
+
},
|
|
2763
|
+
},
|
|
2764
|
+
status: {
|
|
2765
|
+
"aria-live": "polite",
|
|
2766
|
+
":data-file-count"() {
|
|
2767
|
+
return String(this.count);
|
|
2768
|
+
},
|
|
2769
|
+
"x-text"() {
|
|
2770
|
+
return this.count ? String(this.count) : "";
|
|
2771
|
+
},
|
|
2772
|
+
},
|
|
2773
|
+
}));
|
|
2774
|
+
|
|
2775
|
+
// MiddleTruncation: the text shortened in the middle to the root's measured width (canvas metrics in its own font),
|
|
2776
|
+
// re-measured on resize. The full text stays in the page for assistive technology; ellipsis has no default.
|
|
2777
|
+
Alpine.data("lilyMiddleTruncation", (options = {}) => ({
|
|
2778
|
+
text: options.text ?? "",
|
|
2779
|
+
ellipsis: options.ellipsis ?? "",
|
|
2780
|
+
strategy: options.strategy ?? "even",
|
|
2781
|
+
end: options.end,
|
|
2782
|
+
shown: null,
|
|
2783
|
+
_observer: null,
|
|
2784
|
+
_frame: 0,
|
|
2785
|
+
_context: undefined,
|
|
2786
|
+
init() {
|
|
2787
|
+
this.recalculate();
|
|
2788
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
2789
|
+
this._observer = new ResizeObserver(() => {
|
|
2790
|
+
cancelAnimationFrame(this._frame);
|
|
2791
|
+
this._frame = requestAnimationFrame(() => this.recalculate());
|
|
2792
|
+
});
|
|
2793
|
+
this._observer.observe(this.$el);
|
|
2794
|
+
}
|
|
2795
|
+
this.$watch(
|
|
2796
|
+
() => [this.text, this.ellipsis, this.strategy, this.end],
|
|
2797
|
+
() => this.recalculate(),
|
|
2798
|
+
);
|
|
2799
|
+
},
|
|
2800
|
+
destroy() {
|
|
2801
|
+
cancelAnimationFrame(this._frame);
|
|
2802
|
+
this._observer?.disconnect();
|
|
2803
|
+
},
|
|
2804
|
+
recalculate() {
|
|
2805
|
+
const el = this.$el;
|
|
2806
|
+
const width = el.clientWidth;
|
|
2807
|
+
if (this._context === undefined)
|
|
2808
|
+
this._context = document.createElement("canvas").getContext("2d");
|
|
2809
|
+
const ctx = this._context;
|
|
2810
|
+
if (!ctx || width <= 0) {
|
|
2811
|
+
this.shown = null;
|
|
2812
|
+
return;
|
|
2813
|
+
}
|
|
2814
|
+
const style = getComputedStyle(el);
|
|
2815
|
+
ctx.font = `${style.fontStyle} ${style.fontWeight} ${style.fontSize} ${style.fontFamily}`;
|
|
2816
|
+
const result = truncateMiddle(this.text, {
|
|
2817
|
+
ellipsis: this.ellipsis,
|
|
2818
|
+
strategy: this.strategy,
|
|
2819
|
+
end: this.end,
|
|
2820
|
+
maxWidth: width,
|
|
2821
|
+
measure: (t) => ctx.measureText(t).width,
|
|
2822
|
+
});
|
|
2823
|
+
this.shown = result === this.text ? null : result;
|
|
2824
|
+
},
|
|
2825
|
+
root: {
|
|
2826
|
+
":data-strategy"() {
|
|
2827
|
+
return this.strategy;
|
|
2828
|
+
},
|
|
2829
|
+
":data-truncated"() {
|
|
2830
|
+
return this.shown === null ? null : "";
|
|
2831
|
+
},
|
|
2832
|
+
},
|
|
2833
|
+
visual: {
|
|
2834
|
+
"x-text"() {
|
|
2835
|
+
return this.shown ?? this.text;
|
|
2836
|
+
},
|
|
2837
|
+
},
|
|
2838
|
+
full: {
|
|
2839
|
+
"x-text"() {
|
|
2840
|
+
return this.text;
|
|
2841
|
+
},
|
|
2842
|
+
},
|
|
2843
|
+
}));
|
|
2844
|
+
|
|
2845
|
+
// WheelPicker: a single-select listbox, vertical by default, where the selection follows the cursor (APG listbox). The roles
|
|
2846
|
+
// live in the snippet; this owns the value, the keys (arrows, Home/End, PageUp/PageDown, type-ahead), centring the selected
|
|
2847
|
+
// option, the optional hidden input (x-bind="input": its value, disabled with the picker), form reset, and scrolling: when
|
|
2848
|
+
// the user turns the wheel and it settles, the option in the middle is chosen.
|
|
2849
|
+
let wheelPickerCount = 0;
|
|
2850
|
+
Alpine.data("lilyWheelPicker", (config = {}) => ({
|
|
2851
|
+
options: config.options ?? [],
|
|
2852
|
+
value: config.value ?? "",
|
|
2853
|
+
loop: Boolean(config.loop),
|
|
2854
|
+
pageSize: config.pageSize ?? 5,
|
|
2855
|
+
disabled: Boolean(config.disabled),
|
|
2856
|
+
orientation: config.orientation === "horizontal" ? "horizontal" : "vertical",
|
|
2857
|
+
uid: `wheel-picker-${++wheelPickerCount}`,
|
|
2858
|
+
_typeahead: { prefix: "", at: 0 },
|
|
2859
|
+
_initial: config.value ?? "",
|
|
2860
|
+
_form: null,
|
|
2861
|
+
_resetTimer: undefined,
|
|
2862
|
+
init() {
|
|
2863
|
+
this.$nextTick(() => this.centre());
|
|
2864
|
+
this.$watch("value", () => this.$nextTick(() => this.centre()));
|
|
2865
|
+
// Form reset: a hidden input keeps its value through a reset, so put the picker back to its first value, one tick
|
|
2866
|
+
// after `reset` and not when it was cancelled. The input's own `form` follows a `form` attribute.
|
|
2867
|
+
this._form = this.$refs.input?.form ?? this.$el.closest("form");
|
|
2868
|
+
this._onReset = (event) => {
|
|
2869
|
+
clearTimeout(this._resetTimer);
|
|
2870
|
+
this._resetTimer = setTimeout(() => {
|
|
2871
|
+
if (event.defaultPrevented || this.value === this._initial) return;
|
|
2872
|
+
this.value = this._initial;
|
|
2873
|
+
this.$dispatch("change", { value: this._initial });
|
|
2874
|
+
}, 0);
|
|
2875
|
+
};
|
|
2876
|
+
this._form?.addEventListener("reset", this._onReset);
|
|
2877
|
+
// Scrolling chooses: when the user turns the wheel and it settles, the option in the middle becomes the value.
|
|
2878
|
+
this._stopScroll = watchWheelScroll(this.$refs.list, {
|
|
2879
|
+
options: () => this.options,
|
|
2880
|
+
selected: () => this.selectedIndex,
|
|
2881
|
+
orientation: () => this.orientation,
|
|
2882
|
+
disabled: () => this.disabled,
|
|
2883
|
+
choose: (index) => this.select(index),
|
|
2884
|
+
recentre: () => this.centre(),
|
|
2885
|
+
});
|
|
2886
|
+
},
|
|
2887
|
+
destroy() {
|
|
2888
|
+
this._stopScroll?.();
|
|
2889
|
+
clearTimeout(this._resetTimer);
|
|
2890
|
+
this._form?.removeEventListener("reset", this._onReset);
|
|
2891
|
+
},
|
|
2892
|
+
get selectedIndex() {
|
|
2893
|
+
return this.options.findIndex((o) => o.value === this.value);
|
|
2894
|
+
},
|
|
2895
|
+
select(index) {
|
|
2896
|
+
if (index < 0) return;
|
|
2897
|
+
const next = this.options[index].value;
|
|
2898
|
+
if (next === this.value) return; // applying the selection already held is a no-op
|
|
2899
|
+
this.value = next;
|
|
2900
|
+
this.$dispatch("change", { value: next });
|
|
2901
|
+
},
|
|
2902
|
+
// Only the list scrolls (never the page), and instantly: no animation. Moving by the distance between the two middles
|
|
2903
|
+
// works on either axis and in right-to-left.
|
|
2904
|
+
centre() {
|
|
2905
|
+
const list = this.$refs.list;
|
|
2906
|
+
const option = list?.querySelector(`[data-index="${this.selectedIndex}"]`);
|
|
2907
|
+
if (!list || !option) return;
|
|
2908
|
+
const box = list.getBoundingClientRect();
|
|
2909
|
+
const row = option.getBoundingClientRect();
|
|
2910
|
+
if (this.orientation === "horizontal")
|
|
2911
|
+
list.scrollLeft += row.left + row.width / 2 - (box.left + box.width / 2);
|
|
2912
|
+
else list.scrollTop += row.top + row.height / 2 - (box.top + box.height / 2);
|
|
2913
|
+
},
|
|
2914
|
+
input: {
|
|
2915
|
+
":value"() {
|
|
2916
|
+
return this.value;
|
|
2917
|
+
},
|
|
2918
|
+
":disabled"() {
|
|
2919
|
+
return this.disabled;
|
|
2920
|
+
},
|
|
2921
|
+
},
|
|
2922
|
+
list: {
|
|
2923
|
+
role: "listbox",
|
|
2924
|
+
":aria-orientation"() {
|
|
2925
|
+
return this.orientation;
|
|
2926
|
+
},
|
|
2927
|
+
":aria-disabled"() {
|
|
2928
|
+
return this.disabled ? "true" : null;
|
|
2929
|
+
},
|
|
2930
|
+
":aria-activedescendant"() {
|
|
2931
|
+
return this.selectedIndex >= 0 ? `${this.uid}-option-${this.selectedIndex}` : null;
|
|
2932
|
+
},
|
|
2933
|
+
":tabindex"() {
|
|
2934
|
+
return this.disabled ? -1 : 0;
|
|
2935
|
+
},
|
|
2936
|
+
"@keydown"(event) {
|
|
2937
|
+
if (this.disabled) return;
|
|
2938
|
+
const move = wheelMoveKey(event.key, this.orientation, isWheelRtl(this.$refs.list));
|
|
2939
|
+
if (move) {
|
|
2940
|
+
event.preventDefault();
|
|
2941
|
+
this.select(
|
|
2942
|
+
nextWheelIndex(this.options, this.selectedIndex, move, {
|
|
2943
|
+
loop: this.loop,
|
|
2944
|
+
pageSize: this.pageSize,
|
|
2945
|
+
}),
|
|
2946
|
+
);
|
|
2947
|
+
} else if (isWheelTypeaheadKey(event)) {
|
|
2948
|
+
this._typeahead = nextWheelPrefix(this._typeahead, event.key, Date.now());
|
|
2949
|
+
this.select(
|
|
2950
|
+
wheelTypeaheadIndex(
|
|
2951
|
+
this.options,
|
|
2952
|
+
this.selectedIndex,
|
|
2953
|
+
this._typeahead.prefix,
|
|
2954
|
+
),
|
|
2955
|
+
);
|
|
2956
|
+
}
|
|
2957
|
+
},
|
|
2958
|
+
"@click"(event) {
|
|
2959
|
+
if (this.disabled) return;
|
|
2960
|
+
const target = event.target.closest('[role="option"]');
|
|
2961
|
+
if (!target || target.getAttribute("aria-disabled") === "true") return;
|
|
2962
|
+
this.select(Number(target.getAttribute("data-index")));
|
|
2963
|
+
this.$refs.list.focus();
|
|
2964
|
+
},
|
|
2965
|
+
},
|
|
2966
|
+
}));
|
|
2967
|
+
|
|
2968
|
+
// NavigationMenu overflow mode: the snippet owns the list, the hidden More item and the More list; this measures with a
|
|
2969
|
+
// ResizeObserver on the list and moves the items that do not fit (see overflow-navigation.js). Without it the links wrap.
|
|
2970
|
+
Alpine.data("lilyNavigationMenu", () => ({
|
|
2971
|
+
_overflow: null,
|
|
2972
|
+
init() {
|
|
2973
|
+
this._overflow = setupOverflowNavigation(this.$el);
|
|
2974
|
+
},
|
|
2975
|
+
destroy() {
|
|
2976
|
+
this._overflow?.dispose();
|
|
2977
|
+
},
|
|
2978
|
+
}));
|
|
2979
|
+
}
|