@redvars/peacock 4.5.1 → 4.6.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/dist/{BaseField-BbOj212R.js → BaseField-DOCmylob.js} +16 -3
- package/dist/BaseField-DOCmylob.js.map +1 -0
- package/dist/accordion.js +1 -1
- package/dist/activation-gate-D4IpmwyD.js +23 -0
- package/dist/activation-gate-D4IpmwyD.js.map +1 -0
- package/dist/avatar-group.js +2 -1
- package/dist/avatar-group.js.map +1 -1
- package/dist/avatar.js +3 -0
- package/dist/avatar.js.map +1 -1
- package/dist/{base-button-BJMGMcMv.js → base-button-9tGu5RSC.js} +30 -10
- package/dist/base-button-9tGu5RSC.js.map +1 -0
- package/dist/button-group.js +5 -3
- package/dist/button-group.js.map +1 -1
- package/dist/button.js +12 -16
- package/dist/button.js.map +1 -1
- package/dist/calendar-column-view.js +4 -4
- package/dist/{calendar-drag-IXMPZrTN.js → calendar-drag-DdJwSpEz.js} +2 -2
- package/dist/{calendar-drag-IXMPZrTN.js.map → calendar-drag-DdJwSpEz.js.map} +1 -1
- package/dist/{calendar-event-BQChlMXy.js → calendar-event-BvbYZHx1.js} +2 -2
- package/dist/{calendar-event-BQChlMXy.js.map → calendar-event-BvbYZHx1.js.map} +1 -1
- package/dist/calendar-month-view.js +65 -14
- package/dist/calendar-month-view.js.map +1 -1
- package/dist/calendar-timeline.js +9 -4
- package/dist/calendar-timeline.js.map +1 -1
- package/dist/calendar.js +21 -6
- package/dist/calendar.js.map +1 -1
- package/dist/card.js +29 -16
- package/dist/card.js.map +1 -1
- package/dist/chart-doughnut.js +3 -1
- package/dist/chart-doughnut.js.map +1 -1
- package/dist/chart-pie.js +9 -1
- package/dist/chart-pie.js.map +1 -1
- package/dist/chip-set.js +1 -1
- package/dist/chip.js +10 -19
- package/dist/chip.js.map +1 -1
- package/dist/color-field.js +4 -1
- package/dist/color-field.js.map +1 -1
- package/dist/currency-field.js +4 -1
- package/dist/currency-field.js.map +1 -1
- package/dist/custom-elements-jsdocs.json +26 -20
- package/dist/custom-elements.json +755 -90
- package/dist/{datasource-OwvH7SVq.js → datasource-DxEA6jHW.js} +6 -4
- package/dist/datasource-DxEA6jHW.js.map +1 -0
- package/dist/{date-cfPx3alz.js → date-DPQOY8Zd.js} +2 -2
- package/dist/{date-cfPx3alz.js.map → date-DPQOY8Zd.js.map} +1 -1
- package/dist/date-field.js +8 -5
- package/dist/date-field.js.map +1 -1
- package/dist/date-picker.js +2 -2
- package/dist/date-range-field.js +8 -5
- package/dist/date-range-field.js.map +1 -1
- package/dist/datetime-field.js +7 -4
- package/dist/datetime-field.js.map +1 -1
- package/dist/diagram-controls.js +1 -1
- package/dist/{throttle-SQ9t-HL7.js → dispatch-event-utils-DfgqVBK8.js} +2 -24
- package/dist/dispatch-event-utils-DfgqVBK8.js.map +1 -0
- package/dist/{form-submitter-beG1CXAn.js → dispatch-hooks-J_godlHh.js} +2 -87
- package/dist/dispatch-hooks-J_godlHh.js.map +1 -0
- package/dist/dropdown-button.js +11 -7
- package/dist/dropdown-button.js.map +1 -1
- package/dist/{event-manager-KGMT2x2Q.js → event-manager-DYfeN3VE.js} +3 -3
- package/dist/{event-manager-KGMT2x2Q.js.map → event-manager-DYfeN3VE.js.map} +1 -1
- package/dist/fab.js +15 -19
- package/dist/fab.js.map +1 -1
- package/dist/filter-bar.js +3 -3
- package/dist/form-submission-h40coUI8.js +13 -0
- package/dist/form-submission-h40coUI8.js.map +1 -0
- package/dist/form-submitter-BIFqZ0wq.js +88 -0
- package/dist/form-submitter-BIFqZ0wq.js.map +1 -0
- package/dist/form.js +1 -9
- package/dist/form.js.map +1 -1
- package/dist/icon-button.js +15 -19
- package/dist/icon-button.js.map +1 -1
- package/dist/icon.js +1 -1
- package/dist/implicit-submission-ChLdbxaR.js +100 -0
- package/dist/implicit-submission-ChLdbxaR.js.map +1 -0
- package/dist/index.js +20 -15
- package/dist/index.js.map +1 -1
- package/dist/{indicator-navigation-item-CmyhsOmy.js → indicator-navigation-item-BsQE3kUr.js} +2 -2
- package/dist/{indicator-navigation-item-CmyhsOmy.js.map → indicator-navigation-item-BsQE3kUr.js.map} +1 -1
- package/dist/input.js +13 -4
- package/dist/input.js.map +1 -1
- package/dist/json-viewer.js +1 -1
- package/dist/kanban.js +8 -7
- package/dist/kanban.js.map +1 -1
- package/dist/link-button.js +13 -14
- package/dist/link-button.js.map +1 -1
- package/dist/list-item.js +52 -16
- package/dist/list-item.js.map +1 -1
- package/dist/list.js +5 -3
- package/dist/list.js.map +1 -1
- package/dist/listbox.js +1 -1
- package/dist/loader-full.js +17 -12
- package/dist/loader-full.js.map +1 -1
- package/dist/loader.js +17 -12
- package/dist/loader.js.map +1 -1
- package/dist/locale-DEsJZCQG.js.map +1 -1
- package/dist/mention-input.js +8 -1
- package/dist/mention-input.js.map +1 -1
- package/dist/menu-item.js +12 -12
- package/dist/menu-item.js.map +1 -1
- package/dist/menu.js +7 -3
- package/dist/menu.js.map +1 -1
- package/dist/navigation-bar-item.js +4 -3
- package/dist/navigation-bar-item.js.map +1 -1
- package/dist/navigation-bar.js +4 -3
- package/dist/navigation-bar.js.map +1 -1
- package/dist/navigation-drawer-item.js +3 -2
- package/dist/navigation-drawer-item.js.map +1 -1
- package/dist/navigation-drawer.js +3 -2
- package/dist/navigation-drawer.js.map +1 -1
- package/dist/{navigation-item-base-kUrvJgCx.js → navigation-item-base-5ljwtLG_.js} +3 -2
- package/dist/{navigation-item-base-kUrvJgCx.js.map → navigation-item-base-5ljwtLG_.js.map} +1 -1
- package/dist/navigation-rail-item.js +4 -3
- package/dist/navigation-rail-item.js.map +1 -1
- package/dist/navigation-rail.js +6 -5
- package/dist/navigation-rail.js.map +1 -1
- package/dist/number-field.js +4 -1
- package/dist/number-field.js.map +1 -1
- package/dist/option.js +3 -2
- package/dist/option.js.map +1 -1
- package/dist/password-field.js +11 -4
- package/dist/password-field.js.map +1 -1
- package/dist/phone-field.js +4 -1
- package/dist/phone-field.js.map +1 -1
- package/dist/{picker-field-DmXYPvbF.js → picker-field-BiM3iXAQ.js} +2 -2
- package/dist/{picker-field-DmXYPvbF.js.map → picker-field-BiM3iXAQ.js.map} +1 -1
- package/dist/pin-input.js +4 -1
- package/dist/pin-input.js.map +1 -1
- package/dist/{range-utils-DZe96GnO.js → range-utils-vgG1SJ2o.js} +2 -2
- package/dist/{range-utils-DZe96GnO.js.map → range-utils-vgG1SJ2o.js.map} +1 -1
- package/dist/{roving-focus-controller-fm95JkZJ.js → roving-focus-controller-YtNbxH95.js} +30 -7
- package/dist/roving-focus-controller-YtNbxH95.js.map +1 -0
- package/dist/search.js +12 -6
- package/dist/search.js.map +1 -1
- package/dist/select.js +11 -3
- package/dist/select.js.map +1 -1
- package/dist/shipped-icons.js +1 -1
- package/dist/split-button.js +9 -1
- package/dist/split-button.js.map +1 -1
- package/dist/src/__internal/controllers/roving-focus-controller.d.ts +14 -2
- package/dist/src/__internal/implicit-submission.d.ts +25 -0
- package/dist/src/__internal/utils/activation-gate.d.ts +8 -0
- package/dist/src/__internal/utils/form-submission.d.ts +2 -0
- package/dist/src/avatar-group/avatar-group.d.ts +1 -1
- package/dist/src/button/base-button/base-button.d.ts +1 -1
- package/dist/src/button/button/button.d.ts +2 -1
- package/dist/src/button/fab/fab.d.ts +2 -1
- package/dist/src/button/icon-button/icon-button.d.ts +2 -1
- package/dist/src/button/link-button/link-button.d.ts +5 -1
- package/dist/src/calendar/calendar-month-view.d.ts +5 -1
- package/dist/src/calendar/calendar.d.ts +6 -1
- package/dist/src/card/card.d.ts +19 -9
- package/dist/src/chart-pie/chart-pie.d.ts +5 -0
- package/dist/src/chip/chip/chip.d.ts +4 -4
- package/dist/src/dropdown-button/dropdown-button.d.ts +5 -1
- package/dist/src/input/BaseField.d.ts +7 -0
- package/dist/src/input/input.d.ts +5 -1
- package/dist/src/list/list-item.d.ts +2 -1
- package/dist/src/mention-input/mention-input.d.ts +2 -0
- package/dist/src/menu/menu-item/menu-item.d.ts +6 -4
- package/dist/src/password-field/password-field.d.ts +3 -1
- package/dist/src/search/search.d.ts +1 -0
- package/dist/src/select/select.d.ts +2 -0
- package/dist/src/split-button/split-button.d.ts +6 -1
- package/dist/src/stepper/step.d.ts +3 -1
- package/dist/src/tabs/tab.d.ts +12 -2
- package/dist/src/textarea/textarea.d.ts +2 -0
- package/dist/src/toolbar/toolbar.d.ts +13 -2
- package/dist/step.js +7 -1
- package/dist/step.js.map +1 -1
- package/dist/stepper.js +10 -1
- package/dist/stepper.js.map +1 -1
- package/dist/sub-menu.js +3 -2
- package/dist/sub-menu.js.map +1 -1
- package/dist/svg.js +1 -1
- package/dist/tab-group.js +3 -2
- package/dist/tab-group.js.map +1 -1
- package/dist/tab.js +17 -12
- package/dist/tab.js.map +1 -1
- package/dist/tabs.js +3 -2
- package/dist/tabs.js.map +1 -1
- package/dist/test/accessible-name.test.d.ts +1 -0
- package/dist/test/helpers/count-activations.d.ts +9 -0
- package/dist/test/navigation-rail.test.d.ts +1 -0
- package/dist/test/throttle-delay.test.d.ts +1 -0
- package/dist/textarea.js +8 -1
- package/dist/textarea.js.map +1 -1
- package/dist/throttle-C7ZAPqtu.js +24 -0
- package/dist/throttle-C7ZAPqtu.js.map +1 -0
- package/dist/time-field.js +7 -4
- package/dist/time-field.js.map +1 -1
- package/dist/time-picker.js +2 -2
- package/dist/toolbar.js +25 -8
- package/dist/toolbar.js.map +1 -1
- package/dist/tree.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/url-field.js +4 -1
- package/dist/url-field.js.map +1 -1
- package/dist/{utils-DcvLgexs.js → utils-CQzycr9J.js} +2 -1
- package/dist/utils-CQzycr9J.js.map +1 -0
- package/package.json +2 -1
- package/src/__internal/controllers/roving-focus-controller.ts +35 -7
- package/src/__internal/i18n/locale.ts +1 -1
- package/src/__internal/implicit-submission.ts +102 -0
- package/src/__internal/utils/activation-gate.ts +20 -0
- package/src/__internal/utils/cache-fetch.ts +6 -3
- package/src/__internal/utils/form-submission.ts +11 -0
- package/src/avatar/avatar.scss +5 -0
- package/src/avatar-group/avatar-group.scss +3 -0
- package/src/avatar-group/avatar-group.ts +1 -1
- package/src/button/base-button/base-button.ts +41 -16
- package/src/button/button/button.ts +5 -16
- package/src/button/fab/fab.ts +7 -18
- package/src/button/icon-button/icon-button.ts +7 -18
- package/src/button/link-button/link-button.ts +8 -15
- package/src/calendar/_calendar-header.scss +7 -1
- package/src/calendar/calendar-month-view.scss +36 -2
- package/src/calendar/calendar-month-view.ts +33 -8
- package/src/calendar/calendar.ts +17 -2
- package/src/calendar/utils.ts +1 -0
- package/src/card/card.ts +27 -16
- package/src/chart-doughnut/chart-doughnut.ts +6 -1
- package/src/chart-pie/chart-pie.ts +10 -1
- package/src/chip/chip/chip.ts +6 -26
- package/src/dropdown-button/dropdown-button.ts +7 -2
- package/src/form/form.ts +1 -9
- package/src/input/BaseField.ts +17 -0
- package/src/input/input.ts +13 -1
- package/src/kanban/kanban.scss +11 -7
- package/src/list/list-item.scss +5 -0
- package/src/list/list-item.ts +44 -16
- package/src/mention-input/mention-input.ts +5 -0
- package/src/menu/menu/menu.ts +4 -1
- package/src/menu/menu-item/menu-item.ts +9 -14
- package/src/navigation-rail/navigation-rail.scss +3 -2
- package/src/password-field/password-field.ts +11 -1
- package/src/search/search.ts +9 -0
- package/src/select/select.ts +5 -0
- package/src/split-button/split-button.ts +10 -1
- package/src/stepper/step.ts +7 -1
- package/src/stepper/stepper.scss +13 -0
- package/src/tabs/tab.ts +21 -17
- package/src/textarea/textarea.ts +5 -0
- package/src/toolbar/toolbar.ts +26 -7
- package/dist/BaseField-BbOj212R.js.map +0 -1
- package/dist/base-button-BJMGMcMv.js.map +0 -1
- package/dist/datasource-OwvH7SVq.js.map +0 -1
- package/dist/form-submitter-beG1CXAn.js.map +0 -1
- package/dist/roving-focus-controller-fm95JkZJ.js.map +0 -1
- package/dist/throttle-SQ9t-HL7.js.map +0 -1
- package/dist/utils-DcvLgexs.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigation-drawer.js","sources":["../../src/navigation-drawer/navigation-drawer.ts"],"sourcesContent":["import { html, LitElement, nothing, PropertyValues } from 'lit';\nimport { property, query } from 'lit/decorators.js';\nimport IndividualComponent from '@/IndividualComponent.js';\nimport { I18nController } from '@/__internal/i18n/i18n-controller.js';\nimport { selectNavigationItem } from '@/__internal/navigation-item-base.js';\nimport { NavigationDrawerItem } from './navigation-drawer-item.js';\nimport { NavigationDrawerGroup } from './navigation-drawer-group.js';\nimport styles from './navigation-drawer.scss';\n\n/**\n * @label Navigation Drawer\n * @tag wc-navigation-drawer\n * @rawTag navigation-drawer\n *\n * @summary A side panel listing an app's destinations.\n * @overview\n * <p>Navigation drawer holds <code>wc-navigation-drawer-item</code> destinations. Clicking an item makes\n * it the current one (<code>aria-current=\"page\"</code>) and fires <code>change</code>.</p>\n * <p>Put items in a <code>wc-navigation-drawer-group</code> for an expandable section: its header is a\n * disclosure button and its items follow in the Tab order while it is expanded.</p>\n * <ul>\n * <li><code>variant=\"standard\"</code> (default) sits in the page layout, next to the content.</li>\n * <li><code>variant=\"modal\"</code> opens over the page with a scrim. It traps focus, closes on Escape,\n * on a scrim click and after an item is chosen.</li>\n * </ul>\n * <p>Both variants show only while <code>open</code> is set.</p>\n *\n * @slot - The drawer items and groups. Other content, such as `wc-divider` or section titles, works too.\n * @slot header - Content above the items, after the headline.\n *\n * @fires {CustomEvent<{value: string | undefined, index: number, item: NavigationDrawerItem}>} change - Dispatched when the user activates an item. `index` counts every item in the drawer, in groups too, in document order.\n * @fires {CustomEvent} open - Dispatched when the drawer opens.\n * @fires {CustomEvent} close - Dispatched when the drawer closes.\n *\n * @cssprop --navigation-drawer-width - Width of the drawer. Defaults to 22.5rem (360dp).\n * @cssprop --navigation-drawer-container-color - Background of the drawer. Defaults to `--color-surface-container-low`.\n *\n * @example\n * ```html\n * <wc-navigation-drawer open headline=\"Mail\">\n * <wc-navigation-drawer-item current badge=\"24\">\n * <wc-icon slot=\"icon\" name=\"inbox\"></wc-icon>\n * Inbox\n * </wc-navigation-drawer-item>\n * <wc-navigation-drawer-item>\n * <wc-icon slot=\"icon\" name=\"send\"></wc-icon>\n * Sent\n * </wc-navigation-drawer-item>\n * <wc-navigation-drawer-group>\n * <wc-icon slot=\"icon\" name=\"label\"></wc-icon>\n * <span slot=\"label\">Labels</span>\n * <wc-navigation-drawer-item value=\"work\">Work</wc-navigation-drawer-item>\n * <wc-navigation-drawer-item value=\"family\">Family</wc-navigation-drawer-item>\n * </wc-navigation-drawer-group>\n * </wc-navigation-drawer>\n * ```\n * @tags navigation\n */\n@IndividualComponent\nexport class NavigationDrawer extends LitElement {\n // ── Static ───────────────────────────────────────────────────────────────\n\n static styles = [styles];\n\n static Item = NavigationDrawerItem;\n\n static Group = NavigationDrawerGroup;\n\n // ── Properties ───────────────────────────────────────────────────────────\n\n /** Whether the drawer is shown. */\n @property({ type: Boolean, reflect: true }) open = false;\n\n /** `\"standard\"` sits in the layout; `\"modal\"` opens over the page with a scrim. */\n @property({ reflect: true }) variant: 'standard' | 'modal' = 'standard';\n\n /** Title shown at the top of the drawer. */\n @property() headline = '';\n\n // ── Queries ──────────────────────────────────────────────────────────────\n\n @query('dialog') private dialogElement?: HTMLDialogElement;\n\n // ── Private fields ───────────────────────────────────────────────────────\n\n /** Peacock's strings for the landmark label. */\n private readonly i18n = new I18nController(this);\n\n // ── Lifecycle ────────────────────────────────────────────────────────────\n\n override connectedCallback() {\n super.connectedCallback();\n this.addEventListener('click', this.handleItemClick);\n }\n\n override disconnectedCallback() {\n this.removeEventListener('click', this.handleItemClick);\n super.disconnectedCallback();\n }\n\n protected override updated(changed: PropertyValues<this>) {\n if (changed.has('open') || changed.has('variant')) {\n this.syncDialog();\n }\n // Skip the first render: `open` set in markup is not a user action.\n if (changed.has('open') && changed.get('open') !== undefined) {\n this.dispatchEvent(\n new CustomEvent(this.open ? 'open' : 'close', {\n bubbles: true,\n composed: true,\n }),\n );\n }\n }\n\n // ── Public methods ───────────────────────────────────────────────────────\n\n /** Opens the drawer. */\n show() {\n this.open = true;\n }\n\n /** Closes the drawer. */\n close() {\n this.open = false;\n }\n\n // ── Private methods ──────────────────────────────────────────────────────\n\n private getItems(): NavigationDrawerItem[] {\n return Array.from(\n this.querySelectorAll<NavigationDrawerItem>('wc-navigation-drawer-item'),\n );\n }\n\n private syncDialog() {\n const dialog = this.dialogElement;\n if (!dialog) return;\n if (this.open && !dialog.open) {\n dialog.showModal();\n const items = this.getItems();\n (items.find(item => item.current) ?? items[0])?.focus();\n } else if (!this.open && dialog.open) {\n dialog.close();\n }\n }\n\n private handleItemClick = (event: Event) => {\n const detail = selectNavigationItem<NavigationDrawerItem>(\n this,\n event,\n 'wc-navigation-drawer-item',\n );\n if (detail && this.variant === 'modal') this.close();\n };\n\n /** Escape: close through `open` so the property stays the source of truth. */\n private handleCancel(event: Event) {\n event.preventDefault();\n this.close();\n }\n\n /** A click that lands on the dialog itself, not its content, is a scrim click. */\n private handleDialogClick(event: MouseEvent) {\n if (event.target === this.dialogElement) this.close();\n }\n\n // ── Render helpers ───────────────────────────────────────────────────────\n\n private renderContent() {\n return html`\n <div class=\"container\" part=\"container\">\n ${this.headline\n ? html`<div class=\"headline\">${this.headline}</div>`\n : nothing}\n <slot name=\"header\"></slot>\n <nav\n class=\"items\"\n aria-label=${this.headline || this.i18n.t('navigation')}\n >\n <slot></slot>\n </nav>\n </div>\n `;\n }\n\n // ── Render ───────────────────────────────────────────────────────────────\n\n render() {\n if (this.variant === 'modal') {\n return html`<dialog\n class=\"drawer modal\"\n @cancel=${this.handleCancel}\n @click=${this.handleDialogClick}\n >\n ${this.renderContent()}\n </dialog>`;\n }\n\n return html`<div class=\"drawer standard\" ?hidden=${!this.open}>\n ${this.renderContent()}\n </div>`;\n }\n}\n"],"names":["LitElement","html","nothing","styles","property","query"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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CAAA;AAtBhD,gBAAgB,GAAA,UAAA,CAAA;IAD5B;AACY,CAAA,EAAA,gBAAgB,CAgJ5B;;;;"}
|
|
1
|
+
{"version":3,"file":"navigation-drawer.js","sources":["../../src/navigation-drawer/navigation-drawer.ts"],"sourcesContent":["import { html, LitElement, nothing, PropertyValues } from 'lit';\nimport { property, query } from 'lit/decorators.js';\nimport IndividualComponent from '@/IndividualComponent.js';\nimport { I18nController } from '@/__internal/i18n/i18n-controller.js';\nimport { selectNavigationItem } from '@/__internal/navigation-item-base.js';\nimport { NavigationDrawerItem } from './navigation-drawer-item.js';\nimport { NavigationDrawerGroup } from './navigation-drawer-group.js';\nimport styles from './navigation-drawer.scss';\n\n/**\n * @label Navigation Drawer\n * @tag wc-navigation-drawer\n * @rawTag navigation-drawer\n *\n * @summary A side panel listing an app's destinations.\n * @overview\n * <p>Navigation drawer holds <code>wc-navigation-drawer-item</code> destinations. Clicking an item makes\n * it the current one (<code>aria-current=\"page\"</code>) and fires <code>change</code>.</p>\n * <p>Put items in a <code>wc-navigation-drawer-group</code> for an expandable section: its header is a\n * disclosure button and its items follow in the Tab order while it is expanded.</p>\n * <ul>\n * <li><code>variant=\"standard\"</code> (default) sits in the page layout, next to the content.</li>\n * <li><code>variant=\"modal\"</code> opens over the page with a scrim. It traps focus, closes on Escape,\n * on a scrim click and after an item is chosen.</li>\n * </ul>\n * <p>Both variants show only while <code>open</code> is set.</p>\n *\n * @slot - The drawer items and groups. Other content, such as `wc-divider` or section titles, works too.\n * @slot header - Content above the items, after the headline.\n *\n * @fires {CustomEvent<{value: string | undefined, index: number, item: NavigationDrawerItem}>} change - Dispatched when the user activates an item. `index` counts every item in the drawer, in groups too, in document order.\n * @fires {CustomEvent} open - Dispatched when the drawer opens.\n * @fires {CustomEvent} close - Dispatched when the drawer closes.\n *\n * @cssprop --navigation-drawer-width - Width of the drawer. Defaults to 22.5rem (360dp).\n * @cssprop --navigation-drawer-container-color - Background of the drawer. Defaults to `--color-surface-container-low`.\n *\n * @example\n * ```html\n * <wc-navigation-drawer open headline=\"Mail\">\n * <wc-navigation-drawer-item current badge=\"24\">\n * <wc-icon slot=\"icon\" name=\"inbox\"></wc-icon>\n * Inbox\n * </wc-navigation-drawer-item>\n * <wc-navigation-drawer-item>\n * <wc-icon slot=\"icon\" name=\"send\"></wc-icon>\n * Sent\n * </wc-navigation-drawer-item>\n * <wc-navigation-drawer-group>\n * <wc-icon slot=\"icon\" name=\"label\"></wc-icon>\n * <span slot=\"label\">Labels</span>\n * <wc-navigation-drawer-item value=\"work\">Work</wc-navigation-drawer-item>\n * <wc-navigation-drawer-item value=\"family\">Family</wc-navigation-drawer-item>\n * </wc-navigation-drawer-group>\n * </wc-navigation-drawer>\n * ```\n * @tags navigation\n */\n@IndividualComponent\nexport class NavigationDrawer extends LitElement {\n // ── Static ───────────────────────────────────────────────────────────────\n\n static styles = [styles];\n\n static Item = NavigationDrawerItem;\n\n static Group = NavigationDrawerGroup;\n\n // ── Properties ───────────────────────────────────────────────────────────\n\n /** Whether the drawer is shown. */\n @property({ type: Boolean, reflect: true }) open = false;\n\n /** `\"standard\"` sits in the layout; `\"modal\"` opens over the page with a scrim. */\n @property({ reflect: true }) variant: 'standard' | 'modal' = 'standard';\n\n /** Title shown at the top of the drawer. */\n @property() headline = '';\n\n // ── Queries ──────────────────────────────────────────────────────────────\n\n @query('dialog') private dialogElement?: HTMLDialogElement;\n\n // ── Private fields ───────────────────────────────────────────────────────\n\n /** Peacock's strings for the landmark label. */\n private readonly i18n = new I18nController(this);\n\n // ── Lifecycle ────────────────────────────────────────────────────────────\n\n override connectedCallback() {\n super.connectedCallback();\n this.addEventListener('click', this.handleItemClick);\n }\n\n override disconnectedCallback() {\n this.removeEventListener('click', this.handleItemClick);\n super.disconnectedCallback();\n }\n\n protected override updated(changed: PropertyValues<this>) {\n if (changed.has('open') || changed.has('variant')) {\n this.syncDialog();\n }\n // Skip the first render: `open` set in markup is not a user action.\n if (changed.has('open') && changed.get('open') !== undefined) {\n this.dispatchEvent(\n new CustomEvent(this.open ? 'open' : 'close', {\n bubbles: true,\n composed: true,\n }),\n );\n }\n }\n\n // ── Public methods ───────────────────────────────────────────────────────\n\n /** Opens the drawer. */\n show() {\n this.open = true;\n }\n\n /** Closes the drawer. */\n close() {\n this.open = false;\n }\n\n // ── Private methods ──────────────────────────────────────────────────────\n\n private getItems(): NavigationDrawerItem[] {\n return Array.from(\n this.querySelectorAll<NavigationDrawerItem>('wc-navigation-drawer-item'),\n );\n }\n\n private syncDialog() {\n const dialog = this.dialogElement;\n if (!dialog) return;\n if (this.open && !dialog.open) {\n dialog.showModal();\n const items = this.getItems();\n (items.find(item => item.current) ?? items[0])?.focus();\n } else if (!this.open && dialog.open) {\n dialog.close();\n }\n }\n\n private handleItemClick = (event: Event) => {\n const detail = selectNavigationItem<NavigationDrawerItem>(\n this,\n event,\n 'wc-navigation-drawer-item',\n );\n if (detail && this.variant === 'modal') this.close();\n };\n\n /** Escape: close through `open` so the property stays the source of truth. */\n private handleCancel(event: Event) {\n event.preventDefault();\n this.close();\n }\n\n /** A click that lands on the dialog itself, not its content, is a scrim click. */\n private handleDialogClick(event: MouseEvent) {\n if (event.target === this.dialogElement) this.close();\n }\n\n // ── Render helpers ───────────────────────────────────────────────────────\n\n private renderContent() {\n return html`\n <div class=\"container\" part=\"container\">\n ${this.headline\n ? html`<div class=\"headline\">${this.headline}</div>`\n : nothing}\n <slot name=\"header\"></slot>\n <nav\n class=\"items\"\n aria-label=${this.headline || this.i18n.t('navigation')}\n >\n <slot></slot>\n </nav>\n </div>\n `;\n }\n\n // ── Render ───────────────────────────────────────────────────────────────\n\n render() {\n if (this.variant === 'modal') {\n return html`<dialog\n class=\"drawer modal\"\n @cancel=${this.handleCancel}\n @click=${this.handleDialogClick}\n >\n ${this.renderContent()}\n </dialog>`;\n }\n\n return html`<div class=\"drawer standard\" ?hidden=${!this.open}>\n ${this.renderContent()}\n </div>`;\n }\n}\n"],"names":["LitElement","html","nothing","styles","property","query"],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AAK,CAAC,QAAQ;AAA4C,CAAA,EAAA,gBAAA,CAAA,SAAA,EAAA,eAAA,EAAA,MAAA,CAAA;AAtBhD,gBAAgB,GAAA,UAAA,CAAA;IAD5B;AACY,CAAA,EAAA,gBAAgB,CAgJ5B;;;;"}
|
|
@@ -3,7 +3,8 @@ import { n } from './property-B2TG3KEE.js';
|
|
|
3
3
|
import { r } from './state-BCeDVCI9.js';
|
|
4
4
|
import { e } from './query-CHb9Ft_d.js';
|
|
5
5
|
import { e as e$1 } from './class-map-NDIkZErE.js';
|
|
6
|
-
import {
|
|
6
|
+
import { i as isActivationClick, d as dispatchActivationClick } from './dispatch-event-utils-DfgqVBK8.js';
|
|
7
|
+
import { t as throttle } from './throttle-C7ZAPqtu.js';
|
|
7
8
|
|
|
8
9
|
var _NavigationItemBase_id, _NavigationItemBase_dispatchClick;
|
|
9
10
|
/**
|
|
@@ -186,4 +187,4 @@ function selectNavigationItem(host, event, selector) {
|
|
|
186
187
|
}
|
|
187
188
|
|
|
188
189
|
export { NavigationItemBase as N, selectNavigationItem as s };
|
|
189
|
-
//# sourceMappingURL=navigation-item-base-
|
|
190
|
+
//# sourceMappingURL=navigation-item-base-5ljwtLG_.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigation-item-base-kUrvJgCx.js","sources":["../../src/__internal/navigation-item-base.ts"],"sourcesContent":["import { html, LitElement, nothing, TemplateResult } from 'lit';\nimport { property, query, state } from 'lit/decorators.js';\nimport { classMap, ClassInfo } from 'lit/directives/class-map.js';\nimport {\n dispatchActivationClick,\n isActivationClick,\n} from './utils/dispatch-event-utils.js';\nimport { throttle } from './utils/throttle.js';\n\n/**\n * Shared base of `wc-navigation-bar-item`, `wc-navigation-rail-item` and\n * `wc-navigation-drawer-item`: the current-destination state, link or button rendering, the\n * disabled reason, the badge and the throttled host click. Subclasses render the content.\n *\n * Not a component on its own: it is not registered and carries no `@IndividualComponent` marker.\n */\nexport abstract class NavigationItemBase extends LitElement {\n // ── Static ───────────────────────────────────────────────────────────────\n\n static override shadowRootOptions = {\n ...LitElement.shadowRootOptions,\n delegatesFocus: true,\n };\n\n // ── Properties ───────────────────────────────────────────────────────────\n\n /** Whether this item is the current destination. Sets `aria-current=\"page\"`. */\n @property({ type: Boolean, reflect: true }) current = false;\n\n /** Whether this item is disabled. */\n @property({ type: Boolean, reflect: true }) disabled = false;\n\n /** If provided, the item renders as a link. */\n @property({ reflect: true }) href?: string;\n\n /** Link target. */\n @property() target: string = '_self';\n\n /** Identifies the item in the container's `change` event. */\n @property({ reflect: true }) value?: string;\n\n /** Short text, such as an unread count. The `badge` slot overrides it. */\n @property() badge?: string;\n\n /** Reason the item is disabled, read to screen reader users. */\n @property({ attribute: 'disabled-reason' }) disabledReason: string = '';\n\n /** Throttles activation clicks by this many milliseconds. No throttle when unset. */\n @property({ type: Number, attribute: 'throttle-delay' })\n throttleDelay?: number;\n\n // ── State ────────────────────────────────────────────────────────────────\n\n /** True when the `badge` slot has content. */\n @state() protected hasSlottedBadge = false;\n\n // ── Queries ──────────────────────────────────────────────────────────────\n\n @query('#item') readonly itemElement!: HTMLElement | null;\n\n // ── Private fields ───────────────────────────────────────────────────────\n\n readonly #id = crypto.randomUUID();\n\n /** Forwards host clicks to the inner element, throttled once `throttleDelay` is known. */\n #dispatchClick: (event: MouseEvent) => void = event =>\n this.forwardClick(event);\n\n // ── Lifecycle ────────────────────────────────────────────────────────────\n\n constructor() {\n super();\n this.addEventListener('click', this.handleHostClick);\n }\n\n protected override firstUpdated() {\n if (typeof this.throttleDelay === 'number') {\n this.#dispatchClick = throttle(\n (event: MouseEvent) => this.forwardClick(event),\n this.throttleDelay,\n );\n }\n }\n\n // ── Public methods ───────────────────────────────────────────────────────\n\n override focus() {\n this.itemElement?.focus();\n }\n\n override blur() {\n this.itemElement?.blur();\n }\n\n // ── Protected methods ────────────────────────────────────────────────────\n\n /** Extra classes for the inner link or button. */\n protected itemClasses(): ClassInfo {\n return {};\n }\n\n /** Whether the badge has anything to show. */\n protected get hasBadge(): boolean {\n return this.hasSlottedBadge || !!this.badge;\n }\n\n protected handleBadgeSlotChange(event: Event) {\n this.hasSlottedBadge =\n (event.target as HTMLSlotElement).assignedNodes({ flatten: true })\n .length > 0;\n }\n\n /** The content of the inner link or button. */\n protected abstract renderContent(): TemplateResult;\n\n // ── Private methods ──────────────────────────────────────────────────────\n\n private handleHostClick = (event: MouseEvent) => {\n this.#dispatchClick(event);\n };\n\n /** A click on the host itself (`item.click()`) activates the inner link or button. */\n private forwardClick(event: MouseEvent) {\n if (!isActivationClick(event) || !this.itemElement) return;\n this.focus();\n dispatchActivationClick(this.itemElement);\n }\n\n // ── Render helpers ───────────────────────────────────────────────────────\n\n protected renderBadge() {\n return html`<span class=\"badge\" ?hidden=${!this.hasBadge}\n ><slot name=\"badge\" @slotchange=${this.handleBadgeSlotChange}\n >${this.badge ?? nothing}</slot\n ></span\n >`;\n }\n\n protected renderDisabledReason() {\n if (!this.disabled || !this.disabledReason) return nothing;\n return html`<div\n id=\"disabled-reason-${this.#id}\"\n class=\"screen-reader-only\"\n >\n ${this.disabledReason}\n </div>`;\n }\n\n // ── Render ───────────────────────────────────────────────────────────────\n\n render() {\n const classes = classMap({\n item: true,\n ...this.itemClasses(),\n current: this.current,\n disabled: this.disabled,\n });\n const describedBy =\n this.disabled && this.disabledReason\n ? `disabled-reason-${this.#id}`\n : nothing;\n\n if (this.href && !this.disabled) {\n return html`<a\n id=\"item\"\n class=${classes}\n href=${this.href}\n target=${this.target}\n aria-current=${this.current ? 'page' : nothing}\n >${this.renderContent()}</a\n >`;\n }\n\n return html`<button\n id=\"item\"\n class=${classes}\n ?disabled=${this.disabled}\n aria-current=${this.current ? 'page' : nothing}\n aria-describedby=${describedBy}\n >\n ${this.renderContent()}\n </button>\n ${this.renderDisabledReason()}`;\n }\n}\n\n/** Detail of the `change` event that navigation bars, rails and drawers fire. */\nexport interface NavigationChangeDetail<\n T extends NavigationItemBase = NavigationItemBase,\n> {\n /** The chosen item's `value`. */\n value: string | undefined;\n /** The chosen item's position among the container's items, in document order. */\n index: number;\n /** The chosen item. */\n item: T;\n}\n\n/**\n * The click handling the navigation containers share: finds the item the click landed on, makes\n * it the only current one and fires `change` with `{ value, index, item }`. Returns the detail, or\n * `null` when the click was not on an enabled item.\n */\nexport function selectNavigationItem<T extends NavigationItemBase>(\n host: HTMLElement,\n event: Event,\n selector: string,\n): NavigationChangeDetail<T> | null {\n const item = (event.target as Element | null)?.closest?.(\n selector,\n ) as T | null;\n if (!item || item.disabled || !host.contains(item)) return null;\n\n const items = Array.from(host.querySelectorAll<T>(selector));\n for (const other of items) {\n other.current = other === item;\n }\n\n const detail: NavigationChangeDetail<T> = {\n value: item.value,\n index: items.indexOf(item),\n item,\n };\n host.dispatchEvent(\n new CustomEvent<NavigationChangeDetail<T>>('change', {\n detail,\n bubbles: true,\n composed: true,\n }),\n );\n return detail;\n}\n"],"names":["LitElement","html","nothing","classMap","property","state","query"],"mappings":";;;;;;;;AASA;;;;;;AAMG;AACG,MAAgB,kBAAmB,SAAQA,CAAU,CAAA;;AAsDzD,IAAA,WAAA,GAAA;AACE,QAAA,KAAK,EAAE;;;QA5CmC,IAAA,CAAA,OAAO,GAAG,KAAK;;QAGf,IAAA,CAAA,QAAQ,GAAG,KAAK;;QAMhD,IAAA,CAAA,MAAM,GAAW,OAAO;;QASQ,IAAA,CAAA,cAAc,GAAW,EAAE;;;QASpD,IAAA,CAAA,eAAe,GAAG,KAAK;;AAQjC,QAAA,sBAAA,CAAA,GAAA,CAAA,IAAA,EAAM,MAAM,CAAC,UAAU,EAAE,CAAA;;QAGlC,iCAAA,CAAA,GAAA,CAAA,IAAA,EAA8C,KAAK,IACjD,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAA;;AAmDlB,QAAA,IAAA,CAAA,eAAe,GAAG,CAAC,KAAiB,KAAI;AAC9C,YAAA,sBAAA,CAAA,IAAI,EAAA,iCAAA,EAAA,GAAA,CAAe,CAAA,IAA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,UAAA,CAAA;AAAlB,IAAAC,CAAK;AAAqC,CAAA,EAAA,kBAAA,CAAA,SAAA,EAAA,iBAAA,EAAA,MAAA,CAAA;AAIlB,UAAA,CAAA;IAAxBC,CAAK,CAAC,OAAO;AAA4C,CAAA,EAAA,kBAAA,CAAA,SAAA,EAAA,aAAA,EAAA,MAAA,CAAA;AA4I5D;;;;AAIG;SACa,oBAAoB,CAClC,IAAiB,EACjB,KAAY,EACZ,QAAgB,EAAA;IAEhB,MAAM,IAAI,GAAI,KAAK,CAAC,MAAyB,EAAE,OAAO,GACpD,QAAQ,CACG;AACb,IAAA,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;AAAE,QAAA,OAAO,IAAI;AAE/D,IAAA,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAI,QAAQ,CAAC,CAAC;AAC5D,IAAA,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE;AACzB,QAAA,KAAK,CAAC,OAAO,GAAG,KAAK,KAAK,IAAI;IAChC;AAEA,IAAA,MAAM,MAAM,GAA8B;QACxC,KAAK,EAAE,IAAI,CAAC,KAAK;AACjB,QAAA,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QAC1B,IAAI;KACL;AACD,IAAA,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAA4B,QAAQ,EAAE;QACnD,MAAM;AACN,QAAA,OAAO,EAAE,IAAI;AACb,QAAA,QAAQ,EAAE,IAAI;AACf,KAAA,CAAC,CACH;AACD,IAAA,OAAO,MAAM;AACf;;;;"}
|
|
1
|
+
{"version":3,"file":"navigation-item-base-5ljwtLG_.js","sources":["../../src/__internal/navigation-item-base.ts"],"sourcesContent":["import { html, LitElement, nothing, TemplateResult } from 'lit';\nimport { property, query, state } from 'lit/decorators.js';\nimport { classMap, ClassInfo } from 'lit/directives/class-map.js';\nimport {\n dispatchActivationClick,\n isActivationClick,\n} from './utils/dispatch-event-utils.js';\nimport { throttle } from './utils/throttle.js';\n\n/**\n * Shared base of `wc-navigation-bar-item`, `wc-navigation-rail-item` and\n * `wc-navigation-drawer-item`: the current-destination state, link or button rendering, the\n * disabled reason, the badge and the throttled host click. Subclasses render the content.\n *\n * Not a component on its own: it is not registered and carries no `@IndividualComponent` marker.\n */\nexport abstract class NavigationItemBase extends LitElement {\n // ── Static ───────────────────────────────────────────────────────────────\n\n static override shadowRootOptions = {\n ...LitElement.shadowRootOptions,\n delegatesFocus: true,\n };\n\n // ── Properties ───────────────────────────────────────────────────────────\n\n /** Whether this item is the current destination. Sets `aria-current=\"page\"`. */\n @property({ type: Boolean, reflect: true }) current = false;\n\n /** Whether this item is disabled. */\n @property({ type: Boolean, reflect: true }) disabled = false;\n\n /** If provided, the item renders as a link. */\n @property({ reflect: true }) href?: string;\n\n /** Link target. */\n @property() target: string = '_self';\n\n /** Identifies the item in the container's `change` event. */\n @property({ reflect: true }) value?: string;\n\n /** Short text, such as an unread count. The `badge` slot overrides it. */\n @property() badge?: string;\n\n /** Reason the item is disabled, read to screen reader users. */\n @property({ attribute: 'disabled-reason' }) disabledReason: string = '';\n\n /** Throttles activation clicks by this many milliseconds. No throttle when unset. */\n @property({ type: Number, attribute: 'throttle-delay' })\n throttleDelay?: number;\n\n // ── State ────────────────────────────────────────────────────────────────\n\n /** True when the `badge` slot has content. */\n @state() protected hasSlottedBadge = false;\n\n // ── Queries ──────────────────────────────────────────────────────────────\n\n @query('#item') readonly itemElement!: HTMLElement | null;\n\n // ── Private fields ───────────────────────────────────────────────────────\n\n readonly #id = crypto.randomUUID();\n\n /** Forwards host clicks to the inner element, throttled once `throttleDelay` is known. */\n #dispatchClick: (event: MouseEvent) => void = event =>\n this.forwardClick(event);\n\n // ── Lifecycle ────────────────────────────────────────────────────────────\n\n constructor() {\n super();\n this.addEventListener('click', this.handleHostClick);\n }\n\n protected override firstUpdated() {\n if (typeof this.throttleDelay === 'number') {\n this.#dispatchClick = throttle(\n (event: MouseEvent) => this.forwardClick(event),\n this.throttleDelay,\n );\n }\n }\n\n // ── Public methods ───────────────────────────────────────────────────────\n\n override focus() {\n this.itemElement?.focus();\n }\n\n override blur() {\n this.itemElement?.blur();\n }\n\n // ── Protected methods ────────────────────────────────────────────────────\n\n /** Extra classes for the inner link or button. */\n protected itemClasses(): ClassInfo {\n return {};\n }\n\n /** Whether the badge has anything to show. */\n protected get hasBadge(): boolean {\n return this.hasSlottedBadge || !!this.badge;\n }\n\n protected handleBadgeSlotChange(event: Event) {\n this.hasSlottedBadge =\n (event.target as HTMLSlotElement).assignedNodes({ flatten: true })\n .length > 0;\n }\n\n /** The content of the inner link or button. */\n protected abstract renderContent(): TemplateResult;\n\n // ── Private methods ──────────────────────────────────────────────────────\n\n private handleHostClick = (event: MouseEvent) => {\n this.#dispatchClick(event);\n };\n\n /** A click on the host itself (`item.click()`) activates the inner link or button. */\n private forwardClick(event: MouseEvent) {\n if (!isActivationClick(event) || !this.itemElement) return;\n this.focus();\n dispatchActivationClick(this.itemElement);\n }\n\n // ── Render helpers ───────────────────────────────────────────────────────\n\n protected renderBadge() {\n return html`<span class=\"badge\" ?hidden=${!this.hasBadge}\n ><slot name=\"badge\" @slotchange=${this.handleBadgeSlotChange}\n >${this.badge ?? nothing}</slot\n ></span\n >`;\n }\n\n protected renderDisabledReason() {\n if (!this.disabled || !this.disabledReason) return nothing;\n return html`<div\n id=\"disabled-reason-${this.#id}\"\n class=\"screen-reader-only\"\n >\n ${this.disabledReason}\n </div>`;\n }\n\n // ── Render ───────────────────────────────────────────────────────────────\n\n render() {\n const classes = classMap({\n item: true,\n ...this.itemClasses(),\n current: this.current,\n disabled: this.disabled,\n });\n const describedBy =\n this.disabled && this.disabledReason\n ? `disabled-reason-${this.#id}`\n : nothing;\n\n if (this.href && !this.disabled) {\n return html`<a\n id=\"item\"\n class=${classes}\n href=${this.href}\n target=${this.target}\n aria-current=${this.current ? 'page' : nothing}\n >${this.renderContent()}</a\n >`;\n }\n\n return html`<button\n id=\"item\"\n class=${classes}\n ?disabled=${this.disabled}\n aria-current=${this.current ? 'page' : nothing}\n aria-describedby=${describedBy}\n >\n ${this.renderContent()}\n </button>\n ${this.renderDisabledReason()}`;\n }\n}\n\n/** Detail of the `change` event that navigation bars, rails and drawers fire. */\nexport interface NavigationChangeDetail<\n T extends NavigationItemBase = NavigationItemBase,\n> {\n /** The chosen item's `value`. */\n value: string | undefined;\n /** The chosen item's position among the container's items, in document order. */\n index: number;\n /** The chosen item. */\n item: T;\n}\n\n/**\n * The click handling the navigation containers share: finds the item the click landed on, makes\n * it the only current one and fires `change` with `{ value, index, item }`. Returns the detail, or\n * `null` when the click was not on an enabled item.\n */\nexport function selectNavigationItem<T extends NavigationItemBase>(\n host: HTMLElement,\n event: Event,\n selector: string,\n): NavigationChangeDetail<T> | null {\n const item = (event.target as Element | null)?.closest?.(\n selector,\n ) as T | null;\n if (!item || item.disabled || !host.contains(item)) return null;\n\n const items = Array.from(host.querySelectorAll<T>(selector));\n for (const other of items) {\n other.current = other === item;\n }\n\n const detail: NavigationChangeDetail<T> = {\n value: item.value,\n index: items.indexOf(item),\n item,\n };\n host.dispatchEvent(\n new CustomEvent<NavigationChangeDetail<T>>('change', {\n detail,\n bubbles: true,\n composed: true,\n }),\n );\n return detail;\n}\n"],"names":["LitElement","html","nothing","classMap","property","state","query"],"mappings":";;;;;;;;;AASA;;;;;;AAMG;AACG,MAAgB,kBAAmB,SAAQA,CAAU,CAAA;;AAsDzD,IAAA,WAAA,GAAA;AACE,QAAA,KAAK,EAAE;;;QA5CmC,IAAA,CAAA,OAAO,GAAG,KAAK;;QAGf,IAAA,CAAA,QAAQ,GAAG,KAAK;;QAMhD,IAAA,CAAA,MAAM,GAAW,OAAO;;QASQ,IAAA,CAAA,cAAc,GAAW,EAAE;;;QASpD,IAAA,CAAA,eAAe,GAAG,KAAK;;AAQjC,QAAA,sBAAA,CAAA,GAAA,CAA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IAAI;AACb,QAAA,QAAQ,EAAE,IAAI;AACf,KAAA,CAAC,CACH;AACD,IAAA,OAAO,MAAM;AACf;;;;"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { _ as __decorate, I as IndividualComponent } from './IndividualComponent-BK7XZjE2.js';
|
|
2
2
|
import { n } from './property-B2TG3KEE.js';
|
|
3
|
-
import { I as IndicatorNavigationItem } from './indicator-navigation-item-
|
|
3
|
+
import { I as IndicatorNavigationItem } from './indicator-navigation-item-BsQE3kUr.js';
|
|
4
4
|
import './state-BCeDVCI9.js';
|
|
5
5
|
import './observe-slot-change-DPxaZrZF.js';
|
|
6
|
-
import './navigation-item-base-
|
|
6
|
+
import './navigation-item-base-5ljwtLG_.js';
|
|
7
7
|
import './query-CHb9Ft_d.js';
|
|
8
8
|
import './base-Cl6v8-BZ.js';
|
|
9
9
|
import './class-map-NDIkZErE.js';
|
|
10
10
|
import './directive-ZPhl09Yt.js';
|
|
11
|
-
import './
|
|
11
|
+
import './dispatch-event-utils-DfgqVBK8.js';
|
|
12
|
+
import './throttle-C7ZAPqtu.js';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* @label Navigation Rail Item
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigation-rail-item.js","sources":["../../src/navigation-rail/navigation-rail-item.ts"],"sourcesContent":["import { property } from 'lit/decorators.js';\nimport IndividualComponent from '@/IndividualComponent.js';\nimport { IndicatorNavigationItem } from '@/__internal/indicator-navigation-item.js';\n\n/**\n * @label Navigation Rail Item\n * @tag wc-navigation-rail-item\n * @rawTag navigation-rail-item\n *\n * @summary A destination in a navigation rail.\n * @overview\n * <p>Shows an icon inside the active-indicator pill with an optional label below. The current\n * item (<code>current</code>) gets the indicator and <code>aria-current=\"page\"</code>. With\n * <code>href</code> it renders a link, otherwise a button.</p>\n *\n * @slot - The label.\n * @slot icon - The icon.\n * @slot active-icon - Icon shown instead of `icon` while the item is current, such as a filled variant.\n * @slot badge - Badge on the icon, such as a count. Overrides the `badge` attribute.\n *\n * @example\n * ```html\n * <wc-navigation-rail-item current>\n * <wc-icon slot=\"icon\" name=\"home\"></wc-icon>\n * Home\n * </wc-navigation-rail-item>\n * ```\n * @tags navigation\n */\n@IndividualComponent\nexport class NavigationRailItem extends IndicatorNavigationItem {\n // ── Properties ───────────────────────────────────────────────────────────\n\n /** Whether the parent rail is in collapsed mode (labels hidden). Set by the rail. */\n @property({ type: Boolean, reflect: true }) collapsed = false;\n\n // ── Protected methods ────────────────────────────────────────────────────\n\n protected override get labelHidden(): boolean {\n return this.collapsed;\n }\n}\n"],"names":["property"],"mappings":"
|
|
1
|
+
{"version":3,"file":"navigation-rail-item.js","sources":["../../src/navigation-rail/navigation-rail-item.ts"],"sourcesContent":["import { property } from 'lit/decorators.js';\nimport IndividualComponent from '@/IndividualComponent.js';\nimport { IndicatorNavigationItem } from '@/__internal/indicator-navigation-item.js';\n\n/**\n * @label Navigation Rail Item\n * @tag wc-navigation-rail-item\n * @rawTag navigation-rail-item\n *\n * @summary A destination in a navigation rail.\n * @overview\n * <p>Shows an icon inside the active-indicator pill with an optional label below. The current\n * item (<code>current</code>) gets the indicator and <code>aria-current=\"page\"</code>. With\n * <code>href</code> it renders a link, otherwise a button.</p>\n *\n * @slot - The label.\n * @slot icon - The icon.\n * @slot active-icon - Icon shown instead of `icon` while the item is current, such as a filled variant.\n * @slot badge - Badge on the icon, such as a count. Overrides the `badge` attribute.\n *\n * @example\n * ```html\n * <wc-navigation-rail-item current>\n * <wc-icon slot=\"icon\" name=\"home\"></wc-icon>\n * Home\n * </wc-navigation-rail-item>\n * ```\n * @tags navigation\n */\n@IndividualComponent\nexport class NavigationRailItem extends IndicatorNavigationItem {\n // ── Properties ───────────────────────────────────────────────────────────\n\n /** Whether the parent rail is in collapsed mode (labels hidden). Set by the rail. */\n @property({ type: Boolean, reflect: true }) collapsed = false;\n\n // ── Protected methods ────────────────────────────────────────────────────\n\n protected override get labelHidden(): boolean {\n return this.collapsed;\n }\n}\n"],"names":["property"],"mappings":";;;;;;;;;;;;;AAIA;;;;;;;;;;;;;;;;;;;;;;;;AAwBG;AAEI,IAAM,kBAAkB,GAAxB,MAAM,kBAAmB,SAAQ,uBAAuB,CAAA;AAAxD,IAAA,WAAA,GAAA;;;;QAIuC,IAAA,CAAA,SAAS,GAAG,KAAK;IAO/D;;AAHE,IAAA,IAAuB,WAAW,GAAA;QAChC,OAAO,IAAI,CAAC,SAAS;IACvB;;AAN4C,UAAA,CAAA;IAA3CA,CAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE;AAAoB,CAAA,EAAA,kBAAA,CAAA,SAAA,EAAA,WAAA,EAAA,MAAA,CAAA;AAJnD,kBAAkB,GAAA,UAAA,CAAA;IAD9B;AACY,CAAA,EAAA,kBAAkB,CAW9B;;;;"}
|
package/dist/navigation-rail.js
CHANGED
|
@@ -3,14 +3,15 @@ import { n } from './property-B2TG3KEE.js';
|
|
|
3
3
|
import { e } from './class-map-NDIkZErE.js';
|
|
4
4
|
import { NavigationRailItem } from './navigation-rail-item.js';
|
|
5
5
|
import { I as I18nController } from './i18n-controller-BTeChxE0.js';
|
|
6
|
-
import { s as selectNavigationItem } from './navigation-item-base-
|
|
6
|
+
import { s as selectNavigationItem } from './navigation-item-base-5ljwtLG_.js';
|
|
7
7
|
import './directive-ZPhl09Yt.js';
|
|
8
|
-
import './indicator-navigation-item-
|
|
8
|
+
import './indicator-navigation-item-BsQE3kUr.js';
|
|
9
9
|
import './state-BCeDVCI9.js';
|
|
10
10
|
import './observe-slot-change-DPxaZrZF.js';
|
|
11
11
|
import './query-CHb9Ft_d.js';
|
|
12
12
|
import './base-Cl6v8-BZ.js';
|
|
13
|
-
import './
|
|
13
|
+
import './dispatch-event-utils-DfgqVBK8.js';
|
|
14
|
+
import './throttle-C7ZAPqtu.js';
|
|
14
15
|
import './strings-DeiQWMd9.js';
|
|
15
16
|
import './locale-DEsJZCQG.js';
|
|
16
17
|
|
|
@@ -64,12 +65,12 @@ var css_248z = i`* {
|
|
|
64
65
|
display: flex;
|
|
65
66
|
flex-direction: column;
|
|
66
67
|
align-items: center;
|
|
67
|
-
height:
|
|
68
|
+
min-height: 100%;
|
|
68
69
|
width: 100%;
|
|
69
70
|
border-radius: inherit;
|
|
70
71
|
background-color: var(--nav-rail-container-color);
|
|
71
72
|
color: var(--nav-rail-label-text-color);
|
|
72
|
-
|
|
73
|
+
padding-block: var(--nav-rail-padding-block); /* 24dp */
|
|
73
74
|
box-sizing: border-box;
|
|
74
75
|
}
|
|
75
76
|
.rail .header {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigation-rail.js","sources":["../../src/navigation-rail/navigation-rail.ts"],"sourcesContent":["import { html, LitElement, PropertyValues } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport styles from './navigation-rail.scss';\nimport { NavigationRailItem } from './navigation-rail-item.js';\nimport IndividualComponent from '@/IndividualComponent.js';\nimport { I18nController } from '@/__internal/i18n/i18n-controller.js';\nimport { selectNavigationItem } from '@/__internal/navigation-item-base.js';\n\n/**\n * @label Navigation Rail\n * @tag wc-navigation-rail\n * @rawTag navigation-rail\n *\n * @summary A vertical side navigation for medium-sized screens.\n * @overview\n * <p>Navigation rail provides access to primary destinations in an app using icons—with or without labels—on a vertical rail.</p>\n * <p>Use navigation rail on medium-sized screens (tablets) with 3–7 destinations. Clicking an item makes it the\n * current one (<code>aria-current=\"page\"</code>) and fires <code>change</code>.</p>\n *\n * @slot - The rail items.\n * @slot header - Content displayed above the rail items.\n * @slot footer - Content pinned to the bottom of the rail.\n *\n * @fires {CustomEvent<{value: string | undefined, index: number, item: NavigationRailItem}>} change - Dispatched when the user activates an item. *\n * @cssprop --nav-rail-width - Width of the rail container. Defaults to 5rem (80dp).\n * @cssprop --nav-rail-container-color - Background color of the rail. Defaults to surface color.\n * @cssprop --nav-rail-indicator-color - Color of the active indicator. Defaults to secondary-container.\n * @cssprop --nav-rail-indicator-shape - Shape (border-radius) of the active indicator. Defaults to full (pill).\n * @cssprop --nav-rail-indicator-width - Width of the active indicator. Defaults to 3.5rem (56dp).\n * @cssprop --nav-rail-indicator-height - Height of the active indicator. Defaults to 2rem (32dp).\n * @cssprop --nav-rail-inactive-icon-color - Color of inactive icons. Defaults to on-surface-variant.\n * @cssprop --nav-rail-active-icon-color - Color of active icons. Defaults to on-secondary-container.\n * @cssprop --nav-rail-inactive-label-color - Color of inactive labels. Defaults to on-surface-variant.\n * @cssprop --nav-rail-active-label-color - Color of active labels. Defaults to on-surface.\n *\n * @example\n * ```html\n * <wc-navigation-rail>\n * <wc-navigation-rail-item current>\n * <wc-icon slot=\"icon\" name=\"home\"></wc-icon>\n * Home\n * </wc-navigation-rail-item>\n * <wc-navigation-rail-item>\n * <wc-icon slot=\"icon\" name=\"search\"></wc-icon>\n * Search\n * </wc-navigation-rail-item>\n * </wc-navigation-rail>\n * ```\n * @tags navigation\n */\n@IndividualComponent\nexport class NavigationRail extends LitElement {\n // ── Static ───────────────────────────────────────────────────────────────\n\n static styles = [styles];\n\n static Item = NavigationRailItem;\n\n // ── Properties ───────────────────────────────────────────────────────────\n\n /**\n * Display mode of the navigation rail.\n * - `\"expanded\"`: shows labels.\n * - `\"collapsed\"`: hides labels.\n */\n @property({ reflect: true }) mode: 'expanded' | 'collapsed' = 'expanded';\n\n /** Whether to show a divider between the header and items sections. */\n @property({ type: Boolean, attribute: 'show-divider' }) showDivider = false;\n\n // ── Private fields ───────────────────────────────────────────────────────\n\n /** Peacock's strings for the default landmark label. */\n private readonly i18n = new I18nController(this);\n\n /** The `aria-label` the rail set itself, so it follows the string table until the author sets one. */\n private defaultLabel?: string;\n\n // ── Lifecycle ────────────────────────────────────────────────────────────\n\n override connectedCallback() {\n super.connectedCallback();\n this.addEventListener('click', this.handleItemClick);\n this.setAttribute('role', 'navigation');\n this.syncLabel();\n }\n\n override disconnectedCallback() {\n this.removeEventListener('click', this.handleItemClick);\n super.disconnectedCallback();\n }\n\n protected override willUpdate() {\n this.syncLabel();\n }\n\n protected override firstUpdated() {\n this.syncItemMode();\n }\n\n protected override updated(changedProperties: PropertyValues<this>) {\n if (changedProperties.has('mode')) {\n this.syncItemMode();\n }\n }\n\n // ── Private methods ──────────────────────────────────────────────────────\n\n private handleItemClick = (event: Event) => {\n selectNavigationItem<NavigationRailItem>(\n this,\n event,\n 'wc-navigation-rail-item',\n );\n };\n\n /** Gives the landmark the default label unless the author set one. */\n private syncLabel() {\n const current = this.getAttribute('aria-label');\n if (current !== null && current !== this.defaultLabel) return;\n this.defaultLabel = this.i18n.t('mainNavigation');\n this.setAttribute('aria-label', this.defaultLabel);\n }\n\n private getItems(): NavigationRailItem[] {\n return Array.from(\n this.querySelectorAll<NavigationRailItem>('wc-navigation-rail-item'),\n );\n }\n\n private syncItemMode = () => {\n const isCollapsed = this.mode === 'collapsed';\n for (const railItem of this.getItems()) {\n railItem.collapsed = isCollapsed;\n }\n };\n\n // ── Render ───────────────────────────────────────────────────────────────\n\n render() {\n const cssClasses = {\n rail: true,\n [`mode-${this.mode}`]: true,\n };\n\n return html`\n <div class=${classMap(cssClasses)}>\n <div class=\"header\">\n <slot name=\"header\"></slot>\n </div>\n ${this.showDivider ? html`<wc-divider></wc-divider>` : ''}\n <div class=\"items\">\n <slot @slotchange=${this.syncItemMode}></slot>\n </div>\n <div class=\"footer\">\n <slot name=\"footer\"></slot>\n </div>\n </div>\n `;\n }\n}\n"],"names":["LitElement","html","classMap","styles","property"],"mappings":"
|
|
1
|
+
{"version":3,"file":"navigation-rail.js","sources":["../../src/navigation-rail/navigation-rail.ts"],"sourcesContent":["import { html, LitElement, PropertyValues } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport styles from './navigation-rail.scss';\nimport { NavigationRailItem } from './navigation-rail-item.js';\nimport IndividualComponent from '@/IndividualComponent.js';\nimport { I18nController } from '@/__internal/i18n/i18n-controller.js';\nimport { selectNavigationItem } from '@/__internal/navigation-item-base.js';\n\n/**\n * @label Navigation Rail\n * @tag wc-navigation-rail\n * @rawTag navigation-rail\n *\n * @summary A vertical side navigation for medium-sized screens.\n * @overview\n * <p>Navigation rail provides access to primary destinations in an app using icons—with or without labels—on a vertical rail.</p>\n * <p>Use navigation rail on medium-sized screens (tablets) with 3–7 destinations. Clicking an item makes it the\n * current one (<code>aria-current=\"page\"</code>) and fires <code>change</code>.</p>\n *\n * @slot - The rail items.\n * @slot header - Content displayed above the rail items.\n * @slot footer - Content pinned to the bottom of the rail.\n *\n * @fires {CustomEvent<{value: string | undefined, index: number, item: NavigationRailItem}>} change - Dispatched when the user activates an item. *\n * @cssprop --nav-rail-width - Width of the rail container. Defaults to 5rem (80dp).\n * @cssprop --nav-rail-container-color - Background color of the rail. Defaults to surface color.\n * @cssprop --nav-rail-indicator-color - Color of the active indicator. Defaults to secondary-container.\n * @cssprop --nav-rail-indicator-shape - Shape (border-radius) of the active indicator. Defaults to full (pill).\n * @cssprop --nav-rail-indicator-width - Width of the active indicator. Defaults to 3.5rem (56dp).\n * @cssprop --nav-rail-indicator-height - Height of the active indicator. Defaults to 2rem (32dp).\n * @cssprop --nav-rail-inactive-icon-color - Color of inactive icons. Defaults to on-surface-variant.\n * @cssprop --nav-rail-active-icon-color - Color of active icons. Defaults to on-secondary-container.\n * @cssprop --nav-rail-inactive-label-color - Color of inactive labels. Defaults to on-surface-variant.\n * @cssprop --nav-rail-active-label-color - Color of active labels. Defaults to on-surface.\n *\n * @example\n * ```html\n * <wc-navigation-rail>\n * <wc-navigation-rail-item current>\n * <wc-icon slot=\"icon\" name=\"home\"></wc-icon>\n * Home\n * </wc-navigation-rail-item>\n * <wc-navigation-rail-item>\n * <wc-icon slot=\"icon\" name=\"search\"></wc-icon>\n * Search\n * </wc-navigation-rail-item>\n * </wc-navigation-rail>\n * ```\n * @tags navigation\n */\n@IndividualComponent\nexport class NavigationRail extends LitElement {\n // ── Static ───────────────────────────────────────────────────────────────\n\n static styles = [styles];\n\n static Item = NavigationRailItem;\n\n // ── Properties ───────────────────────────────────────────────────────────\n\n /**\n * Display mode of the navigation rail.\n * - `\"expanded\"`: shows labels.\n * - `\"collapsed\"`: hides labels.\n */\n @property({ reflect: true }) mode: 'expanded' | 'collapsed' = 'expanded';\n\n /** Whether to show a divider between the header and items sections. */\n @property({ type: Boolean, attribute: 'show-divider' }) showDivider = false;\n\n // ── Private fields ───────────────────────────────────────────────────────\n\n /** Peacock's strings for the default landmark label. */\n private readonly i18n = new I18nController(this);\n\n /** The `aria-label` the rail set itself, so it follows the string table until the author sets one. */\n private defaultLabel?: string;\n\n // ── Lifecycle ────────────────────────────────────────────────────────────\n\n override connectedCallback() {\n super.connectedCallback();\n this.addEventListener('click', this.handleItemClick);\n this.setAttribute('role', 'navigation');\n this.syncLabel();\n }\n\n override disconnectedCallback() {\n this.removeEventListener('click', this.handleItemClick);\n super.disconnectedCallback();\n }\n\n protected override willUpdate() {\n this.syncLabel();\n }\n\n protected override firstUpdated() {\n this.syncItemMode();\n }\n\n protected override updated(changedProperties: PropertyValues<this>) {\n if (changedProperties.has('mode')) {\n this.syncItemMode();\n }\n }\n\n // ── Private methods ──────────────────────────────────────────────────────\n\n private handleItemClick = (event: Event) => {\n selectNavigationItem<NavigationRailItem>(\n this,\n event,\n 'wc-navigation-rail-item',\n );\n };\n\n /** Gives the landmark the default label unless the author set one. */\n private syncLabel() {\n const current = this.getAttribute('aria-label');\n if (current !== null && current !== this.defaultLabel) return;\n this.defaultLabel = this.i18n.t('mainNavigation');\n this.setAttribute('aria-label', this.defaultLabel);\n }\n\n private getItems(): NavigationRailItem[] {\n return Array.from(\n this.querySelectorAll<NavigationRailItem>('wc-navigation-rail-item'),\n );\n }\n\n private syncItemMode = () => {\n const isCollapsed = this.mode === 'collapsed';\n for (const railItem of this.getItems()) {\n railItem.collapsed = isCollapsed;\n }\n };\n\n // ── Render ───────────────────────────────────────────────────────────────\n\n render() {\n const cssClasses = {\n rail: true,\n [`mode-${this.mode}`]: true,\n };\n\n return html`\n <div class=${classMap(cssClasses)}>\n <div class=\"header\">\n <slot name=\"header\"></slot>\n </div>\n ${this.showDivider ? html`<wc-divider></wc-divider>` : ''}\n <div class=\"items\">\n <slot @slotchange=${this.syncItemMode}></slot>\n </div>\n <div class=\"footer\">\n <slot name=\"footer\"></slot>\n </div>\n </div>\n `;\n }\n}\n"],"names":["LitElement","html","classMap","styles","property"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCG;AAEI,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQA,GAAU,CAAA;AAAvC,IAAA,WAAA,GAAA;;;;AASL;;;;AAIG;QAC0B,IAAA,CAAA,IAAI,GAA6B,UAAU;;QAGhB,IAAA,CAAA,WAAW,GAAG,KAAK;;;AAK1D,QAAA,IAAA,CAAA,IAAI,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC;;AAmCxC,QAAA,IAAA,CAAA,eAAe,GAAG,CAAC,KAAY,KAAI;AACzC,YAAA,oBAAoB,CAClB,IAAI,EACJ,KAAK,EACL,yBAAyB,CAC1B;AACH,QAAA,CAAC;QAgBO,IAAA,CAAA,YAAY,GAAG,MAAK;AAC1B,YAAA,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,KAAK,WAAW;YAC7C,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,QAAQ,EAAE,EAAE;AACtC,gBAAA,QAAQ,CAAC,SAAS,GAAG,WAAW;YAClC;AACF,QAAA,CAAC;IAyBH;;IAhFW,iBAAiB,GAAA;QACxB,KAAK,CAAC,iBAAiB,EAAE;QACzB,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,eAAe,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AC,YAAY,CAAA;;;;;;KAM1C;IACH;;AAzGO,cAAA,CAAA,MAAM,GAAG,CAACE,QAAM,CAAC;AAEjB,cAAA,CAAA,IAAI,GAAG,kBAAH;AASkB,UAAA,CAAA;AAA5B,IAAAC,CAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE;AAA8C,CAAA,EAAA,cAAA,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,CAAA;AAGjB,UAAA,CAAA;IAAvDA,CAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE;AAAsB,CAAA,EAAA,cAAA,CAAA,SAAA,EAAA,aAAA,EAAA,MAAA,CAAA;AAjBjE,cAAc,GAAA,UAAA,CAAA;IAD1B;AACY,CAAA,EAAA,cAAc,CA6G1B;;;;"}
|
package/dist/number-field.js
CHANGED
|
@@ -5,13 +5,16 @@ import { e as e$1 } from './class-map-NDIkZErE.js';
|
|
|
5
5
|
import { o } from './if-defined-D9DEJR_6.js';
|
|
6
6
|
import { s as spread } from './spread-B5cgadZl.js';
|
|
7
7
|
import { I as I18nController } from './i18n-controller-BTeChxE0.js';
|
|
8
|
-
import { B as BaseField } from './BaseField-
|
|
8
|
+
import { B as BaseField } from './BaseField-DOCmylob.js';
|
|
9
9
|
import { n as nativeValidity } from './BaseInput-Cv03GZLu.js';
|
|
10
10
|
import './base-Cl6v8-BZ.js';
|
|
11
11
|
import './directive-ZPhl09Yt.js';
|
|
12
12
|
import './strings-DeiQWMd9.js';
|
|
13
13
|
import './locale-DEsJZCQG.js';
|
|
14
14
|
import './state-BCeDVCI9.js';
|
|
15
|
+
import './implicit-submission-ChLdbxaR.js';
|
|
16
|
+
import './dispatch-hooks-J_godlHh.js';
|
|
17
|
+
import './form-submission-h40coUI8.js';
|
|
15
18
|
import './element-internals-QME0yEz4.js';
|
|
16
19
|
import './form-associated-BHbg72PG.js';
|
|
17
20
|
import './suggestion-controller-7YRQqkaI.js';
|
package/dist/number-field.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number-field.js","sources":["../../src/number-field/number-field.ts"],"sourcesContent":["import { html, nothing } from 'lit';\nimport { property, query } from 'lit/decorators.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { ifDefined } from 'lit/directives/if-defined.js';\n\nimport { spread } from '@/__internal/directive/spread.js';\nimport { I18nController } from '@/__internal/i18n/i18n-controller.js';\nimport type { FormRestoreState } from '@/__internal/mixins/form-associated.js';\n\nimport IndividualComponent from '@/IndividualComponent.js';\nimport BaseField from '../input/BaseField.js';\nimport { type ControlValidity, nativeValidity } from '../input/BaseInput.js';\nimport styles from './number-field.scss';\n\n/**\n * @label Number Field\n * @tag wc-number-field\n * @rawTag number-field\n *\n * @summary A text field for a number, with optional buttons that step it down and up.\n * @overview\n * <p>Number Field is form-associated: inside a <code><form></code> its <code>value</code> is\n * submitted under its <code>name</code>, and <code>form.reset()</code> restores the starting value.</p>\n * <p>It validates like a native number input: <code>required</code>, <code>min</code>,\n * <code>max</code> and <code>step</code> block form submission, and the message shows under the\n * field once the value is committed or the form is submitted.</p>\n * <p>For money, use <code>wc-currency-field</code>: its value is an exact decimal string with the\n * currency's number of decimals, where this field's value is a JavaScript number.</p>\n *\n * @fires {CustomEvent<{value: number | undefined}>} input - Dispatched as the user types or steps the value.\n * @fires {CustomEvent<{value: number | undefined}>} change - Dispatched when the value is committed.\n *\n * @example\n * ```html\n * <wc-number-field label=\"Age\" placeholder=\"Enter your age\"></wc-number-field>\n * ```\n */\n@IndividualComponent\nexport class NumberField extends BaseField {\n // ── Static ───────────────────────────────────────────────────────────────\n\n static styles = [styles];\n\n // ── Properties ───────────────────────────────────────────────────────────\n\n @property({ type: Number })\n value?: number;\n\n /** The largest value allowed. */\n @property({ type: Number })\n max?: number;\n\n /** The smallest value allowed. */\n @property({ type: Number })\n min?: number;\n\n /** How much the value changes per step, and the granularity a valid value must match. */\n @property({ type: Number })\n step?: number;\n\n /** Whether the browser may autofill the field: `\"on\"` or `\"off\"` (default). */\n @property({ type: String })\n autocomplete: 'on' | 'off' = 'off';\n\n /** Shows buttons that step the value down and up. */\n @property({ type: Boolean })\n stepper: boolean = false;\n\n /**\n * How to show the value while the field is not focused, as `Intl.NumberFormat` options (for\n * example `{ style: 'currency', currency: 'EUR' }`). While focused the field shows the plain\n * number to edit. `value` stays a number either way. Formatted in the field's locale: the\n * nearest `lang`, else the browser's.\n */\n @property({ type: Object })\n format?: Intl.NumberFormatOptions;\n\n // ── Queries ──────────────────────────────────────────────────────────────\n\n @query('.input-element')\n private inputElement?: HTMLInputElement;\n\n // ── Private fields ───────────────────────────────────────────────────────\n\n /** Peacock's strings for the stepper buttons. */\n private readonly i18n = new I18nController(this);\n\n // ── Public methods ───────────────────────────────────────────────────────\n\n override focus() {\n this.inputElement?.focus();\n }\n\n override blur() {\n this.inputElement?.blur();\n }\n\n // ── Protected methods ────────────────────────────────────────────────────\n\n protected override computeValidity(): ControlValidity {\n return this.inputElement\n ? nativeValidity(this.inputElement)\n : super.computeValidity();\n }\n\n protected override validityAnchor() {\n // `@query` gives null before the first render.\n return this.inputElement ?? undefined;\n }\n\n protected override parseRestoreState(state: FormRestoreState): unknown {\n if (typeof state !== 'string' || state.trim() === '') return undefined;\n const number = Number(state);\n return Number.isNaN(number) ? undefined : number;\n }\n\n protected override clearValue() {\n this.value = undefined;\n this.emitValue('input');\n this.emitValue('change');\n }\n\n // ── Private methods ──────────────────────────────────────────────────────\n\n /** The value as `format` shows it, or '' when there is nothing to format. */\n private formattedValue(): string {\n if (!this.format || this.value === undefined) return '';\n try {\n return new Intl.NumberFormat(this.i18n.locale, this.format).format(\n this.value,\n );\n } catch {\n // Options Intl rejects (such as a currency style without a currency): show the number.\n return String(this.value);\n }\n }\n\n /** The input's value as a number, or `undefined` when it is empty or not a number. */\n private static __toValue(input: HTMLInputElement): number | undefined {\n const number = input.valueAsNumber;\n return Number.isNaN(number) ? undefined : number;\n }\n\n private __handleInput(event: Event) {\n // Replace the native event, which escapes the shadow root, with the field's own.\n event.stopPropagation();\n this.value = NumberField.__toValue(event.target as HTMLInputElement);\n this.emitValue('input');\n }\n\n private __handleChange(event: Event) {\n event.stopPropagation();\n this.emitValue('change');\n }\n\n private stepUp() {\n this.__step(1);\n }\n\n private stepDown() {\n this.__step(-1);\n }\n\n /**\n * Steps the value like the native spinner. `stepUp()`/`stepDown()` fire no events, so this\n * updates `value` and emits `input` and `change` itself.\n */\n private __step(direction: 1 | -1) {\n const input = this.inputElement;\n if (!input || this.disabled || this.readonly) return;\n if (direction === 1) input.stepUp();\n else input.stepDown();\n this.value = NumberField.__toValue(input);\n this.emitValue('input');\n this.emitValue('change');\n }\n\n // ── Render helpers ───────────────────────────────────────────────────────\n\n private renderStepper(direction: 'up' | 'down') {\n if (!this.stepper || this.disabled || this.readonly) return nothing;\n const up = direction === 'up';\n return html`<wc-icon-button\n class=\"stepper\"\n variant=\"text\"\n slot=${up ? 'field-end' : 'field-start'}\n aria-label=${up ? this.i18n.t('increase') : this.i18n.t('decrease')}\n @click=${up ? this.stepUp : this.stepDown}\n >\n <wc-icon name=${up ? 'add' : 'remove'}></wc-icon>\n </wc-icon-button>`;\n }\n\n // ── Render ───────────────────────────────────────────────────────────────\n\n render() {\n // The formatted text covers the input while it is not focused; the input keeps the number, so\n // validation and editing work on the raw value.\n const formatted = this.focused ? '' : this.formattedValue();\n const classes = {\n input: true,\n 'input-element': true,\n 'no-spin-buttons': this.stepper,\n 'show-formatted': !!formatted,\n };\n\n const input = html`<input\n class=${classMap(classes)}\n type=\"number\"\n placeholder=${this.placeholder}\n autocomplete=${this.autocomplete}\n .value=${this.value === undefined ? '' : String(this.value)}\n ?readonly=${this.readonly}\n ?required=${this.required}\n ?disabled=${this.disabled}\n min=${ifDefined(this.min)}\n max=${ifDefined(this.max)}\n step=${ifDefined(this.step)}\n @input=${this.__handleInput}\n @change=${this.__handleChange}\n @focus=${this.handleFieldFocus}\n @blur=${this.handleFieldFocus}\n ${spread(this.fieldAria())}\n />`;\n\n const control = this.format\n ? html`<span class=\"format-control\">\n ${input}\n ${formatted\n ? html`<span class=\"formatted\" aria-hidden=\"true\"\n >${formatted}</span\n >`\n : nothing}\n </span>`\n : input;\n\n return this.renderField(control, {\n populated: this.value !== undefined,\n start: this.renderStepper('down'),\n end: this.renderStepper('up'),\n });\n }\n}\n"],"names":["nothing","html","classMap","ifDefined","styles","property","query"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA;;;;;;;;;;;;;;;;;;;;;;AAsBG;AAEI,IAAM,WAAW,GAAA,aAAA,GAAjB,MAAM,WAAY,SAAQ,SAAS,CAAA;AAAnC,IAAA,WAAA,GAAA;;;;QAwBL,IAAA,CAAA,YAAY,GAAiB,KAAK;;QAIlC,IAAA,CAAA,OAAO,GAAY,KAAK;;;AAmBP,QAAA,IAAA,CAAA,IAAI,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC;IA6JlD;;IAzJW,KAAK,GAAA;AACZ,QAAA,IAAI,CAAC,YAAY,EAAE,KAAK,EAAE;IAC5B;IAES,IAAI,GAAA;AACX,QAAA,IAAI,CAAC,YAAY,EAAE,IAAI,EAAE;IAC3B;;IAImB,eAAe,GAAA;QAChC,OAAO,IAAI,CAAC;AACV,cAAE,cAAc,CAAC,IAAI,CAAC,YAAY;AAClC,cAAE,KAAK,CAAC,eAAe,EAAE;IAC7B;IAEmB,cAAc,GAAA;;AAE/B,QAAA,OAAO,IAAI,CAAC,YAAY,IAAI,SAAS;IACvC;AAEmB,IAAA,iBAAiB,CAAC,KAAuB,EAAA;QAC1D,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE;AAAE,YAAA,OAAO,SAAS;AACtE,QAAA,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,C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A,EAAA,WAAW,CA4MvB;;;;"}
|
|
1
|
+
{"version":3,"file":"number-field.js","sources":["../../src/number-field/number-field.ts"],"sourcesContent":["import { html, nothing } from 'lit';\nimport { property, query } from 'lit/decorators.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { ifDefined } from 'lit/directives/if-defined.js';\n\nimport { spread } from '@/__internal/directive/spread.js';\nimport { I18nController } from '@/__internal/i18n/i18n-controller.js';\nimport type { FormRestoreState } from '@/__internal/mixins/form-associated.js';\n\nimport IndividualComponent from '@/IndividualComponent.js';\nimport BaseField from '../input/BaseField.js';\nimport { type ControlValidity, nativeValidity } from '../input/BaseInput.js';\nimport styles from './number-field.scss';\n\n/**\n * @label Number Field\n * @tag wc-number-field\n * @rawTag number-field\n *\n * @summary A text field for a number, with optional buttons that step it down and up.\n * @overview\n * <p>Number Field is form-associated: inside a <code><form></code> its <code>value</code> is\n * submitted under its <code>name</code>, and <code>form.reset()</code> restores the starting value.</p>\n * <p>It validates like a native number input: <code>required</code>, <code>min</code>,\n * <code>max</code> and <code>step</code> block form submission, and the message shows under the\n * field once the value is committed or the form is submitted.</p>\n * <p>For money, use <code>wc-currency-field</code>: its value is an exact decimal string with the\n * currency's number of decimals, where this field's value is a JavaScript number.</p>\n *\n * @fires {CustomEvent<{value: number | undefined}>} input - Dispatched as the user types or steps the value.\n * @fires {CustomEvent<{value: number | undefined}>} change - Dispatched when the value is committed.\n *\n * @example\n * ```html\n * <wc-number-field label=\"Age\" placeholder=\"Enter your age\"></wc-number-field>\n * ```\n */\n@IndividualComponent\nexport class NumberField extends BaseField {\n // ── Static ───────────────────────────────────────────────────────────────\n\n static styles = [styles];\n\n // ── Properties ───────────────────────────────────────────────────────────\n\n @property({ type: Number })\n value?: number;\n\n /** The largest value allowed. */\n @property({ type: Number })\n max?: number;\n\n /** The smallest value allowed. */\n @property({ type: Number })\n min?: number;\n\n /** How much the value changes per step, and the granularity a valid value must match. */\n @property({ type: Number })\n step?: number;\n\n /** Whether the browser may autofill the field: `\"on\"` or `\"off\"` (default). */\n @property({ type: String })\n autocomplete: 'on' | 'off' = 'off';\n\n /** Shows buttons that step the value down and up. */\n @property({ type: Boolean })\n stepper: boolean = false;\n\n /**\n * How to show the value while the field is not focused, as `Intl.NumberFormat` options (for\n * example `{ style: 'currency', currency: 'EUR' }`). While focused the field shows the plain\n * number to edit. `value` stays a number either way. Formatted in the field's locale: the\n * nearest `lang`, else the browser's.\n */\n @property({ type: Object })\n format?: Intl.NumberFormatOptions;\n\n // ── Queries ──────────────────────────────────────────────────────────────\n\n @query('.input-element')\n private inputElement?: HTMLInputElement;\n\n // ── Private fields ───────────────────────────────────────────────────────\n\n /** Peacock's strings for the stepper buttons. */\n private readonly i18n = new I18nController(this);\n\n // ── Public methods ───────────────────────────────────────────────────────\n\n override focus() {\n this.inputElement?.focus();\n }\n\n override blur() {\n this.inputElement?.blur();\n }\n\n // ── Protected methods ────────────────────────────────────────────────────\n\n protected override computeValidity(): ControlValidity {\n return this.inputElement\n ? nativeValidity(this.inputElement)\n : super.computeValidity();\n }\n\n protected override validityAnchor() {\n // `@query` gives null before the first render.\n return this.inputElement ?? undefined;\n }\n\n protected override parseRestoreState(state: FormRestoreState): unknown {\n if (typeof state !== 'string' || state.trim() === '') return undefined;\n const number = Number(state);\n return Number.isNaN(number) ? undefined : number;\n }\n\n protected override clearValue() {\n this.value = undefined;\n this.emitValue('input');\n this.emitValue('change');\n }\n\n // ── Private methods ──────────────────────────────────────────────────────\n\n /** The value as `format` shows it, or '' when there is nothing to format. */\n private formattedValue(): string {\n if (!this.format || this.value === undefined) return '';\n try {\n return new Intl.NumberFormat(this.i18n.locale, this.format).format(\n this.value,\n );\n } catch {\n // Options Intl rejects (such as a currency style without a currency): show the number.\n return String(this.value);\n }\n }\n\n /** The input's value as a number, or `undefined` when it is empty or not a number. */\n private static __toValue(input: HTMLInputElement): number | undefined {\n const number = input.valueAsNumber;\n return Number.isNaN(number) ? undefined : number;\n }\n\n private __handleInput(event: Event) {\n // Replace the native event, which escapes the shadow root, with the field's own.\n event.stopPropagation();\n this.value = NumberField.__toValue(event.target as HTMLInputElement);\n this.emitValue('input');\n }\n\n private __handleChange(event: Event) {\n event.stopPropagation();\n this.emitValue('change');\n }\n\n private stepUp() {\n this.__step(1);\n }\n\n private stepDown() {\n this.__step(-1);\n }\n\n /**\n * Steps the value like the native spinner. `stepUp()`/`stepDown()` fire no events, so this\n * updates `value` and emits `input` and `change` itself.\n */\n private __step(direction: 1 | -1) {\n const input = this.inputElement;\n if (!input || this.disabled || this.readonly) return;\n if (direction === 1) input.stepUp();\n else input.stepDown();\n this.value = NumberField.__toValue(input);\n this.emitValue('input');\n this.emitValue('change');\n }\n\n // ── Render helpers ───────────────────────────────────────────────────────\n\n private renderStepper(direction: 'up' | 'down') {\n if (!this.stepper || this.disabled || this.readonly) return nothing;\n const up = direction === 'up';\n return html`<wc-icon-button\n class=\"stepper\"\n variant=\"text\"\n slot=${up ? 'field-end' : 'field-start'}\n aria-label=${up ? this.i18n.t('increase') : this.i18n.t('decrease')}\n @click=${up ? this.stepUp : this.stepDown}\n >\n <wc-icon name=${up ? 'add' : 'remove'}></wc-icon>\n </wc-icon-button>`;\n }\n\n // ── Render ───────────────────────────────────────────────────────────────\n\n render() {\n // The formatted text covers the input while it is not focused; the input keeps the number, so\n // validation and editing work on the raw value.\n const formatted = this.focused ? '' : this.formattedValue();\n const classes = {\n input: true,\n 'input-element': true,\n 'no-spin-buttons': this.stepper,\n 'show-formatted': !!formatted,\n };\n\n const input = html`<input\n class=${classMap(classes)}\n type=\"number\"\n placeholder=${this.placeholder}\n autocomplete=${this.autocomplete}\n .value=${this.value === undefined ? '' : String(this.value)}\n ?readonly=${this.readonly}\n ?required=${this.required}\n ?disabled=${this.disabled}\n min=${ifDefined(this.min)}\n max=${ifDefined(this.max)}\n step=${ifDefined(this.step)}\n @input=${this.__handleInput}\n @change=${this.__handleChange}\n @focus=${this.handleFieldFocus}\n @blur=${this.handleFieldFocus}\n ${spread(this.fieldAria())}\n />`;\n\n const control = this.format\n ? html`<span class=\"format-control\">\n ${input}\n ${formatted\n ? html`<span class=\"formatted\" aria-hidden=\"true\"\n >${formatted}</span\n >`\n : nothing}\n </span>`\n : input;\n\n return this.renderField(control, {\n populated: this.value !== undefined,\n start: this.renderStepper('down'),\n end: this.renderStepper('up'),\n });\n }\n}\n"],"names":["nothing","html","classMap","ifDefined","styles","property","query"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA;;;;;;;;;;;;;;;;;;;;;;AAsBG;AAEI,IAAM,WAAW,GAAA,aAAA,GAAjB,MAAM,WAAY,SAAQ,SAAS,CAAA;AAAnC,IAAA,WAAA,GAAA;;;;QAwBL,IAAA,CAAA,YAAY,GAAiB,KAAK;;QAIlC,IAAA,CAAA,OAAO,GAAY,KAAK;;;AAmBP,QAAA,IAAA,CAAA,IAAI,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC;IA6JlD;;IAzJW,KAAK,GAAA;AACZ,QAAA,IAAI,CAAC,YAAY,EAAE,KAAK,EAAE;IAC5B;IAES,IAAI,GAAA;AACX,QAAA,IAAI,CAAC,YAAY,EAAE,IAAI,EAAE;IAC3B;;IAImB,eAAe,GAAA;QAChC,OAAO,IAAI,CAAC;AACV,cAAE,cAAc,CAAC,IAAI,CAAC,YAAY;AAClC,cAAE,KAAK,CAAC,eAAe,EAAE;IAC7B;IAEmB,cAAc,GAAA;;AAE/B,QAAA,OAAO,IAAI,CAAC,YAAY,IAAI,SAAS;IACvC;AAEmB,IAAA,iBAAiB,CAAC,KAAuB,EAAA;QAC1D,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE;AAAE,YAAA,OAAO,SAAS;AACtE,QAAA,MAAM,MAAM,GAAG,MAAM,CAAC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AACY,CAAA,EAAA,WAAW,CA4MvB;;;;"}
|
package/dist/option.js
CHANGED
|
@@ -6,11 +6,12 @@ import './base-Cl6v8-BZ.js';
|
|
|
6
6
|
import './if-defined-D9DEJR_6.js';
|
|
7
7
|
import './class-map-NDIkZErE.js';
|
|
8
8
|
import './directive-ZPhl09Yt.js';
|
|
9
|
-
import './base-button-
|
|
10
|
-
import './
|
|
9
|
+
import './base-button-9tGu5RSC.js';
|
|
10
|
+
import './activation-gate-D4IpmwyD.js';
|
|
11
11
|
import './warn-once-BNxX1Y98.js';
|
|
12
12
|
import './hyperlink-DycWPKwU.js';
|
|
13
13
|
import './element-internals-QME0yEz4.js';
|
|
14
|
+
import './dispatch-event-utils-DfgqVBK8.js';
|
|
14
15
|
import './is-link-Dk2OV3PM.js';
|
|
15
16
|
|
|
16
17
|
/**
|
package/dist/option.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"option.js","sources":["../../src/select/option.ts"],"sourcesContent":["import { html, nothing, type PropertyValues, type TemplateResult } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { MenuItem } from '../menu/menu-item/menu-item.js';\nimport IndividualComponent from '@/IndividualComponent.js';\n\n/**\n * @label Select Option\n * @tag wc-option\n * @rawTag option\n *\n * @summary One option in a select dropdown, with an optional icon before its label.\n * @overview\n * <p>Options are menu items with the <code>option</code> role. The selected option of a single select\n * shows a check mark at the end; in a multi-select every option shows a checkbox at the start.</p>\n *\n * @example\n * ```html\n * <wc-select label=\"Fruit\">\n * <wc-option value=\"apple\">Apple</wc-option>\n * <wc-option value=\"banana\">Banana</wc-option>\n * </wc-select>\n * ```\n */\n@IndividualComponent\nexport class SelectOptionElement extends MenuItem {\n /**\n * Optional Material Symbol icon name shown before the label.\n */\n @property({ type: String, reflect: true })\n icon: string = '';\n\n // ── Managed by wc-select ──────────────────────────────────────────────────\n\n /** Whether the option belongs to a multi-select, which shows a checkbox. Set by wc-select. */\n @property({ type: Boolean, reflect: true })\n multiple: boolean = false;\n\n /**\n * When true the option is hidden and skipped by keyboard navigation because it does not\n * match the current typeahead search query. Set by wc-select.\n */\n @property({ type: Boolean, reflect: true })\n filtered: boolean = false;\n\n /**\n * Marks the option the assistant suggested with a Suggested badge, while the select holds the\n * suggestion. Set by wc-select.\n */\n @property({ type: Boolean, reflect: true })\n suggested: boolean = false;\n\n protected override willUpdate(changed: PropertyValues<this>) {\n super.willUpdate(changed);\n if (changed.has('filtered')) {\n this.hidden = this.filtered;\n }\n if (changed.has('multiple')) {\n this.keepOpen = this.multiple;\n }\n }\n\n protected override get itemRole() {\n return 'option';\n }\n\n protected override get itemAriaSelected() {\n return String(this.selected);\n }\n\n protected override renderStart(): TemplateResult | typeof nothing {\n const checkbox = this.multiple\n ? html`<wc-icon\n class=\"indicator checkbox-indicator\"\n name=${this.selected ? 'check_box' : 'check_box_outline_blank'}\n aria-hidden=\"true\"\n ></wc-icon>`\n : nothing;\n const icon = this.icon\n ? html`<wc-icon name=${this.icon} aria-hidden=\"true\"></wc-icon>`\n : nothing;\n\n if (checkbox === nothing && icon === nothing) {\n return nothing;\n }\n\n return html`${checkbox}${icon}`;\n }\n\n protected override renderEnd(): TemplateResult | typeof nothing {\n // A multi-select shows its state in the leading checkbox instead of a trailing check.\n const end = this.multiple ? nothing : super.renderEnd();\n if (!this.suggested) return end;\n return html`<wc-ai-badge class=\"suggested-badge\"></wc-ai-badge>${end}`;\n }\n}\n"],"names":["html","nothing","property"],"mappings":"
|
|
1
|
+
{"version":3,"file":"option.js","sources":["../../src/select/option.ts"],"sourcesContent":["import { html, nothing, type PropertyValues, type TemplateResult } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { MenuItem } from '../menu/menu-item/menu-item.js';\nimport IndividualComponent from '@/IndividualComponent.js';\n\n/**\n * @label Select Option\n * @tag wc-option\n * @rawTag option\n *\n * @summary One option in a select dropdown, with an optional icon before its label.\n * @overview\n * <p>Options are menu items with the <code>option</code> role. The selected option of a single select\n * shows a check mark at the end; in a multi-select every option shows a checkbox at the start.</p>\n *\n * @example\n * ```html\n * <wc-select label=\"Fruit\">\n * <wc-option value=\"apple\">Apple</wc-option>\n * <wc-option value=\"banana\">Banana</wc-option>\n * </wc-select>\n * ```\n */\n@IndividualComponent\nexport class SelectOptionElement extends MenuItem {\n /**\n * Optional Material Symbol icon name shown before the label.\n */\n @property({ type: String, reflect: true })\n icon: string = '';\n\n // ── Managed by wc-select ──────────────────────────────────────────────────\n\n /** Whether the option belongs to a multi-select, which shows a checkbox. Set by wc-select. */\n @property({ type: Boolean, reflect: true })\n multiple: boolean = false;\n\n /**\n * When true the option is hidden and skipped by keyboard navigation because it does not\n * match the current typeahead search query. Set by wc-select.\n */\n @property({ type: Boolean, reflect: true })\n filtered: boolean = false;\n\n /**\n * Marks the option the assistant suggested with a Suggested badge, while the select holds the\n * suggestion. Set by wc-select.\n */\n @property({ type: Boolean, reflect: true })\n suggested: boolean = false;\n\n protected override willUpdate(changed: PropertyValues<this>) {\n super.willUpdate(changed);\n if (changed.has('filtered')) {\n this.hidden = this.filtered;\n }\n if (changed.has('multiple')) {\n this.keepOpen = this.multiple;\n }\n }\n\n protected override get itemRole() {\n return 'option';\n }\n\n protected override get itemAriaSelected() {\n return String(this.selected);\n }\n\n protected override renderStart(): TemplateResult | typeof nothing {\n const checkbox = this.multiple\n ? html`<wc-icon\n class=\"indicator checkbox-indicator\"\n name=${this.selected ? 'check_box' : 'check_box_outline_blank'}\n aria-hidden=\"true\"\n ></wc-icon>`\n : nothing;\n const icon = this.icon\n ? html`<wc-icon name=${this.icon} aria-hidden=\"true\"></wc-icon>`\n : nothing;\n\n if (checkbox === nothing && icon === nothing) {\n return nothing;\n }\n\n return html`${checkbox}${icon}`;\n }\n\n protected override renderEnd(): TemplateResult | typeof nothing {\n // A multi-select shows its state in the leading checkbox instead of a trailing check.\n const end = this.multiple ? nothing : super.renderEnd();\n if (!this.suggested) return end;\n return html`<wc-ai-badge class=\"suggested-badge\"></wc-ai-badge>${end}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as spread } from './spread-B5cgadZl.js';
|
|
7
7
|
import { I as I18nController } from './i18n-controller-BTeChxE0.js';
|
|
8
|
-
import {
|
|
8
|
+
import { s as setupImplicitSubmission } from './implicit-submission-ChLdbxaR.js';
|
|
9
|
+
import { B as BaseField } from './BaseField-DOCmylob.js';
|
|
9
10
|
import { n as nativeValidity } from './BaseInput-Cv03GZLu.js';
|
|
10
11
|
import './base-Cl6v8-BZ.js';
|
|
11
12
|
import './locale-DEsJZCQG.js';
|
|
12
13
|
import './directive-ZPhl09Yt.js';
|
|
13
14
|
import './strings-DeiQWMd9.js';
|
|
15
|
+
import './dispatch-hooks-J_godlHh.js';
|
|
16
|
+
import './form-submission-h40coUI8.js';
|
|
14
17
|
import './element-internals-QME0yEz4.js';
|
|
15
18
|
import './form-associated-BHbg72PG.js';
|
|
16
19
|
import './suggestion-controller-7YRQqkaI.js';
|
|
@@ -85,7 +88,8 @@ var _a;
|
|
|
85
88
|
* <p>It validates like a native password input: <code>required</code>, <code>minlength</code>,
|
|
86
89
|
* <code>maxlength</code> and <code>pattern</code> block form submission, and the message shows under
|
|
87
90
|
* the field once the value is committed or the form is submitted. Inside a <code><form></code>
|
|
88
|
-
* its <code>value</code> is submitted under its <code>name</code
|
|
91
|
+
* its <code>value</code> is submitted under its <code>name</code>, and Enter submits the form as in
|
|
92
|
+
* a native input (see <code>wc-input</code>).</p>
|
|
89
93
|
*
|
|
90
94
|
* @fires {CustomEvent<{value: string}>} input - Dispatched as the user types.
|
|
91
95
|
* @fires {CustomEvent<{value: string}>} change - Dispatched when the value is committed.
|
|
@@ -106,9 +110,9 @@ var _a;
|
|
|
106
110
|
* @tags input, form
|
|
107
111
|
*/
|
|
108
112
|
let PasswordField = class PasswordField extends BaseField {
|
|
113
|
+
// ── Lifecycle ────────────────────────────────────────────────────────────
|
|
109
114
|
constructor() {
|
|
110
|
-
|
|
111
|
-
super(...arguments);
|
|
115
|
+
super();
|
|
112
116
|
// ── Properties ───────────────────────────────────────────────────────────
|
|
113
117
|
this.value = '';
|
|
114
118
|
/** Tells password managers whether this is an existing password or a new one. */
|
|
@@ -120,6 +124,8 @@ let PasswordField = class PasswordField extends BaseField {
|
|
|
120
124
|
// ── Private fields ───────────────────────────────────────────────────────
|
|
121
125
|
/** Peacock's strings for the show/hide toggle. */
|
|
122
126
|
this.i18n = new I18nController(this);
|
|
127
|
+
// Enter in the input (not on the show/hide toggle) submits the form, as in a native one.
|
|
128
|
+
setupImplicitSubmission(this, () => this.inputElement);
|
|
123
129
|
}
|
|
124
130
|
// ── Public methods ───────────────────────────────────────────────────────
|
|
125
131
|
focus() {
|
|
@@ -201,6 +207,7 @@ let PasswordField = class PasswordField extends BaseField {
|
|
|
201
207
|
}
|
|
202
208
|
};
|
|
203
209
|
_a = ALWAYS_SENSITIVE;
|
|
210
|
+
// ── Static ───────────────────────────────────────────────────────────────
|
|
204
211
|
PasswordField.styles = [css_248z];
|
|
205
212
|
/** A password never reaches a model (ADR-030002). */
|
|
206
213
|
PasswordField[_a] = true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"password-field.js","sources":["../../src/password-field/password-field.ts"],"sourcesContent":["import { html, nothing } from 'lit';\nimport { property, query, state } from 'lit/decorators.js';\n\nimport { ALWAYS_SENSITIVE } from '@/__internal/ai/ai-controller.js';\nimport { spread } from '@/__internal/directive/spread.js';\nimport { I18nController } from '@/__internal/i18n/i18n-controller.js';\nimport IndividualComponent from '@/IndividualComponent.js';\n\nimport BaseField from '../input/BaseField.js';\nimport { type ControlValidity, nativeValidity } from '../input/BaseInput.js';\nimport styles from './password-field.scss';\n\n/**\n * @label Password Field\n * @tag wc-password-field\n * @rawTag password-field\n *\n * @summary A text field for a password, with a button that shows or hides what was typed.\n * @overview\n * <p>Password field hides what is typed until the person presses the show button; pressing it\n * again hides the text. Set <code>autocomplete=\"new-password\"</code> on sign-up and\n * change-password forms so password managers offer to generate one; the default,\n * <code>current-password</code>, suits sign-in forms.</p>\n * <p>It validates like a native password input: <code>required</code>, <code>minlength</code>,\n * <code>maxlength</code> and <code>pattern</code> block form submission, and the message shows under\n * the field once the value is committed or the form is submitted. Inside a <code><form></code>\n * its <code>value</code> is submitted under its <code>name</code>.</p>\n *\n * @fires {CustomEvent<{value: string}>} input - Dispatched as the user types.\n * @fires {CustomEvent<{value: string}>} change - Dispatched when the value is committed.\n *\n * @example\n * ```html\n * <wc-password-field label=\"Password\" required></wc-password-field>\n * ```\n * @example\n * ```html\n * <wc-password-field\n * label=\"New password\"\n * autocomplete=\"new-password\"\n * minlength=\"12\"\n * helper-text=\"At least 12 characters\"\n * ></wc-password-field>\n * ```\n * @tags input, form\n */\n@IndividualComponent\nexport class PasswordField extends BaseField {\n // ── Static ───────────────────────────────────────────────────────────────\n\n static styles = [styles];\n\n /** A password never reaches a model (ADR-030002). */\n static readonly [ALWAYS_SENSITIVE] = true;\n\n // ── Properties ───────────────────────────────────────────────────────────\n\n @property({ type: String })\n value = '';\n\n /** Tells password managers whether this is an existing password or a new one. */\n @property({ type: String })\n autocomplete: 'current-password' | 'new-password' = 'current-password';\n\n /** Fewest characters allowed. */\n @property({ type: Number, attribute: 'minlength' })\n minLength?: number;\n\n /** Most characters allowed; the input stops taking more. */\n @property({ type: Number, attribute: 'maxlength' })\n maxLength?: number;\n\n /** Regular expression the whole value must match, as on `<input pattern>`. */\n @property({ type: String })\n pattern = '';\n\n // ── State ────────────────────────────────────────────────────────────────\n\n @state()\n private passwordVisible = false;\n\n // ── Queries ──────────────────────────────────────────────────────────────\n\n @query('.input-element')\n private inputElement?: HTMLInputElement;\n\n // ── Private fields ───────────────────────────────────────────────────────\n\n /** Peacock's strings for the show/hide toggle. */\n private readonly i18n = new I18nController(this);\n\n // ── Public methods ───────────────────────────────────────────────────────\n\n override focus() {\n this.inputElement?.focus();\n }\n\n override blur() {\n this.inputElement?.blur();\n }\n\n // ── Protected methods ────────────────────────────────────────────────────\n\n protected override computeValidity(): ControlValidity {\n return this.inputElement\n ? nativeValidity(this.inputElement)\n : super.computeValidity();\n }\n\n protected override validityAnchor() {\n // `@query` gives null before the first render.\n return this.inputElement ?? undefined;\n }\n\n // ── Private methods ──────────────────────────────────────────────────────\n\n private handleInput(event: Event) {\n // Replace the native event, which escapes the shadow root, with the field's own.\n event.stopPropagation();\n this.value = (event.target as HTMLInputElement).value;\n this.emitValue('input');\n }\n\n private handleChange(event: Event) {\n event.stopPropagation();\n this.emitValue('change');\n }\n\n private togglePasswordVisible() {\n this.passwordVisible = !this.passwordVisible;\n }\n\n // ── Render helpers ───────────────────────────────────────────────────────\n\n private renderToggle() {\n const label = this.passwordVisible\n ? this.i18n.t('hidePassword')\n : this.i18n.t('showPassword');\n return html`\n <wc-icon-button\n class=\"password-toggle\"\n shape=\"round\"\n variant=\"text\"\n size=\"sm\"\n slot=\"field-end\"\n aria-label=${label}\n aria-pressed=${String(this.passwordVisible)}\n tooltip=${label}\n ?disabled=${this.disabled}\n @click=${this.togglePasswordVisible}\n >\n <wc-icon\n name=${this.passwordVisible ? 'visibility_off' : 'visibility'}\n ></wc-icon>\n </wc-icon-button>\n `;\n }\n\n // ── Render ───────────────────────────────────────────────────────────────\n\n render() {\n return this.renderField(\n html`<input\n class=\"input input-element\"\n type=${this.passwordVisible ? 'text' : 'password'}\n placeholder=${this.placeholder}\n autocomplete=${this.autocomplete}\n spellcheck=\"false\"\n autocapitalize=\"off\"\n minlength=${this.minLength ?? nothing}\n maxlength=${this.maxLength ?? nothing}\n pattern=${this.pattern || nothing}\n .value=${this.value}\n ?readonly=${this.readonly}\n ?required=${this.required}\n ?disabled=${this.disabled}\n @input=${this.handleInput}\n @change=${this.handleChange}\n @focus=${this.handleFieldFocus}\n @blur=${this.handleFieldFocus}\n ${spread(this.fieldAria())}\n />`,\n { populated: !!this.value, end: this.renderToggle() },\n );\n }\n}\n"],"names":["html","nothing","styles","property","state","query"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,CAAkB,GAAG,IAAH;AAKlC,UAAA,CAAA;AADC,IAAAC,CAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE;AACf,CAAA,EAAA,aAAA,CAAA,SAAA,EAAA,OAAA,EAAA,MAAA,CAAA;AAIX,UAAA,CAAA;AADC,IAAAA,CAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE;AAC6C,CAAA,EAAA,aAAA,CAAA,SAAA,EAAA,cAAA,EAAA,MAAA,CAAA;AAIvE,UAAA,CAAA;IADCA,CAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE;AAC/B,CAAA,EAAA,aAAA,CAAA,SAAA,EAAA,WAAA,EAAA,MAAA,CAAA;AAInB,UAAA,CAAA;IADCA,CAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE;AAC/B,CAAA,EAAA,aAAA,CAAA,SAAA,EAAA,WAAA,EAAA,MAAA,CAAA;AAInB,UAAA,CAAA;AADC,IAAAA,CAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE;AACb,CAAA,EAAA,aAAA,CAAA,SAAA,EAAA,SAAA,EAAA,MAAA,CAAA;AAKL,UAAA,CAAA;AADP,IAAAC,CAAK;AAC0B,CAAA,EAAA,aAAA,CAAA,SAAA,EAAA,iBAAA,EAAA,MAAA,CAAA;AAKxB,UAAA,CAAA;IADPC,CAAK,CAAC,gBAAgB;AACiB,CAAA,EAAA,aAAA,CAAA,SAAA,EAAA,cAAA,EAAA,MAAA,CAAA;AArC7B,aAAa,GAAA,UAAA,CAAA;IADzB;AACY,CAAA,EAAA,aAAa,CA0IzB;;;;"}
|
|
1
|
+
{"version":3,"file":"password-field.js","sources":["../../src/password-field/password-field.ts"],"sourcesContent":["import { html, nothing } from 'lit';\nimport { property, query, state } from 'lit/decorators.js';\n\nimport { ALWAYS_SENSITIVE } from '@/__internal/ai/ai-controller.js';\nimport { spread } from '@/__internal/directive/spread.js';\nimport { I18nController } from '@/__internal/i18n/i18n-controller.js';\nimport { setupImplicitSubmission } from '@/__internal/implicit-submission.js';\nimport IndividualComponent from '@/IndividualComponent.js';\n\nimport BaseField from '../input/BaseField.js';\nimport { type ControlValidity, nativeValidity } from '../input/BaseInput.js';\nimport styles from './password-field.scss';\n\n/**\n * @label Password Field\n * @tag wc-password-field\n * @rawTag password-field\n *\n * @summary A text field for a password, with a button that shows or hides what was typed.\n * @overview\n * <p>Password field hides what is typed until the person presses the show button; pressing it\n * again hides the text. Set <code>autocomplete=\"new-password\"</code> on sign-up and\n * change-password forms so password managers offer to generate one; the default,\n * <code>current-password</code>, suits sign-in forms.</p>\n * <p>It validates like a native password input: <code>required</code>, <code>minlength</code>,\n * <code>maxlength</code> and <code>pattern</code> block form submission, and the message shows under\n * the field once the value is committed or the form is submitted. Inside a <code><form></code>\n * its <code>value</code> is submitted under its <code>name</code>, and Enter submits the form as in\n * a native input (see <code>wc-input</code>).</p>\n *\n * @fires {CustomEvent<{value: string}>} input - Dispatched as the user types.\n * @fires {CustomEvent<{value: string}>} change - Dispatched when the value is committed.\n *\n * @example\n * ```html\n * <wc-password-field label=\"Password\" required></wc-password-field>\n * ```\n * @example\n * ```html\n * <wc-password-field\n * label=\"New password\"\n * autocomplete=\"new-password\"\n * minlength=\"12\"\n * helper-text=\"At least 12 characters\"\n * ></wc-password-field>\n * ```\n * @tags input, form\n */\n@IndividualComponent\nexport class PasswordField extends BaseField {\n // ── Static ───────────────────────────────────────────────────────────────\n\n static styles = [styles];\n\n /** A password never reaches a model (ADR-030002). */\n static readonly [ALWAYS_SENSITIVE] = true;\n\n // ── Properties ───────────────────────────────────────────────────────────\n\n @property({ type: String })\n value = '';\n\n /** Tells password managers whether this is an existing password or a new one. */\n @property({ type: String })\n autocomplete: 'current-password' | 'new-password' = 'current-password';\n\n /** Fewest characters allowed. */\n @property({ type: Number, attribute: 'minlength' })\n minLength?: number;\n\n /** Most characters allowed; the input stops taking more. */\n @property({ type: Number, attribute: 'maxlength' })\n maxLength?: number;\n\n /** Regular expression the whole value must match, as on `<input pattern>`. */\n @property({ type: String })\n pattern = '';\n\n // ── State ────────────────────────────────────────────────────────────────\n\n @state()\n private passwordVisible = false;\n\n // ── Queries ──────────────────────────────────────────────────────────────\n\n @query('.input-element')\n private inputElement?: HTMLInputElement;\n\n // ── Private fields ───────────────────────────────────────────────────────\n\n /** Peacock's strings for the show/hide toggle. */\n private readonly i18n = new I18nController(this);\n\n // ── Lifecycle ────────────────────────────────────────────────────────────\n\n constructor() {\n super();\n // Enter in the input (not on the show/hide toggle) submits the form, as in a native one.\n setupImplicitSubmission(this, () => this.inputElement);\n }\n\n // ── Public methods ───────────────────────────────────────────────────────\n\n override focus() {\n this.inputElement?.focus();\n }\n\n override blur() {\n this.inputElement?.blur();\n }\n\n // ── Protected methods ────────────────────────────────────────────────────\n\n protected override computeValidity(): ControlValidity {\n return this.inputElement\n ? nativeValidity(this.inputElement)\n : super.computeValidity();\n }\n\n protected override validityAnchor() {\n // `@query` gives null before the first render.\n return this.inputElement ?? undefined;\n }\n\n // ── Private methods ──────────────────────────────────────────────────────\n\n private handleInput(event: Event) {\n // Replace the native event, which escapes the shadow root, with the field's own.\n event.stopPropagation();\n this.value = (event.target as HTMLInputElement).value;\n this.emitValue('input');\n }\n\n private handleChange(event: Event) {\n event.stopPropagation();\n this.emitValue('change');\n }\n\n private togglePasswordVisible() {\n this.passwordVisible = !this.passwordVisible;\n }\n\n // ── Render helpers ───────────────────────────────────────────────────────\n\n private renderToggle() {\n const label = this.passwordVisible\n ? this.i18n.t('hidePassword')\n : this.i18n.t('showPassword');\n return html`\n <wc-icon-button\n class=\"password-toggle\"\n shape=\"round\"\n variant=\"text\"\n size=\"sm\"\n slot=\"field-end\"\n aria-label=${label}\n aria-pressed=${String(this.passwordVisible)}\n tooltip=${label}\n ?disabled=${this.disabled}\n @click=${this.togglePasswordVisible}\n >\n <wc-icon\n name=${this.passwordVisible ? 'visibility_off' : 'visibility'}\n ></wc-icon>\n </wc-icon-button>\n `;\n }\n\n // ── Render ───────────────────────────────────────────────────────────────\n\n render() {\n return this.renderField(\n html`<input\n class=\"input input-element\"\n type=${this.passwordVisible ? 'text' : 'password'}\n placeholder=${this.placeholder}\n autocomplete=${this.autocomplete}\n spellcheck=\"false\"\n autocapitalize=\"off\"\n minlength=${this.minLength ?? nothing}\n maxlength=${this.maxLength ?? nothing}\n pattern=${this.pattern || nothing}\n .value=${this.value}\n ?readonly=${this.readonly}\n ?required=${this.required}\n ?disabled=${this.disabled}\n @input=${this.handleInput}\n @change=${this.handleChange}\n @focus=${this.handleFieldFocus}\n @blur=${this.handleFieldFocus}\n ${spread(this.fieldAria())}\n />`,\n { populated: !!this.value, end: this.renderToggle() },\n );\n }\n}\n"],"names":["html","nothing","styles","property","state","query"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCG;AAEI,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,SAAS,CAAA;;AA8C1C,IAAA,WAAA,GAAA;AACE,QAAA,KAAK,EAAE;;QApCT,IAAA,CAAA,KAAK,GAAG,EAAE;;QAIV,IAAA,CAAA,YAAY,GAAwC,kBAAkB;;QAYtE,IAAA,CAAA,OAAO,GAAG,EAAE;;QAKJ,IAAA,CAAA,eAAe,GAAG,KAAK;;;AAUd,QAAA,IAAA,CAAA,IAAI,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC;;QAO9C,uBAAuB,CAAC,IAAI,EAAE,MAAM,IAAI,CAAC,YAAY,CAAC;IACxD;;IAIS,KAAK,GAAA;AACZ,QAAA,IAAI,CAAC,YAAY,EAAE,KAAK,EAAE;IAC5B;IAES,IAAI,GAAA;AACX,QAAA,IAAI,CAAC,YAAY,EAAE,IAAI,EAAE;IAC3B;;IAImB,eAAe,GAAA;QAChC,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WAAW,EAAE;AAC/B,CAAA,EAAA,aAAA,CAAA,SAAA,EAAA,WAAA,EAAA,MAAA,CAAA;AAInB,UAAA,CAAA;AADC,IAAAA,CAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE;AACb,CAAA,EAAA,aAAA,CAAA,SAAA,EAAA,SAAA,EAAA,MAAA,CAAA;AAKL,UAAA,CAAA;AADP,IAAAC,CAAK;AAC0B,CAAA,EAAA,aAAA,CAAA,SAAA,EAAA,iBAAA,EAAA,MAAA,CAAA;AAKxB,UAAA,CAAA;IADPC,CAAK,CAAC,gBAAgB;AACiB,CAAA,EAAA,aAAA,CAAA,SAAA,EAAA,cAAA,EAAA,MAAA,CAAA;AArC7B,aAAa,GAAA,UAAA,CAAA;IADzB;AACY,CAAA,EAAA,aAAa,CAkJzB;;;;"}
|
package/dist/phone-field.js
CHANGED
|
@@ -4,11 +4,14 @@ import { r } from './state-BCeDVCI9.js';
|
|
|
4
4
|
import { e } from './query-CHb9Ft_d.js';
|
|
5
5
|
import { s as spread } from './spread-B5cgadZl.js';
|
|
6
6
|
import { I as I18nController } from './i18n-controller-BTeChxE0.js';
|
|
7
|
-
import { B as BaseField } from './BaseField-
|
|
7
|
+
import { B as BaseField } from './BaseField-DOCmylob.js';
|
|
8
8
|
import './base-Cl6v8-BZ.js';
|
|
9
9
|
import './directive-ZPhl09Yt.js';
|
|
10
10
|
import './strings-DeiQWMd9.js';
|
|
11
11
|
import './locale-DEsJZCQG.js';
|
|
12
|
+
import './implicit-submission-ChLdbxaR.js';
|
|
13
|
+
import './dispatch-hooks-J_godlHh.js';
|
|
14
|
+
import './form-submission-h40coUI8.js';
|
|
12
15
|
import './BaseInput-Cv03GZLu.js';
|
|
13
16
|
import './element-internals-QME0yEz4.js';
|
|
14
17
|
import './form-associated-BHbg72PG.js';
|