@omicronenergy/oscd-ui 0.0.6 → 0.0.7
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/app-bar/OscdAppBar.d.ts +3 -3
- package/app-bar/OscdAppBar.js +12 -10
- package/app-bar/OscdAppBar.js.map +1 -1
- package/button/OscdFilledButton.js +2 -2
- package/button/OscdFilledButton.js.map +1 -1
- package/button/OscdOutlinedButton.js +1 -1
- package/button/OscdOutlinedButton.js.map +1 -1
- package/button/OscdTextButton.js +1 -1
- package/button/OscdTextButton.js.map +1 -1
- package/button/oscd-outlined-button.d.ts +1 -1
- package/button/oscd-outlined-button.js.map +1 -1
- package/dialog/OscdDialog.js +1 -1
- package/dialog/OscdDialog.js.map +1 -1
- package/divider/OscdDivider.js +1 -1
- package/divider/OscdDivider.js.map +1 -1
- package/elevation/OscdElevation.d.ts +1 -2
- package/elevation/OscdElevation.js +3 -4
- package/elevation/OscdElevation.js.map +1 -1
- package/elevation/_elevation.scss +6 -0
- package/elevation/internal/_elevation.scss +176 -0
- package/elevation/internal/elevation-styles.css +1 -0
- package/elevation/internal/elevation-styles.css.map +1 -0
- package/elevation/internal/elevation-styles.d.ts +1 -0
- package/elevation/internal/elevation-styles.js +10 -0
- package/elevation/internal/elevation-styles.js.map +1 -0
- package/elevation/internal/elevation-styles.scss +10 -0
- package/elevation/internal/elevation.d.ts +13 -0
- package/elevation/internal/elevation.js +21 -0
- package/elevation/internal/elevation.js.map +1 -0
- package/field/OscdFilledField.js +1 -1
- package/field/OscdFilledField.js.map +1 -1
- package/field/OscdOutlinedField.js +1 -1
- package/field/OscdOutlinedField.js.map +1 -1
- package/focus/OscdFocusRing.d.ts +5 -0
- package/focus/OscdFocusRing.js +6 -0
- package/focus/OscdFocusRing.js.map +1 -0
- package/focus/_focus-ring.scss +6 -0
- package/focus/internal/_focus-ring.scss +113 -0
- package/focus/internal/focus-ring-styles.css +1 -0
- package/focus/internal/focus-ring-styles.css.map +1 -0
- package/focus/internal/focus-ring-styles.d.ts +1 -0
- package/focus/internal/focus-ring-styles.js +10 -0
- package/focus/internal/focus-ring-styles.js.map +1 -0
- package/focus/internal/focus-ring-styles.scss +10 -0
- package/focus/internal/focus-ring.d.ts +39 -0
- package/focus/internal/focus-ring.js +101 -0
- package/focus/internal/focus-ring.js.map +1 -0
- package/focus/oscd-focus-ring.d.ts +21 -0
- package/focus/oscd-focus-ring.js +23 -0
- package/focus/oscd-focus-ring.js.map +1 -0
- package/icon/OscdIcon.js +1 -1
- package/icon/OscdIcon.js.map +1 -1
- package/iconbutton/OscdFilledIconButton.js +1 -1
- package/iconbutton/OscdFilledIconButton.js.map +1 -1
- package/iconbutton/OscdFilledTonalIconButton.js +1 -1
- package/iconbutton/OscdFilledTonalIconButton.js.map +1 -1
- package/iconbutton/OscdIconButton.js +1 -1
- package/iconbutton/OscdIconButton.js.map +1 -1
- package/iconbutton/OscdOutlinedIconButton.js +1 -1
- package/iconbutton/OscdOutlinedIconButton.js.map +1 -1
- package/internal/aria/aria.d.ts +103 -0
- package/internal/aria/aria.js +81 -0
- package/internal/aria/aria.js.map +1 -0
- package/internal/aria/delegate.d.ts +54 -0
- package/internal/aria/delegate.js +176 -0
- package/internal/aria/delegate.js.map +1 -0
- package/internal/controller/attachable-controller.d.ts +114 -0
- package/internal/controller/attachable-controller.js +121 -0
- package/internal/controller/attachable-controller.js.map +1 -0
- package/internal/controller/form-submitter.d.ts +70 -0
- package/internal/controller/form-submitter.js +69 -0
- package/internal/controller/form-submitter.js.map +1 -0
- package/internal/controller/is-rtl.d.ts +14 -0
- package/internal/controller/is-rtl.js +18 -0
- package/internal/controller/is-rtl.js.map +1 -0
- package/internal/controller/string-converter.d.ts +9 -0
- package/internal/controller/string-converter.js +14 -0
- package/internal/controller/string-converter.js.map +1 -0
- package/internal/events/dispatch-hooks.d.ts +85 -0
- package/internal/events/dispatch-hooks.js +151 -0
- package/internal/events/dispatch-hooks.js.map +1 -0
- package/internal/events/form-label-activation.d.ts +55 -0
- package/internal/events/form-label-activation.js +96 -0
- package/internal/events/form-label-activation.js.map +1 -0
- package/internal/events/redispatch-event.d.ts +27 -0
- package/internal/events/redispatch-event.js +40 -0
- package/internal/events/redispatch-event.js.map +1 -0
- package/internal/motion/_animation.scss +33 -0
- package/internal/motion/animation.d.ts +80 -0
- package/internal/motion/animation.js +101 -0
- package/internal/motion/animation.js.map +1 -0
- package/internal/sass/_string-ext.scss +195 -0
- package/internal/sass/_var.scss +237 -0
- package/labs/badge/OscdBadge.d.ts +14 -0
- package/labs/badge/OscdBadge.js +15 -0
- package/labs/badge/OscdBadge.js.map +1 -0
- package/labs/badge/_badge.scss +6 -0
- package/labs/badge/internal/_badge.scss +76 -0
- package/labs/badge/internal/badge-styles.css +1 -0
- package/labs/badge/internal/badge-styles.css.map +1 -0
- package/labs/badge/internal/badge-styles.d.ts +1 -0
- package/labs/badge/internal/badge-styles.js +10 -0
- package/labs/badge/internal/badge-styles.js.map +1 -0
- package/labs/badge/internal/badge-styles.scss +10 -0
- package/labs/badge/internal/badge.d.ts +13 -0
- package/labs/badge/internal/badge.js +28 -0
- package/labs/badge/internal/badge.js.map +1 -0
- package/labs/badge/oscd-badge.d.ts +19 -0
- package/labs/badge/oscd-badge.js +21 -0
- package/labs/badge/oscd-badge.js.map +1 -0
- package/labs/behaviors/constraint-validation.d.ts +133 -0
- package/labs/behaviors/constraint-validation.js +131 -0
- package/labs/behaviors/constraint-validation.js.map +1 -0
- package/labs/behaviors/element-internals.d.ts +45 -0
- package/labs/behaviors/element-internals.js +46 -0
- package/labs/behaviors/element-internals.js.map +1 -0
- package/labs/behaviors/focusable.d.ts +39 -0
- package/labs/behaviors/focusable.js +87 -0
- package/labs/behaviors/focusable.js.map +1 -0
- package/labs/behaviors/form-associated.d.ts +199 -0
- package/labs/behaviors/form-associated.js +175 -0
- package/labs/behaviors/form-associated.js.map +1 -0
- package/labs/behaviors/mixin.d.ts +54 -0
- package/labs/behaviors/mixin.js +7 -0
- package/labs/behaviors/mixin.js.map +1 -0
- package/labs/behaviors/on-report-validity.d.ts +71 -0
- package/labs/behaviors/on-report-validity.js +289 -0
- package/labs/behaviors/on-report-validity.js.map +1 -0
- package/labs/behaviors/validators/checkbox-validator.d.ts +35 -0
- package/labs/behaviors/validators/checkbox-validator.js +34 -0
- package/labs/behaviors/validators/checkbox-validator.js.map +1 -0
- package/labs/behaviors/validators/radio-validator.d.ts +38 -0
- package/labs/behaviors/validators/radio-validator.js +67 -0
- package/labs/behaviors/validators/radio-validator.js.map +1 -0
- package/labs/behaviors/validators/select-validator.d.ts +35 -0
- package/labs/behaviors/validators/select-validator.js +35 -0
- package/labs/behaviors/validators/select-validator.js.map +1 -0
- package/labs/behaviors/validators/text-field-validator.d.ts +110 -0
- package/labs/behaviors/validators/text-field-validator.js +156 -0
- package/labs/behaviors/validators/text-field-validator.js.map +1 -0
- package/labs/behaviors/validators/validator.d.ts +96 -0
- package/labs/behaviors/validators/validator.js +73 -0
- package/labs/behaviors/validators/validator.js.map +1 -0
- package/labs/card/OscdElevatedCard.d.ts +20 -0
- package/labs/card/OscdElevatedCard.js +23 -0
- package/labs/card/OscdElevatedCard.js.map +1 -0
- package/labs/card/OscdFilledCard.d.ts +20 -0
- package/labs/card/OscdFilledCard.js +23 -0
- package/labs/card/OscdFilledCard.js.map +1 -0
- package/labs/card/OscdOutlinedCard.d.ts +20 -0
- package/labs/card/OscdOutlinedCard.js +23 -0
- package/labs/card/OscdOutlinedCard.js.map +1 -0
- package/labs/card/_elevated-card.scss +6 -0
- package/labs/card/_filled-card.scss +6 -0
- package/labs/card/_outlined-card.scss +6 -0
- package/labs/card/demo/demo.d.ts +7 -0
- package/labs/card/demo/demo.js +13 -0
- package/labs/card/demo/demo.js.map +1 -0
- package/labs/card/demo/stories.d.ts +15 -0
- package/labs/card/demo/stories.js +104 -0
- package/labs/card/demo/stories.js.map +1 -0
- package/labs/card/internal/_elevated-card.scss +35 -0
- package/labs/card/internal/_filled-card.scss +35 -0
- package/labs/card/internal/_outlined-card.scss +40 -0
- package/labs/card/internal/_shared.scss +62 -0
- package/labs/card/internal/card.d.ts +12 -0
- package/labs/card/internal/card.js +21 -0
- package/labs/card/internal/card.js.map +1 -0
- package/labs/card/internal/elevated-styles.css +1 -0
- package/labs/card/internal/elevated-styles.css.map +1 -0
- package/labs/card/internal/elevated-styles.d.ts +1 -0
- package/labs/card/internal/elevated-styles.js +10 -0
- package/labs/card/internal/elevated-styles.js.map +1 -0
- package/labs/card/internal/elevated-styles.scss +10 -0
- package/labs/card/internal/filled-styles.css +1 -0
- package/labs/card/internal/filled-styles.css.map +1 -0
- package/labs/card/internal/filled-styles.d.ts +1 -0
- package/labs/card/internal/filled-styles.js +10 -0
- package/labs/card/internal/filled-styles.js.map +1 -0
- package/labs/card/internal/filled-styles.scss +10 -0
- package/labs/card/internal/outlined-styles.css +1 -0
- package/labs/card/internal/outlined-styles.css.map +1 -0
- package/labs/card/internal/outlined-styles.d.ts +1 -0
- package/labs/card/internal/outlined-styles.js +10 -0
- package/labs/card/internal/outlined-styles.js.map +1 -0
- package/labs/card/internal/outlined-styles.scss +10 -0
- package/labs/card/internal/shared-styles.css +1 -0
- package/labs/card/internal/shared-styles.css.map +1 -0
- package/labs/card/internal/shared-styles.d.ts +1 -0
- package/labs/card/internal/shared-styles.js +10 -0
- package/labs/card/internal/shared-styles.js.map +1 -0
- package/labs/card/internal/shared-styles.scss +10 -0
- package/labs/card/oscd-elevated-card.d.ts +20 -0
- package/labs/card/oscd-elevated-card.js +23 -0
- package/labs/card/oscd-elevated-card.js.map +1 -0
- package/labs/card/oscd-filled-card.d.ts +25 -0
- package/labs/card/oscd-filled-card.js +28 -0
- package/labs/card/oscd-filled-card.js.map +1 -0
- package/labs/card/oscd-outlined-card.d.ts +20 -0
- package/labs/card/oscd-outlined-card.js +23 -0
- package/labs/card/oscd-outlined-card.js.map +1 -0
- package/list/OscdList.js +1 -1
- package/list/OscdList.js.map +1 -1
- package/list/OscdListItem.d.ts +4 -0
- package/list/OscdListItem.js +13 -1
- package/list/OscdListItem.js.map +1 -1
- package/menu/OscdMenu.js +1 -1
- package/menu/OscdMenu.js.map +1 -1
- package/menu/OscdMenuItem.js +1 -1
- package/menu/OscdMenuItem.js.map +1 -1
- package/navigation-drawer/OscdNavigationDrawer.js +2 -2
- package/navigation-drawer/OscdNavigationDrawer.js.map +1 -1
- package/navigation-drawer/OscdNavigationDrawerHeader.js +2 -2
- package/navigation-drawer/OscdNavigationDrawerHeader.js.map +1 -1
- package/package.json +76 -110
- package/radio/OscdRadio.d.ts +31 -0
- package/radio/OscdRadio.js +27 -0
- package/radio/OscdRadio.js.map +1 -0
- package/radio/demo/demo.d.ts +7 -0
- package/radio/demo/demo.js +14 -0
- package/radio/demo/demo.js.map +1 -0
- package/radio/demo/stories.d.ts +13 -0
- package/radio/demo/stories.js +97 -0
- package/radio/demo/stories.js.map +1 -0
- package/radio/internal/_radio.scss +198 -0
- package/radio/internal/radio-styles.css +1 -0
- package/radio/internal/radio-styles.css.map +1 -0
- package/radio/internal/radio-styles.d.ts +1 -0
- package/radio/internal/radio-styles.js +10 -0
- package/radio/internal/radio-styles.js.map +1 -0
- package/radio/internal/radio-styles.scss +10 -0
- package/radio/internal/radio.d.ts +59 -0
- package/radio/internal/radio.js +175 -0
- package/radio/internal/radio.js.map +1 -0
- package/radio/internal/single-selection-controller.d.ts +80 -0
- package/radio/internal/single-selection-controller.js +199 -0
- package/radio/internal/single-selection-controller.js.map +1 -0
- package/radio/oscd-radio.d.ts +32 -0
- package/radio/oscd-radio.js +34 -0
- package/radio/oscd-radio.js.map +1 -0
- package/ripple/OscdRipple.d.ts +5 -0
- package/ripple/OscdRipple.js +6 -0
- package/ripple/OscdRipple.js.map +1 -0
- package/ripple/_ripple.scss +6 -0
- package/ripple/internal/_ripple.scss +92 -0
- package/ripple/internal/ripple-styles.css +1 -0
- package/ripple/internal/ripple-styles.css.map +1 -0
- package/ripple/internal/ripple-styles.d.ts +1 -0
- package/ripple/internal/ripple-styles.js +10 -0
- package/ripple/internal/ripple-styles.js.map +1 -0
- package/ripple/internal/ripple-styles.scss +10 -0
- package/ripple/internal/ripple.d.ts +76 -0
- package/ripple/internal/ripple.js +425 -0
- package/ripple/internal/ripple.js.map +1 -0
- package/ripple/oscd-ripple.d.ts +29 -0
- package/ripple/oscd-ripple.js +31 -0
- package/ripple/oscd-ripple.js.map +1 -0
- package/select/OscdFilledSelect.js +1 -1
- package/select/OscdFilledSelect.js.map +1 -1
- package/select/OscdOutlinedSelect.js +1 -1
- package/select/OscdOutlinedSelect.js.map +1 -1
- package/select/OscdSelectOption.js +1 -1
- package/select/OscdSelectOption.js.map +1 -1
- package/tabs/OscdPrimaryTab.js +1 -1
- package/tabs/OscdPrimaryTab.js.map +1 -1
- package/tabs/OscdSecondaryTab.js +1 -1
- package/tabs/OscdSecondaryTab.js.map +1 -1
- package/tabs/OscdTabs.js +1 -1
- package/tabs/OscdTabs.js.map +1 -1
- package/textfield/OscdFilledTextField.js +5 -2
- package/textfield/OscdFilledTextField.js.map +1 -1
- package/textfield/OscdOutlinedTextField.js +5 -2
- package/textfield/OscdOutlinedTextField.js.map +1 -1
- package/tokens/_index.scss +66 -0
- package/tokens/_md-comp-assist-chip.scss +153 -0
- package/tokens/_md-comp-badge.scss +39 -0
- package/tokens/_md-comp-checkbox.scss +156 -0
- package/tokens/_md-comp-circular-progress.scss +79 -0
- package/tokens/_md-comp-dialog.scss +112 -0
- package/tokens/_md-comp-divider.scss +43 -0
- package/tokens/_md-comp-elevated-button.scss +143 -0
- package/tokens/_md-comp-elevated-card.scss +80 -0
- package/tokens/_md-comp-elevation.scss +48 -0
- package/tokens/_md-comp-fab-branded.scss +155 -0
- package/tokens/_md-comp-fab.scss +296 -0
- package/tokens/_md-comp-filled-button.scss +143 -0
- package/tokens/_md-comp-filled-card.scss +80 -0
- package/tokens/_md-comp-filled-field.scss +293 -0
- package/tokens/_md-comp-filled-icon-button.scss +119 -0
- package/tokens/_md-comp-filled-select.scss +198 -0
- package/tokens/_md-comp-filled-text-field.scss +200 -0
- package/tokens/_md-comp-filled-tonal-button.scss +143 -0
- package/tokens/_md-comp-filled-tonal-icon-button.scss +123 -0
- package/tokens/_md-comp-filter-chip.scss +265 -0
- package/tokens/_md-comp-focus-ring.scss +78 -0
- package/tokens/_md-comp-full-screen-dialog.scss +25 -0
- package/tokens/_md-comp-icon-button.scss +94 -0
- package/tokens/_md-comp-icon.scss +46 -0
- package/tokens/_md-comp-input-chip.scss +247 -0
- package/tokens/_md-comp-item.scss +88 -0
- package/tokens/_md-comp-linear-progress.scss +64 -0
- package/tokens/_md-comp-list-item.scss +173 -0
- package/tokens/_md-comp-list.scss +44 -0
- package/tokens/_md-comp-menu-item.scss +125 -0
- package/tokens/_md-comp-menu.scss +59 -0
- package/tokens/_md-comp-navigation-bar.scss +44 -0
- package/tokens/_md-comp-navigation-drawer.scss +44 -0
- package/tokens/_md-comp-outlined-button.scss +139 -0
- package/tokens/_md-comp-outlined-card.scss +86 -0
- package/tokens/_md-comp-outlined-field.scss +268 -0
- package/tokens/_md-comp-outlined-icon-button.scss +117 -0
- package/tokens/_md-comp-outlined-segmented-button.scss +123 -0
- package/tokens/_md-comp-outlined-select.scss +186 -0
- package/tokens/_md-comp-outlined-text-field.scss +187 -0
- package/tokens/_md-comp-primary-tab.scss +160 -0
- package/tokens/_md-comp-radio.scss +86 -0
- package/tokens/_md-comp-ripple.scss +48 -0
- package/tokens/_md-comp-secondary-tab.scss +158 -0
- package/tokens/_md-comp-slider.scss +117 -0
- package/tokens/_md-comp-suggestion-chip.scss +157 -0
- package/tokens/_md-comp-switch.scss +187 -0
- package/tokens/_md-comp-test-table.scss +43 -0
- package/tokens/_md-comp-text-button.scss +132 -0
- package/tokens/_md-ref-palette.scss +112 -0
- package/tokens/_md-ref-typeface.scss +46 -0
- package/tokens/_md-sys-color.scss +119 -0
- package/tokens/_md-sys-elevation.scss +31 -0
- package/tokens/_md-sys-motion.scss +12 -0
- package/tokens/_md-sys-shape.scss +102 -0
- package/tokens/_md-sys-state.scss +12 -0
- package/tokens/_md-sys-typescale.scss +149 -0
- package/tokens/internal/_shape.scss +93 -0
- package/tokens/internal/_validate.scss +109 -0
- package/tokens/v0_192/_index.scss +107 -0
- package/tokens/v0_192/_md-comp-assist-chip.scss +111 -0
- package/tokens/v0_192/_md-comp-badge.scss +61 -0
- package/tokens/v0_192/_md-comp-banner.scss +76 -0
- package/tokens/v0_192/_md-comp-bottom-app-bar.scss +36 -0
- package/tokens/v0_192/_md-comp-carousel-item.scss +66 -0
- package/tokens/v0_192/_md-comp-checkbox.scss +129 -0
- package/tokens/v0_192/_md-comp-circular-progress-indicator.scss +41 -0
- package/tokens/v0_192/_md-comp-data-table.scss +99 -0
- package/tokens/v0_192/_md-comp-date-input-modal.scss +90 -0
- package/tokens/v0_192/_md-comp-date-picker-docked.scss +247 -0
- package/tokens/v0_192/_md-comp-date-picker-modal.scss +306 -0
- package/tokens/v0_192/_md-comp-dialog.scss +124 -0
- package/tokens/v0_192/_md-comp-divider.scss +28 -0
- package/tokens/v0_192/_md-comp-elevated-button.scss +92 -0
- package/tokens/v0_192/_md-comp-elevated-card.scss +60 -0
- package/tokens/v0_192/_md-comp-extended-fab-branded.scss +89 -0
- package/tokens/v0_192/_md-comp-extended-fab-primary.scss +97 -0
- package/tokens/v0_192/_md-comp-extended-fab-secondary.scss +98 -0
- package/tokens/v0_192/_md-comp-extended-fab-surface.scss +93 -0
- package/tokens/v0_192/_md-comp-extended-fab-tertiary.scss +98 -0
- package/tokens/v0_192/_md-comp-fab-branded-large.scss +63 -0
- package/tokens/v0_192/_md-comp-fab-branded.scss +63 -0
- package/tokens/v0_192/_md-comp-fab-primary-large.scss +68 -0
- package/tokens/v0_192/_md-comp-fab-primary-small.scss +68 -0
- package/tokens/v0_192/_md-comp-fab-primary.scss +68 -0
- package/tokens/v0_192/_md-comp-fab-secondary-large.scss +69 -0
- package/tokens/v0_192/_md-comp-fab-secondary-small.scss +69 -0
- package/tokens/v0_192/_md-comp-fab-secondary.scss +69 -0
- package/tokens/v0_192/_md-comp-fab-surface-large.scss +67 -0
- package/tokens/v0_192/_md-comp-fab-surface-small.scss +67 -0
- package/tokens/v0_192/_md-comp-fab-surface.scss +67 -0
- package/tokens/v0_192/_md-comp-fab-tertiary-large.scss +69 -0
- package/tokens/v0_192/_md-comp-fab-tertiary-small.scss +69 -0
- package/tokens/v0_192/_md-comp-fab-tertiary.scss +69 -0
- package/tokens/v0_192/_md-comp-filled-autocomplete.scss +239 -0
- package/tokens/v0_192/_md-comp-filled-button.scss +92 -0
- package/tokens/v0_192/_md-comp-filled-card.scss +62 -0
- package/tokens/v0_192/_md-comp-filled-icon-button.scss +83 -0
- package/tokens/v0_192/_md-comp-filled-menu-button.scss +101 -0
- package/tokens/v0_192/_md-comp-filled-select.scss +273 -0
- package/tokens/v0_192/_md-comp-filled-text-field.scss +193 -0
- package/tokens/v0_192/_md-comp-filled-tonal-button.scss +102 -0
- package/tokens/v0_192/_md-comp-filled-tonal-icon-button.scss +90 -0
- package/tokens/v0_192/_md-comp-filter-chip.scss +210 -0
- package/tokens/v0_192/_md-comp-full-screen-dialog.scss +114 -0
- package/tokens/v0_192/_md-comp-icon-button.scss +74 -0
- package/tokens/v0_192/_md-comp-input-chip.scss +187 -0
- package/tokens/v0_192/_md-comp-linear-progress-indicator.scss +43 -0
- package/tokens/v0_192/_md-comp-list.scss +255 -0
- package/tokens/v0_192/_md-comp-menu.scss +44 -0
- package/tokens/v0_192/_md-comp-navigation-bar.scss +115 -0
- package/tokens/v0_192/_md-comp-navigation-drawer.scss +165 -0
- package/tokens/v0_192/_md-comp-navigation-rail.scss +119 -0
- package/tokens/v0_192/_md-comp-outlined-autocomplete.scss +229 -0
- package/tokens/v0_192/_md-comp-outlined-button.scss +87 -0
- package/tokens/v0_192/_md-comp-outlined-card.scss +66 -0
- package/tokens/v0_192/_md-comp-outlined-icon-button.scss +83 -0
- package/tokens/v0_192/_md-comp-outlined-menu-button.scss +97 -0
- package/tokens/v0_192/_md-comp-outlined-segmented-button.scss +115 -0
- package/tokens/v0_192/_md-comp-outlined-select.scss +263 -0
- package/tokens/v0_192/_md-comp-outlined-text-field.scss +174 -0
- package/tokens/v0_192/_md-comp-plain-tooltip.scss +58 -0
- package/tokens/v0_192/_md-comp-primary-navigation-tab.scss +124 -0
- package/tokens/v0_192/_md-comp-radio-button.scss +71 -0
- package/tokens/v0_192/_md-comp-rich-tooltip.scss +122 -0
- package/tokens/v0_192/_md-comp-scrim.scss +28 -0
- package/tokens/v0_192/_md-comp-search-bar.scss +100 -0
- package/tokens/v0_192/_md-comp-search-view.scss +94 -0
- package/tokens/v0_192/_md-comp-secondary-navigation-tab.scss +87 -0
- package/tokens/v0_192/_md-comp-sheet-bottom.scss +46 -0
- package/tokens/v0_192/_md-comp-sheet-floating.scss +35 -0
- package/tokens/v0_192/_md-comp-sheet-side.scss +94 -0
- package/tokens/v0_192/_md-comp-slider.scss +118 -0
- package/tokens/v0_192/_md-comp-snackbar.scss +130 -0
- package/tokens/v0_192/_md-comp-standard-menu-button.scss +101 -0
- package/tokens/v0_192/_md-comp-suggestion-chip.scss +127 -0
- package/tokens/v0_192/_md-comp-switch.scss +141 -0
- package/tokens/v0_192/_md-comp-text-button.scss +80 -0
- package/tokens/v0_192/_md-comp-time-input.scss +220 -0
- package/tokens/v0_192/_md-comp-time-picker.scss +267 -0
- package/tokens/v0_192/_md-comp-top-app-bar-large.scss +64 -0
- package/tokens/v0_192/_md-comp-top-app-bar-medium.scss +64 -0
- package/tokens/v0_192/_md-comp-top-app-bar-small-centered.scss +71 -0
- package/tokens/v0_192/_md-comp-top-app-bar-small.scss +67 -0
- package/tokens/v0_192/_md-ref-palette.scss +109 -0
- package/tokens/v0_192/_md-ref-typeface.scss +23 -0
- package/tokens/v0_192/_md-sys-color.scss +135 -0
- package/tokens/v0_192/_md-sys-elevation.scss +24 -0
- package/tokens/v0_192/_md-sys-motion.scss +55 -0
- package/tokens/v0_192/_md-sys-shape.scss +33 -0
- package/tokens/v0_192/_md-sys-state.scss +22 -0
- package/tokens/v0_192/_md-sys-typescale.scss +286 -0
- package/tokens/v0_192/index.test.css +1 -0
- package/tokens/v0_192/index.test.css.map +1 -0
- package/tokens/v0_192/index.test.scss +584 -0
- package/tokens/v0_192/lib.test.css +1 -0
- package/tokens/v0_192/lib.test.css.map +1 -0
- package/tokens/v0_192/lib.test.scss +663 -0
- package/utils/storybook/getStorybookHelpers.js +0 -1
- package/utils/storybook/getStorybookHelpers.js.map +1 -1
- package/utils/storybook/scopedWcDecorator.js +1 -0
- package/utils/storybook/scopedWcDecorator.js.map +1 -1
- package/utils/storybook/stories/components/knob-ui-components.d.ts +103 -0
- package/utils/storybook/stories/components/knob-ui-components.js +414 -0
- package/utils/storybook/stories/components/knob-ui-components.js.map +1 -0
- package/utils/storybook/stories/components/stories-renderer.d.ts +40 -0
- package/utils/storybook/stories/components/stories-renderer.js +204 -0
- package/utils/storybook/stories/components/stories-renderer.js.map +1 -0
- package/utils/storybook/stories/components/story-knob-panel.d.ts +53 -0
- package/utils/storybook/stories/components/story-knob-panel.js +333 -0
- package/utils/storybook/stories/components/story-knob-panel.js.map +1 -0
- package/utils/storybook/stories/components/story-renderer.d.ts +27 -0
- package/utils/storybook/stories/components/story-renderer.js +84 -0
- package/utils/storybook/stories/components/story-renderer.js.map +1 -0
- package/utils/storybook/stories/index.d.ts +8 -0
- package/utils/storybook/stories/index.js +11 -0
- package/utils/storybook/stories/index.js.map +1 -0
- package/utils/storybook/stories/knobs.d.ts +143 -0
- package/utils/storybook/stories/knobs.js +177 -0
- package/utils/storybook/stories/knobs.js.map +1 -0
- package/utils/storybook/stories/material-collection.d.ts +75 -0
- package/utils/storybook/stories/material-collection.js +59 -0
- package/utils/storybook/stories/material-collection.js.map +1 -0
- package/utils/storybook/stories/story.d.ts +85 -0
- package/utils/storybook/stories/story.js +142 -0
- package/utils/storybook/stories/story.js.map +1 -0
- package/utils/storybook/stories/theme-loader.d.ts +13 -0
- package/utils/storybook/stories/theme-loader.js +43 -0
- package/utils/storybook/stories/theme-loader.js.map +1 -0
- package/utils/storybook/themingDecorator.d.ts +15 -2
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2023 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { __decorate } from "tslib";
|
|
7
|
+
import { property } from 'lit/decorators.js';
|
|
8
|
+
import { internals } from './element-internals.js';
|
|
9
|
+
/**
|
|
10
|
+
* A symbol property to retrieve the form value for an element.
|
|
11
|
+
*/
|
|
12
|
+
export const getFormValue = Symbol('getFormValue');
|
|
13
|
+
/**
|
|
14
|
+
* A symbol property to retrieve the form state for an element.
|
|
15
|
+
*/
|
|
16
|
+
export const getFormState = Symbol('getFormState');
|
|
17
|
+
/**
|
|
18
|
+
* Mixes in form-associated behavior for a class. This allows an element to add
|
|
19
|
+
* values to `<form>` elements.
|
|
20
|
+
*
|
|
21
|
+
* Implementing classes should provide a `[formValue]` to return the current
|
|
22
|
+
* value of the element, as well as reset and restore callbacks.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* const base = mixinFormAssociated(mixinElementInternals(LitElement));
|
|
27
|
+
*
|
|
28
|
+
* class MyControl extends base {
|
|
29
|
+
* \@property()
|
|
30
|
+
* value = '';
|
|
31
|
+
*
|
|
32
|
+
* override [getFormValue]() {
|
|
33
|
+
* return this.value;
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* override formResetCallback() {
|
|
37
|
+
* const defaultValue = this.getAttribute('value');
|
|
38
|
+
* this.value = defaultValue;
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* override formStateRestoreCallback(state: string) {
|
|
42
|
+
* this.value = state;
|
|
43
|
+
* }
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* Elements may optionally provide a `[formState]` if their values do not
|
|
48
|
+
* represent the state of the component.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* const base = mixinFormAssociated(mixinElementInternals(LitElement));
|
|
53
|
+
*
|
|
54
|
+
* class MyCheckbox extends base {
|
|
55
|
+
* \@property()
|
|
56
|
+
* value = 'on';
|
|
57
|
+
*
|
|
58
|
+
* \@property({type: Boolean})
|
|
59
|
+
* checked = false;
|
|
60
|
+
*
|
|
61
|
+
* override [getFormValue]() {
|
|
62
|
+
* return this.checked ? this.value : null;
|
|
63
|
+
* }
|
|
64
|
+
*
|
|
65
|
+
* override [getFormState]() {
|
|
66
|
+
* return String(this.checked);
|
|
67
|
+
* }
|
|
68
|
+
*
|
|
69
|
+
* override formResetCallback() {
|
|
70
|
+
* const defaultValue = this.hasAttribute('checked');
|
|
71
|
+
* this.checked = defaultValue;
|
|
72
|
+
* }
|
|
73
|
+
*
|
|
74
|
+
* override formStateRestoreCallback(state: string) {
|
|
75
|
+
* this.checked = Boolean(state);
|
|
76
|
+
* }
|
|
77
|
+
* }
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* IMPORTANT: Requires declares for lit-analyzer
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* const base = mixinFormAssociated(mixinElementInternals(LitElement));
|
|
84
|
+
* class MyControl extends base {
|
|
85
|
+
* // Writable mixin properties for lit-html binding, needed for lit-analyzer
|
|
86
|
+
* declare disabled: boolean;
|
|
87
|
+
* declare name: string;
|
|
88
|
+
* }
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @param base The class to mix functionality into. The base class must use
|
|
92
|
+
* `mixinElementInternals()`.
|
|
93
|
+
* @return The provided class with `FormAssociated` mixed in.
|
|
94
|
+
*/
|
|
95
|
+
export function mixinFormAssociated(base) {
|
|
96
|
+
class FormAssociatedElement extends base {
|
|
97
|
+
/** @nocollapse */
|
|
98
|
+
static { this.formAssociated = true; }
|
|
99
|
+
get form() {
|
|
100
|
+
return this[internals].form;
|
|
101
|
+
}
|
|
102
|
+
get labels() {
|
|
103
|
+
return this[internals].labels;
|
|
104
|
+
}
|
|
105
|
+
// Use @property for the `name` and `disabled` properties to add them to the
|
|
106
|
+
// `observedAttributes` array and trigger `attributeChangedCallback()`.
|
|
107
|
+
//
|
|
108
|
+
// We don't use Lit's default getter/setter (`noAccessor: true`) because
|
|
109
|
+
// the attributes need to be updated synchronously to work with synchronous
|
|
110
|
+
// form APIs, and Lit updates attributes async by default.
|
|
111
|
+
get name() {
|
|
112
|
+
return this.getAttribute('name') ?? '';
|
|
113
|
+
}
|
|
114
|
+
set name(name) {
|
|
115
|
+
// Note: setting name to null or empty does not remove the attribute.
|
|
116
|
+
this.setAttribute('name', name);
|
|
117
|
+
// We don't need to call `requestUpdate()` since it's called synchronously
|
|
118
|
+
// in `attributeChangedCallback()`.
|
|
119
|
+
}
|
|
120
|
+
get disabled() {
|
|
121
|
+
return this.hasAttribute('disabled');
|
|
122
|
+
}
|
|
123
|
+
set disabled(disabled) {
|
|
124
|
+
this.toggleAttribute('disabled', disabled);
|
|
125
|
+
// We don't need to call `requestUpdate()` since it's called synchronously
|
|
126
|
+
// in `attributeChangedCallback()`.
|
|
127
|
+
}
|
|
128
|
+
attributeChangedCallback(name, old, value) {
|
|
129
|
+
// Manually `requestUpdate()` for `name` and `disabled` when their
|
|
130
|
+
// attribute or property changes.
|
|
131
|
+
// The properties update their attributes, so this callback is invoked
|
|
132
|
+
// immediately when the properties are set. We call `requestUpdate()` here
|
|
133
|
+
// instead of letting Lit set the properties from the attribute change.
|
|
134
|
+
// That would cause the properties to re-set the attribute and invoke this
|
|
135
|
+
// callback again in a loop. This leads to stale state when Lit tries to
|
|
136
|
+
// determine if a property changed or not.
|
|
137
|
+
if (name === 'name' || name === 'disabled') {
|
|
138
|
+
// Disabled's value is only false if the attribute is missing and null.
|
|
139
|
+
const oldValue = name === 'disabled' ? old !== null : old;
|
|
140
|
+
// Trigger a lit update when the attribute changes.
|
|
141
|
+
this.requestUpdate(name, oldValue);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
super.attributeChangedCallback(name, old, value);
|
|
145
|
+
}
|
|
146
|
+
requestUpdate(name, oldValue, options) {
|
|
147
|
+
super.requestUpdate(name, oldValue, options);
|
|
148
|
+
// If any properties change, update the form value, which may have changed
|
|
149
|
+
// as well.
|
|
150
|
+
// Update the form value synchronously in `requestUpdate()` rather than
|
|
151
|
+
// `update()` or `updated()`, which are async. This is necessary to ensure
|
|
152
|
+
// that form data is updated in time for synchronous event listeners.
|
|
153
|
+
this[internals].setFormValue(this[getFormValue](), this[getFormState]());
|
|
154
|
+
}
|
|
155
|
+
[getFormValue]() {
|
|
156
|
+
// Closure does not allow abstract symbol members, so a default
|
|
157
|
+
// implementation is needed.
|
|
158
|
+
throw new Error(`Implement [getFormValue] in ${this.constructor.name}`);
|
|
159
|
+
}
|
|
160
|
+
[getFormState]() {
|
|
161
|
+
return this[getFormValue]();
|
|
162
|
+
}
|
|
163
|
+
formDisabledCallback(disabled) {
|
|
164
|
+
this.disabled = disabled;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
__decorate([
|
|
168
|
+
property({ noAccessor: true })
|
|
169
|
+
], FormAssociatedElement.prototype, "name", null);
|
|
170
|
+
__decorate([
|
|
171
|
+
property({ type: Boolean, noAccessor: true })
|
|
172
|
+
], FormAssociatedElement.prototype, "disabled", null);
|
|
173
|
+
return FormAssociatedElement;
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=form-associated.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form-associated.js","sourceRoot":"","sources":["form-associated.ts"],"names":[],"mappings":"AAAA;;;;GAIG;;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,SAAS,EAAwB,MAAM,wBAAwB,CAAC;AA0GzE;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AAEnD;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6EG;AACH,MAAM,UAAU,mBAAmB,CAEjC,IAAO;IACP,MAAe,qBAAsB,SAAQ,IAAI;QAC/C,kBAAkB;iBACF,mBAAc,GAAG,IAAI,CAAC;QAEtC,IAAI,IAAI;YACN,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC;QAC9B,CAAC;QAED,IAAI,MAAM;YACR,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC;QAChC,CAAC;QAED,4EAA4E;QAC5E,uEAAuE;QACvE,EAAE;QACF,wEAAwE;QACxE,2EAA2E;QAC3E,0DAA0D;QAE1D,IAAI,IAAI;YACN,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QACzC,CAAC;QACD,IAAI,IAAI,CAAC,IAAY;YACnB,qEAAqE;YACrE,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YAChC,0EAA0E;YAC1E,mCAAmC;QACrC,CAAC;QAGD,IAAI,QAAQ;YACV,OAAO,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;QACvC,CAAC;QACD,IAAI,QAAQ,CAAC,QAAiB;YAC5B,IAAI,CAAC,eAAe,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;YAC3C,0EAA0E;YAC1E,mCAAmC;QACrC,CAAC;QAEQ,wBAAwB,CAC/B,IAAY,EACZ,GAAkB,EAClB,KAAoB;YAEpB,kEAAkE;YAClE,iCAAiC;YACjC,sEAAsE;YACtE,0EAA0E;YAC1E,uEAAuE;YACvE,0EAA0E;YAC1E,wEAAwE;YACxE,0CAA0C;YAC1C,IAAI,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;gBAC3C,uEAAuE;gBACvE,MAAM,QAAQ,GAAG,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC;gBAC1D,mDAAmD;gBACnD,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;gBACnC,OAAO;YACT,CAAC;YAED,KAAK,CAAC,wBAAwB,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;QACnD,CAAC;QAEQ,aAAa,CACpB,IAAkB,EAClB,QAAkB,EAClB,OAA6B;YAE7B,KAAK,CAAC,aAAa,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;YAC7C,0EAA0E;YAC1E,WAAW;YACX,uEAAuE;YACvE,0EAA0E;YAC1E,qEAAqE;YACrE,IAAI,CAAC,SAAS,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,EAAE,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;QAC3E,CAAC;QAED,CAAC,YAAY,CAAC;YACZ,+DAA+D;YAC/D,4BAA4B;YAC5B,MAAM,IAAI,KAAK,CAAC,+BAA+B,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;QAC1E,CAAC;QAED,CAAC,YAAY,CAAC;YACZ,OAAO,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC;QAC9B,CAAC;QAED,oBAAoB,CAAC,QAAiB;YACpC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAC3B,CAAC;;IAtED;QADC,QAAQ,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;qDAG9B;IASD;QADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;yDAG7C;IAmEH,OAAO,qBAAqB,CAAC;AAC/B,CAAC","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { LitElement, PropertyDeclaration } from 'lit';\nimport { property } from 'lit/decorators.js';\n\nimport { internals, WithElementInternals } from './element-internals.js';\nimport { MixinBase, MixinReturn } from './mixin.js';\n\n/**\n * A form-associated element.\n *\n * IMPORTANT: Requires declares for lit-analyzer\n * @example\n * ```ts\n * const base = mixinFormAssociated(mixinElementInternals(LitElement));\n * class MyControl extends base {\n * // Writable mixin properties for lit-html binding, needed for lit-analyzer\n * declare disabled: boolean;\n * declare name: string;\n * }\n * ```\n */\nexport interface FormAssociated {\n /**\n * The associated form element with which this element's value will submit.\n */\n readonly form: HTMLFormElement | null;\n\n /**\n * The labels this element is associated with.\n */\n readonly labels: NodeList;\n\n /**\n * The HTML name to use in form submission.\n */\n name: string;\n\n /**\n * Whether or not the element is disabled.\n */\n disabled: boolean;\n\n /**\n * Gets the current form value of a component.\n *\n * @return The current form value.\n */\n [getFormValue](): FormValue | null;\n\n /**\n * Gets the current form state of a component. Defaults to the component's\n * `[formValue]`.\n *\n * Use this when the state of an element is different from its value, such as\n * checkboxes (internal boolean state and a user string value).\n *\n * @return The current form state, defaults to the form value.\n */\n [getFormState](): FormValue | null;\n\n /**\n * A callback for when a form component should be disabled or enabled. This\n * can be called in a variety of situations, such as disabled `<fieldset>`s.\n *\n * @param disabled Whether or not the form control should be disabled.\n */\n formDisabledCallback(disabled: boolean): void;\n\n /**\n * A callback for when the form requests to reset its value. Typically, the\n * default value that is reset is represented in the attribute of an element.\n *\n * This means the attribute used for the value should not update as the value\n * changes. For example, a checkbox should not change its default `checked`\n * attribute when selected. Ensure form values do not reflect.\n */\n formResetCallback(): void;\n\n /**\n * A callback for when the form restores the state of a component. For\n * example, when a page is reloaded or forms are autofilled.\n *\n * @param state The state to restore, or null to reset the form control's\n * value.\n * @param reason The reason state was restored, either `'restore'` or\n * `'autocomplete'`.\n */\n formStateRestoreCallback(\n state: FormRestoreState | null,\n reason: FormRestoreReason,\n ): void;\n\n /**\n * An optional callback for when the associated form changes.\n *\n * @param form The new associated form, or `null` if there is none.\n */\n formAssociatedCallback?(form: HTMLFormElement | null): void;\n}\n\n/**\n * The constructor of a `FormAssociated` element.\n */\nexport interface FormAssociatedConstructor {\n /**\n * Indicates that an element is participating in form association.\n */\n readonly formAssociated: true;\n}\n\n/**\n * A symbol property to retrieve the form value for an element.\n */\nexport const getFormValue = Symbol('getFormValue');\n\n/**\n * A symbol property to retrieve the form state for an element.\n */\nexport const getFormState = Symbol('getFormState');\n\n/**\n * Mixes in form-associated behavior for a class. This allows an element to add\n * values to `<form>` elements.\n *\n * Implementing classes should provide a `[formValue]` to return the current\n * value of the element, as well as reset and restore callbacks.\n *\n * @example\n * ```ts\n * const base = mixinFormAssociated(mixinElementInternals(LitElement));\n *\n * class MyControl extends base {\n * \\@property()\n * value = '';\n *\n * override [getFormValue]() {\n * return this.value;\n * }\n *\n * override formResetCallback() {\n * const defaultValue = this.getAttribute('value');\n * this.value = defaultValue;\n * }\n *\n * override formStateRestoreCallback(state: string) {\n * this.value = state;\n * }\n * }\n * ```\n *\n * Elements may optionally provide a `[formState]` if their values do not\n * represent the state of the component.\n *\n * @example\n * ```ts\n * const base = mixinFormAssociated(mixinElementInternals(LitElement));\n *\n * class MyCheckbox extends base {\n * \\@property()\n * value = 'on';\n *\n * \\@property({type: Boolean})\n * checked = false;\n *\n * override [getFormValue]() {\n * return this.checked ? this.value : null;\n * }\n *\n * override [getFormState]() {\n * return String(this.checked);\n * }\n *\n * override formResetCallback() {\n * const defaultValue = this.hasAttribute('checked');\n * this.checked = defaultValue;\n * }\n *\n * override formStateRestoreCallback(state: string) {\n * this.checked = Boolean(state);\n * }\n * }\n * ```\n *\n * IMPORTANT: Requires declares for lit-analyzer\n * @example\n * ```ts\n * const base = mixinFormAssociated(mixinElementInternals(LitElement));\n * class MyControl extends base {\n * // Writable mixin properties for lit-html binding, needed for lit-analyzer\n * declare disabled: boolean;\n * declare name: string;\n * }\n * ```\n *\n * @param base The class to mix functionality into. The base class must use\n * `mixinElementInternals()`.\n * @return The provided class with `FormAssociated` mixed in.\n */\nexport function mixinFormAssociated<\n T extends MixinBase<LitElement & WithElementInternals>,\n>(base: T): MixinReturn<T & FormAssociatedConstructor, FormAssociated> {\n abstract class FormAssociatedElement extends base implements FormAssociated {\n /** @nocollapse */\n static readonly formAssociated = true;\n\n get form() {\n return this[internals].form;\n }\n\n get labels() {\n return this[internals].labels;\n }\n\n // Use @property for the `name` and `disabled` properties to add them to the\n // `observedAttributes` array and trigger `attributeChangedCallback()`.\n //\n // We don't use Lit's default getter/setter (`noAccessor: true`) because\n // the attributes need to be updated synchronously to work with synchronous\n // form APIs, and Lit updates attributes async by default.\n @property({ noAccessor: true })\n get name() {\n return this.getAttribute('name') ?? '';\n }\n set name(name: string) {\n // Note: setting name to null or empty does not remove the attribute.\n this.setAttribute('name', name);\n // We don't need to call `requestUpdate()` since it's called synchronously\n // in `attributeChangedCallback()`.\n }\n\n @property({ type: Boolean, noAccessor: true })\n get disabled() {\n return this.hasAttribute('disabled');\n }\n set disabled(disabled: boolean) {\n this.toggleAttribute('disabled', disabled);\n // We don't need to call `requestUpdate()` since it's called synchronously\n // in `attributeChangedCallback()`.\n }\n\n override attributeChangedCallback(\n name: string,\n old: string | null,\n value: string | null,\n ) {\n // Manually `requestUpdate()` for `name` and `disabled` when their\n // attribute or property changes.\n // The properties update their attributes, so this callback is invoked\n // immediately when the properties are set. We call `requestUpdate()` here\n // instead of letting Lit set the properties from the attribute change.\n // That would cause the properties to re-set the attribute and invoke this\n // callback again in a loop. This leads to stale state when Lit tries to\n // determine if a property changed or not.\n if (name === 'name' || name === 'disabled') {\n // Disabled's value is only false if the attribute is missing and null.\n const oldValue = name === 'disabled' ? old !== null : old;\n // Trigger a lit update when the attribute changes.\n this.requestUpdate(name, oldValue);\n return;\n }\n\n super.attributeChangedCallback(name, old, value);\n }\n\n override requestUpdate(\n name?: PropertyKey,\n oldValue?: unknown,\n options?: PropertyDeclaration,\n ) {\n super.requestUpdate(name, oldValue, options);\n // If any properties change, update the form value, which may have changed\n // as well.\n // Update the form value synchronously in `requestUpdate()` rather than\n // `update()` or `updated()`, which are async. This is necessary to ensure\n // that form data is updated in time for synchronous event listeners.\n this[internals].setFormValue(this[getFormValue](), this[getFormState]());\n }\n\n [getFormValue](): FormValue | null {\n // Closure does not allow abstract symbol members, so a default\n // implementation is needed.\n throw new Error(`Implement [getFormValue] in ${this.constructor.name}`);\n }\n\n [getFormState](): FormValue | null {\n return this[getFormValue]();\n }\n\n formDisabledCallback(disabled: boolean) {\n this.disabled = disabled;\n }\n\n abstract formResetCallback(): void;\n\n abstract formStateRestoreCallback(\n state: FormRestoreState | null,\n reason: FormRestoreReason,\n ): void;\n }\n\n return FormAssociatedElement;\n}\n\n/**\n * A value that can be provided for form submission and state.\n */\nexport type FormValue = File | string | FormData;\n\n/**\n * A value to be restored for a component's form value. If a component's form\n * state is a `FormData` object, its entry list of name and values will be\n * provided.\n */\nexport type FormRestoreState =\n | File\n | string\n | Array<[string, FormDataEntryValue]>;\n\n/**\n * The reason a form component is being restored for, either `'restore'` for\n * browser restoration or `'autocomplete'` for restoring user values.\n */\nexport type FormRestoreReason = 'restore' | 'autocomplete';\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2023 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* The base class for a mixin with an optional expected base class type.
|
|
8
|
+
*
|
|
9
|
+
* @template ExpectedBase Optional expected base class type, such as
|
|
10
|
+
* `LitElement`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* interface Foo {
|
|
15
|
+
* isFoo: boolean;
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* function mixinFoo<T extends MixinBase>(base: T): MixinReturn<T, Foo> {
|
|
19
|
+
* // Mixins must be `abstract`
|
|
20
|
+
* abstract class FooImpl extends base implements Foo {
|
|
21
|
+
* isFoo = true;
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* return FooImpl;
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export type MixinBase<ExpectedBase = object> = abstract new (...args: any[]) => ExpectedBase;
|
|
29
|
+
/**
|
|
30
|
+
* The return value of a mixin.
|
|
31
|
+
*
|
|
32
|
+
* @template MixinBase The generic that extends `MixinBase` used for the mixin's
|
|
33
|
+
* base class argument.
|
|
34
|
+
* @template MixinClass Optional interface of fuctionality that was mixed in.
|
|
35
|
+
* Omit if no additional APIs were added (such as purely overriding base
|
|
36
|
+
* class functionality).
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* interface Foo {
|
|
41
|
+
* isFoo: boolean;
|
|
42
|
+
* }
|
|
43
|
+
*
|
|
44
|
+
* // Mixins must be `abstract`
|
|
45
|
+
* function mixinFoo<T extends MixinBase>(base: T): MixinReturn<T, Foo> {
|
|
46
|
+
* abstract class FooImpl extends base implements Foo {
|
|
47
|
+
* isFoo = true;
|
|
48
|
+
* }
|
|
49
|
+
*
|
|
50
|
+
* return FooImpl;
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export type MixinReturn<MixinBase, MixinClass = object> = (abstract new (...args: any[]) => MixinClass) & MixinBase;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mixin.js","sourceRoot":"","sources":["mixin.ts"],"names":[],"mappings":"AAAA;;;;GAIG","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * The base class for a mixin with an optional expected base class type.\n *\n * @template ExpectedBase Optional expected base class type, such as\n * `LitElement`.\n *\n * @example\n * ```ts\n * interface Foo {\n * isFoo: boolean;\n * }\n *\n * function mixinFoo<T extends MixinBase>(base: T): MixinReturn<T, Foo> {\n * // Mixins must be `abstract`\n * abstract class FooImpl extends base implements Foo {\n * isFoo = true;\n * }\n *\n * return FooImpl;\n * }\n * ```\n */\nexport type MixinBase<ExpectedBase = object> = abstract new (\n // Mixins must have a constructor with `...args: any[]`\n // tslint:disable-next-line:no-any\n ...args: any[]\n) => ExpectedBase;\n\n/**\n * The return value of a mixin.\n *\n * @template MixinBase The generic that extends `MixinBase` used for the mixin's\n * base class argument.\n * @template MixinClass Optional interface of fuctionality that was mixed in.\n * Omit if no additional APIs were added (such as purely overriding base\n * class functionality).\n *\n * @example\n * ```ts\n * interface Foo {\n * isFoo: boolean;\n * }\n *\n * // Mixins must be `abstract`\n * function mixinFoo<T extends MixinBase>(base: T): MixinReturn<T, Foo> {\n * abstract class FooImpl extends base implements Foo {\n * isFoo = true;\n * }\n *\n * return FooImpl;\n * }\n * ```\n */\nexport type MixinReturn<MixinBase, MixinClass = object> =\n // Mixins must have a constructor with `...args: any[]`\n // tslint:disable-next-line:no-any\n (abstract new (...args: any[]) => MixinClass) & MixinBase;\n"]}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2023 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { LitElement } from 'lit';
|
|
7
|
+
import { ConstraintValidation } from './constraint-validation.js';
|
|
8
|
+
import { WithElementInternals } from './element-internals.js';
|
|
9
|
+
import { MixinBase, MixinReturn } from './mixin.js';
|
|
10
|
+
/**
|
|
11
|
+
* A constraint validation element that has a callback for when the element
|
|
12
|
+
* should report validity styles and error messages to the user.
|
|
13
|
+
*
|
|
14
|
+
* This is commonly used in text-field-like controls that display error styles
|
|
15
|
+
* and error messages.
|
|
16
|
+
*/
|
|
17
|
+
export interface OnReportValidity extends ConstraintValidation {
|
|
18
|
+
/**
|
|
19
|
+
* A callback that is invoked when validity should be reported. Components
|
|
20
|
+
* that can display their own error state can use this and update their
|
|
21
|
+
* styles.
|
|
22
|
+
*
|
|
23
|
+
* If an invalid event is provided, the element is invalid. If `null`, the
|
|
24
|
+
* element is valid.
|
|
25
|
+
*
|
|
26
|
+
* The invalid event's `preventDefault()` may be called to stop the platform
|
|
27
|
+
* popup from displaying.
|
|
28
|
+
*
|
|
29
|
+
* @param invalidEvent The `invalid` event dispatched when an element is
|
|
30
|
+
* invalid, or `null` if the element is valid.
|
|
31
|
+
*/
|
|
32
|
+
[onReportValidity](invalidEvent: Event | null): void;
|
|
33
|
+
formAssociatedCallback(form: HTMLFormElement | null): void;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A symbol property used for a callback when validity has been reported.
|
|
37
|
+
*/
|
|
38
|
+
export declare const onReportValidity: unique symbol;
|
|
39
|
+
/**
|
|
40
|
+
* Mixes in a callback for constraint validation when validity should be
|
|
41
|
+
* styled and reported to the user.
|
|
42
|
+
*
|
|
43
|
+
* This is commonly used in text-field-like controls that display error styles
|
|
44
|
+
* and error messages.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* const baseClass = mixinOnReportValidity(
|
|
49
|
+
* mixinConstraintValidation(
|
|
50
|
+
* mixinFormAssociated(mixinElementInternals(LitElement)),
|
|
51
|
+
* ),
|
|
52
|
+
* );
|
|
53
|
+
*
|
|
54
|
+
* class MyField extends baseClass {
|
|
55
|
+
* \@property({type: Boolean}) error = false;
|
|
56
|
+
* \@property() errorMessage = '';
|
|
57
|
+
*
|
|
58
|
+
* [onReportValidity](invalidEvent: Event | null) {
|
|
59
|
+
* this.error = !!invalidEvent;
|
|
60
|
+
* this.errorMessage = this.validationMessage;
|
|
61
|
+
*
|
|
62
|
+
* // Optionally prevent platform popup from displaying
|
|
63
|
+
* invalidEvent?.preventDefault();
|
|
64
|
+
* }
|
|
65
|
+
* }
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @param base The class to mix functionality into.
|
|
69
|
+
* @return The provided class with `OnReportValidity` mixed in.
|
|
70
|
+
*/
|
|
71
|
+
export declare function mixinOnReportValidity<T extends MixinBase<LitElement & ConstraintValidation & WithElementInternals>>(base: T): MixinReturn<T, OnReportValidity>;
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2023 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { isServer } from 'lit';
|
|
7
|
+
import { internals } from './element-internals.js';
|
|
8
|
+
/**
|
|
9
|
+
* A symbol property used for a callback when validity has been reported.
|
|
10
|
+
*/
|
|
11
|
+
export const onReportValidity = Symbol('onReportValidity');
|
|
12
|
+
// Private symbol members, used to avoid name clashing.
|
|
13
|
+
const privateCleanupFormListeners = Symbol('privateCleanupFormListeners');
|
|
14
|
+
const privateDoNotReportInvalid = Symbol('privateDoNotReportInvalid');
|
|
15
|
+
const privateIsSelfReportingValidity = Symbol('privateIsSelfReportingValidity');
|
|
16
|
+
const privateCallOnReportValidity = Symbol('privateCallOnReportValidity');
|
|
17
|
+
/**
|
|
18
|
+
* Mixes in a callback for constraint validation when validity should be
|
|
19
|
+
* styled and reported to the user.
|
|
20
|
+
*
|
|
21
|
+
* This is commonly used in text-field-like controls that display error styles
|
|
22
|
+
* and error messages.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* const baseClass = mixinOnReportValidity(
|
|
27
|
+
* mixinConstraintValidation(
|
|
28
|
+
* mixinFormAssociated(mixinElementInternals(LitElement)),
|
|
29
|
+
* ),
|
|
30
|
+
* );
|
|
31
|
+
*
|
|
32
|
+
* class MyField extends baseClass {
|
|
33
|
+
* \@property({type: Boolean}) error = false;
|
|
34
|
+
* \@property() errorMessage = '';
|
|
35
|
+
*
|
|
36
|
+
* [onReportValidity](invalidEvent: Event | null) {
|
|
37
|
+
* this.error = !!invalidEvent;
|
|
38
|
+
* this.errorMessage = this.validationMessage;
|
|
39
|
+
*
|
|
40
|
+
* // Optionally prevent platform popup from displaying
|
|
41
|
+
* invalidEvent?.preventDefault();
|
|
42
|
+
* }
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @param base The class to mix functionality into.
|
|
47
|
+
* @return The provided class with `OnReportValidity` mixed in.
|
|
48
|
+
*/
|
|
49
|
+
export function mixinOnReportValidity(base) {
|
|
50
|
+
var _a, _b, _c;
|
|
51
|
+
class OnReportValidityElement extends base {
|
|
52
|
+
// Mixins must have a constructor with `...args: any[]`
|
|
53
|
+
// tslint:disable-next-line:no-any
|
|
54
|
+
constructor(...args) {
|
|
55
|
+
super(...args);
|
|
56
|
+
/**
|
|
57
|
+
* Used to clean up event listeners when a new form is associated.
|
|
58
|
+
*/
|
|
59
|
+
this[_a] = new AbortController();
|
|
60
|
+
/**
|
|
61
|
+
* Used to determine if an invalid event should report validity. Invalid
|
|
62
|
+
* events from `checkValidity()` do not trigger reporting.
|
|
63
|
+
*/
|
|
64
|
+
this[_b] = false;
|
|
65
|
+
/**
|
|
66
|
+
* Used to determine if the control is reporting validity from itself, or
|
|
67
|
+
* if a `<form>` is causing the validity report. Forms have different
|
|
68
|
+
* control focusing behavior.
|
|
69
|
+
*/
|
|
70
|
+
this[_c] = false;
|
|
71
|
+
if (isServer) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
this.addEventListener('invalid', invalidEvent => {
|
|
75
|
+
// Listen for invalid events dispatched by a `<form>` when it tries to
|
|
76
|
+
// submit and the element is invalid. We ignore events dispatched when
|
|
77
|
+
// calling `checkValidity()` as well as untrusted events, since the
|
|
78
|
+
// `reportValidity()` and `<form>`-dispatched events are always
|
|
79
|
+
// trusted.
|
|
80
|
+
if (this[privateDoNotReportInvalid] || !invalidEvent.isTrusted) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
this.addEventListener('invalid', () => {
|
|
84
|
+
// A normal bubbling phase event listener. By adding it here, we
|
|
85
|
+
// ensure it's the last event listener that is called during the
|
|
86
|
+
// bubbling phase.
|
|
87
|
+
this[privateCallOnReportValidity](invalidEvent);
|
|
88
|
+
}, { once: true });
|
|
89
|
+
}, {
|
|
90
|
+
// Listen during the capture phase, which will happen before the
|
|
91
|
+
// bubbling phase. That way, we can add a final event listener that
|
|
92
|
+
// will run after other event listeners, and we can check if it was
|
|
93
|
+
// default prevented. This works because invalid does not bubble.
|
|
94
|
+
capture: true,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
checkValidity() {
|
|
98
|
+
this[privateDoNotReportInvalid] = true;
|
|
99
|
+
const valid = super.checkValidity();
|
|
100
|
+
this[privateDoNotReportInvalid] = false;
|
|
101
|
+
return valid;
|
|
102
|
+
}
|
|
103
|
+
reportValidity() {
|
|
104
|
+
this[privateIsSelfReportingValidity] = true;
|
|
105
|
+
const valid = super.reportValidity();
|
|
106
|
+
// Constructor's invalid listener will handle reporting invalid events.
|
|
107
|
+
if (valid) {
|
|
108
|
+
this[privateCallOnReportValidity](null);
|
|
109
|
+
}
|
|
110
|
+
this[privateIsSelfReportingValidity] = false;
|
|
111
|
+
return valid;
|
|
112
|
+
}
|
|
113
|
+
[(_a = privateCleanupFormListeners, _b = privateDoNotReportInvalid, _c = privateIsSelfReportingValidity, privateCallOnReportValidity)](invalidEvent) {
|
|
114
|
+
// Since invalid events do not bubble to parent listeners, and because
|
|
115
|
+
// our invalid listeners are added lazily after other listeners, we can
|
|
116
|
+
// reliably read `defaultPrevented` synchronously without worrying
|
|
117
|
+
// about waiting for another listener that could cancel it.
|
|
118
|
+
const wasCanceled = invalidEvent?.defaultPrevented;
|
|
119
|
+
if (wasCanceled) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
this[onReportValidity](invalidEvent);
|
|
123
|
+
// If an implementation calls invalidEvent.preventDefault() to stop the
|
|
124
|
+
// platform popup from displaying, focusing is also prevented, so we need
|
|
125
|
+
// to manually focus.
|
|
126
|
+
const implementationCanceledFocus = !wasCanceled && invalidEvent?.defaultPrevented;
|
|
127
|
+
if (!implementationCanceledFocus) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
// The control should be focused when:
|
|
131
|
+
// - `control.reportValidity()` is called (self-reporting).
|
|
132
|
+
// - a form is reporting validity for its controls and this is the first
|
|
133
|
+
// invalid control.
|
|
134
|
+
if (this[privateIsSelfReportingValidity] ||
|
|
135
|
+
isFirstInvalidControlInForm(this[internals].form, this)) {
|
|
136
|
+
this.focus();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
[onReportValidity](_invalidEvent) {
|
|
140
|
+
throw new Error(`Implement [onReportValidity] in ${this.constructor.name}`);
|
|
141
|
+
}
|
|
142
|
+
formAssociatedCallback(form) {
|
|
143
|
+
// can't use super.formAssociatedCallback?.() due to closure
|
|
144
|
+
if (super.formAssociatedCallback) {
|
|
145
|
+
super.formAssociatedCallback(form);
|
|
146
|
+
}
|
|
147
|
+
// Clean up previous form listeners.
|
|
148
|
+
this[privateCleanupFormListeners].abort();
|
|
149
|
+
if (!form) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
this[privateCleanupFormListeners] = new AbortController();
|
|
153
|
+
// Add a listener that fires when the form runs constraint validation and
|
|
154
|
+
// the control is valid, so that it may remove its error styles.
|
|
155
|
+
//
|
|
156
|
+
// This happens on `form.reportValidity()` and `form.requestSubmit()`
|
|
157
|
+
// (both when the submit fails and passes).
|
|
158
|
+
addFormReportValidListener(this, form, () => {
|
|
159
|
+
this[privateCallOnReportValidity](null);
|
|
160
|
+
}, this[privateCleanupFormListeners].signal);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return OnReportValidityElement;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Add a listener that fires when a form runs constraint validation on a control
|
|
167
|
+
* and it is valid. This is needed to clear previously invalid styles.
|
|
168
|
+
*
|
|
169
|
+
* @param control The control of the form to listen for valid events.
|
|
170
|
+
* @param form The control's form that can run constraint validation.
|
|
171
|
+
* @param onControlValid A listener that is called when the form runs constraint
|
|
172
|
+
* validation and the control is valid.
|
|
173
|
+
* @param cleanup A cleanup signal to remove the listener.
|
|
174
|
+
*/
|
|
175
|
+
function addFormReportValidListener(control, form, onControlValid, cleanup) {
|
|
176
|
+
const validateHooks = getFormValidateHooks(form);
|
|
177
|
+
// When a form validates its controls, check if an invalid event is dispatched
|
|
178
|
+
// on the control. If it is not, then inform the control to report its valid
|
|
179
|
+
// state.
|
|
180
|
+
let controlFiredInvalid = false;
|
|
181
|
+
let cleanupInvalidListener;
|
|
182
|
+
let isNextSubmitFromHook = false;
|
|
183
|
+
validateHooks.addEventListener('before', () => {
|
|
184
|
+
isNextSubmitFromHook = true;
|
|
185
|
+
cleanupInvalidListener = new AbortController();
|
|
186
|
+
controlFiredInvalid = false;
|
|
187
|
+
control.addEventListener('invalid', () => {
|
|
188
|
+
controlFiredInvalid = true;
|
|
189
|
+
}, {
|
|
190
|
+
signal: cleanupInvalidListener.signal,
|
|
191
|
+
});
|
|
192
|
+
}, { signal: cleanup });
|
|
193
|
+
validateHooks.addEventListener('after', () => {
|
|
194
|
+
isNextSubmitFromHook = false;
|
|
195
|
+
cleanupInvalidListener?.abort();
|
|
196
|
+
if (controlFiredInvalid) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
onControlValid();
|
|
200
|
+
}, { signal: cleanup });
|
|
201
|
+
// The above hooks handle imperatively submitting the form, but not
|
|
202
|
+
// declaratively submitting the form. This happens when:
|
|
203
|
+
// 1. A non-custom element `<button type="submit">` is clicked.
|
|
204
|
+
// 2. Enter is pressed on a non-custom element text editable `<input>`.
|
|
205
|
+
form.addEventListener('submit', () => {
|
|
206
|
+
// This submit was from `form.requestSubmit()`, which already calls the
|
|
207
|
+
// listener.
|
|
208
|
+
if (isNextSubmitFromHook) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
onControlValid();
|
|
212
|
+
}, {
|
|
213
|
+
signal: cleanup,
|
|
214
|
+
});
|
|
215
|
+
// Note: it is a known limitation that we cannot detect if a form tries to
|
|
216
|
+
// submit declaratively, but fails to do so because an unrelated sibling
|
|
217
|
+
// control failed its constraint validation.
|
|
218
|
+
//
|
|
219
|
+
// Since we cannot detect when that happens, a previously invalid control may
|
|
220
|
+
// not clear its error styling when it becomes valid again.
|
|
221
|
+
//
|
|
222
|
+
// To work around this, call `form.reportValidity()` when submitting a form
|
|
223
|
+
// declaratively. This can be down on the `<button type="submit">`'s click or
|
|
224
|
+
// the text editable `<input>`'s 'Enter' keydown.
|
|
225
|
+
}
|
|
226
|
+
const FORM_VALIDATE_HOOKS = new WeakMap();
|
|
227
|
+
/**
|
|
228
|
+
* Get a hooks `EventTarget` that dispatches 'before' and 'after' events that
|
|
229
|
+
* fire before a form runs constraint validation and immediately after it
|
|
230
|
+
* finishes running constraint validation on its controls.
|
|
231
|
+
*
|
|
232
|
+
* This happens during `form.reportValidity()` and `form.requestSubmit()`.
|
|
233
|
+
*
|
|
234
|
+
* @param form The form to get or set up hooks for.
|
|
235
|
+
* @return A hooks `EventTarget` to add listeners to.
|
|
236
|
+
*/
|
|
237
|
+
function getFormValidateHooks(form) {
|
|
238
|
+
if (!FORM_VALIDATE_HOOKS.has(form)) {
|
|
239
|
+
// Patch form methods to add event listener hooks. These are needed to react
|
|
240
|
+
// to form behaviors that do not dispatch events, such as a form asking its
|
|
241
|
+
// controls to report their validity.
|
|
242
|
+
//
|
|
243
|
+
// We should only patch the methods once, since multiple controls and other
|
|
244
|
+
// forces may want to patch this method. We cannot reliably clean it up if
|
|
245
|
+
// there are multiple patched and re-patched methods referring holding
|
|
246
|
+
// references to each other.
|
|
247
|
+
//
|
|
248
|
+
// Instead, we never clean up the patch but add and clean up event listeners
|
|
249
|
+
// added to the hooks after the patch.
|
|
250
|
+
const hooks = new EventTarget();
|
|
251
|
+
FORM_VALIDATE_HOOKS.set(form, hooks);
|
|
252
|
+
// Add hooks to support notifying before and after a form has run constraint
|
|
253
|
+
// validation on its controls.
|
|
254
|
+
// Note: `form.submit()` does not run constraint validation per spec.
|
|
255
|
+
for (const methodName of ['reportValidity', 'requestSubmit']) {
|
|
256
|
+
const superMethod = form[methodName];
|
|
257
|
+
form[methodName] = function (...args) {
|
|
258
|
+
hooks.dispatchEvent(new Event('before'));
|
|
259
|
+
const result = Reflect.apply(superMethod, this, args);
|
|
260
|
+
hooks.dispatchEvent(new Event('after'));
|
|
261
|
+
return result;
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return FORM_VALIDATE_HOOKS.get(form);
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Checks if a control is the first invalid control in a form.
|
|
269
|
+
*
|
|
270
|
+
* @param form The control's form. When `null`, the control doesn't have a form
|
|
271
|
+
* and the method returns true.
|
|
272
|
+
* @param control The control to check.
|
|
273
|
+
* @return True if there is no form or if the control is the form's first
|
|
274
|
+
* invalid control.
|
|
275
|
+
*/
|
|
276
|
+
function isFirstInvalidControlInForm(form, control) {
|
|
277
|
+
if (!form) {
|
|
278
|
+
return true;
|
|
279
|
+
}
|
|
280
|
+
let firstInvalidControl;
|
|
281
|
+
for (const element of Array.from(form.elements)) {
|
|
282
|
+
if (element.matches(':invalid')) {
|
|
283
|
+
firstInvalidControl = element;
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return firstInvalidControl === control;
|
|
288
|
+
}
|
|
289
|
+
//# sourceMappingURL=on-report-validity.js.map
|