@redvars/peacock 4.5.0 → 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 +13 -8
- 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/calendar-timeline/calendar-timeline.scss +15 -5
- 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
package/dist/tabs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tabs.js","sources":["../../src/tabs/tabs.ts"],"sourcesContent":["import { html, LitElement } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport styles from './tabs.scss';\nimport { Tab } from './tab.js';\nimport IndividualComponent from '@/IndividualComponent.js';\nimport { RovingFocusController } from '@/__internal/controllers/roving-focus-controller.js';\nimport { isLink } from '@/__internal/utils/is-link.js';\n\n/** Detail of the `change` event. */\nexport interface TabsChangeDetail {\n index: number;\n value?: string;\n}\n\n/**\n * @label Tabs\n * @tag wc-tabs\n * @rawTag tabs\n *\n * @summary The row of tabs, which the person moves between by clicking or with the arrow keys.\n * @overview\n * <p>Tabs holds the tab buttons and manages their layout. It follows the WAI-ARIA tabs pattern:\n * the host has <code>role=\"tablist\"</code> (give it an <code>aria-label</code>), only the selected\n * tab is a tab stop, and the Left and Right arrow keys (mirrored in right-to-left layouts), Home\n * and End move between tabs. Moving to a tab selects it, so its panel shows at once. Disabled\n * tabs are skipped.</p>\n * <p>With <code>managed</code>, the tabs do not change the selection themselves: they fire\n * <code>change</code> and the consumer sets <code>selected</code> on the chosen tab.</p>\n * <p>When every tab is a link (<code>href</code>), the tabs are navigation rather than a tablist:\n * the host gets no tablist role, so wrap it in a <code><nav></code>.</p>\n *\n * @fires {CustomEvent<{index: number, value: string | undefined}>} change - Dispatched when the user selects a tab, by click or with the arrow keys.\n *\n * @example\n * ```html\n * <wc-tabs aria-label=\"Sections\">\n * <wc-tab selected>Tab 1</wc-tab>\n * <wc-tab>Tab 2</wc-tab>\n * </wc-tabs>\n * ```\n * @tags navigation\n */\n@IndividualComponent\nexport class Tabs extends LitElement {\n // ── Static\n\n static styles = [styles];\n\n static Tab = Tab;\n\n // ── Properties\n\n /** The visual style of the tabs: `\"primary\"` (default), `\"secondary\"`, `\"contained\"` or `\"filled\"`. */\n @property({ reflect: true })\n variant: 'primary' | 'secondary' | 'contained' | 'filled' = 'primary';\n\n /** The consumer controls the selection: the tabs fire `change` but do not select a tab. */\n @property({ type: Boolean }) managed = false;\n\n // ── Private fields\n\n /** One tab stop, on the selected tab; the arrow keys move it and select the tab they reach. */\n private readonly roving = new RovingFocusController(this, {\n items: () => this.__getTabs(),\n orientation: () => 'horizontal',\n initialItem: items => items.find(tab => (tab as Tab).selected) ?? items[0],\n onMove: item => this.__selectFromUser(item as Tab),\n });\n\n private __mutationObserver?: MutationObserver;\n\n private __lastActiveTab?: Tab;\n\n /** Set while a click is handled, so a click on a link tab still selects it. */\n private __clicking = false;\n\n // ── Lifecycle\n\n connectedCallback() {\n super.connectedCallback();\n this.addEventListener('click', this.__handleTabClick);\n this.__syncRole();\n }\n\n firstUpdated() {\n this.__mutationObserver = new MutationObserver(() => {\n this.__syncIndicatorsFromActiveState();\n this.__syncRole();\n });\n\n this.__mutationObserver.observe(this, {\n subtree: true,\n childList: true,\n attributes: true,\n attributeFilter: ['selected', 'disabled', 'href'],\n });\n\n this.__lastActiveTab = this.__getActiveTab();\n this.__syncRole();\n }\n\n updated(changedProperties: Map<string, unknown>) {\n if (changedProperties.has('variant')) {\n this.__lastActiveTab = this.__getActiveTab();\n }\n }\n\n disconnectedCallback() {\n this.__mutationObserver?.disconnect();\n\n this.removeEventListener('click', this.__handleTabClick);\n super.disconnectedCallback();\n }\n\n // ── Private\n\n private __getTabs() {\n return Array.from(this.querySelectorAll('wc-tab')) as Tab[];\n }\n\n private __getActiveTab() {\n return this.__getTabs().find(tab => tab.selected && !tab.disabled);\n }\n\n /** A tablist, unless every tab is a link: then the tabs are navigation. */\n private __syncRole() {\n const tabs = this.__getTabs();\n const navigation = tabs.length > 0 && tabs.every(tab => isLink(tab));\n if (navigation) {\n if (this.getAttribute('role') === 'tablist') this.removeAttribute('role');\n } else if (!this.hasAttribute('role')) {\n this.setAttribute('role', 'tablist');\n }\n }\n\n private static __getTabIndicator(tab?: Tab) {\n if (!tab?.shadowRoot) return undefined;\n return tab.shadowRoot.querySelector('.indicator') as HTMLElement | null;\n }\n\n private static __getTabBackground(tab?: Tab) {\n if (!tab?.shadowRoot) return undefined;\n return tab.shadowRoot.querySelector('.background') as HTMLElement | null;\n }\n\n private __getAnimationElements(previousTab?: Tab, nextTab?: Tab) {\n if (this.variant === 'primary' || this.variant === 'secondary') {\n return {\n previous: Tabs.__getTabIndicator(previousTab),\n next: Tabs.__getTabIndicator(nextTab),\n };\n }\n\n if (this.variant === 'filled' || this.variant === 'contained') {\n return {\n previous: Tabs.__getTabBackground(previousTab),\n next: Tabs.__getTabBackground(nextTab),\n };\n }\n\n return {\n previous: undefined,\n next: undefined,\n };\n }\n\n private __animateIndicatorTransition(previousTab?: Tab, nextTab?: Tab) {\n if (!previousTab || !nextTab || previousTab === nextTab) return;\n\n const { previous: previousAnimationElement, next: nextAnimationElement } =\n this.__getAnimationElements(previousTab, nextTab);\n if (!previousAnimationElement || !nextAnimationElement) return;\n\n const previousRect = previousTab.getBoundingClientRect();\n const nextRect = nextTab.getBoundingClientRect();\n\n const incomingOffset = previousRect.left - nextRect.left;\n const outgoingOffset = nextRect.left - previousRect.left;\n const incomingScale = previousRect.width / nextRect.width;\n const outgoingScale = nextRect.width / previousRect.width;\n\n nextAnimationElement.style.transition = 'none';\n nextAnimationElement.style.opacity = '0';\n nextAnimationElement.style.transform = `translateX(${incomingOffset}px) scaleX(${incomingScale})`;\n\n previousAnimationElement.style.transition = 'none';\n previousAnimationElement.style.opacity = '1';\n previousAnimationElement.style.transform = 'translateX(0) scaleX(1)';\n\n requestAnimationFrame(() => {\n nextAnimationElement.style.transition = '';\n previousAnimationElement.style.transition = '';\n\n nextAnimationElement.style.opacity = '1';\n nextAnimationElement.style.transform = 'translateX(0) scaleX(1)';\n\n previousAnimationElement.style.opacity = '0';\n previousAnimationElement.style.transform = `translateX(${outgoingOffset}px) scaleX(${outgoingScale})`;\n });\n }\n\n private __syncIndicatorsFromActiveState() {\n const activeTab = this.__getActiveTab();\n if (\n this.__lastActiveTab &&\n activeTab &&\n this.__lastActiveTab !== activeTab\n ) {\n this.__animateIndicatorTransition(this.__lastActiveTab, activeTab);\n }\n\n this.__lastActiveTab = activeTab;\n // The tab stop follows the selection, also when it is set from outside.\n if (activeTab && this.roving.activeItem !== activeTab) {\n this.roving.setActive(activeTab, false);\n }\n }\n\n /** Selects `tab` (unless managed) and tells the consumer, after a click or an arrow key. */\n private __selectFromUser(tab: Tab) {\n if (tab.disabled) return;\n // Arrowing onto a link only moves focus; following it is the person's choice.\n if (isLink(tab) && !this.__clicking) return;\n\n const tabs = this.__getTabs();\n if (!this.managed) {\n const previousActiveTab = this.__getActiveTab();\n for (const other of tabs) other.selected = other === tab;\n this.__animateIndicatorTransition(previousActiveTab, tab);\n this.__lastActiveTab = tab;\n }\n\n const detail: TabsChangeDetail = {\n index: tabs.indexOf(tab),\n value: tab.value,\n };\n this.dispatchEvent(\n new CustomEvent('change', { bubbles: true, composed: true, detail }),\n );\n }\n\n private __handleTabClick = (event: Event) => {\n const clickedTab = event\n .composedPath()\n .find(node => node instanceof Element && node.localName === 'wc-tab') as\n | Tab\n | undefined;\n if (!clickedTab || !this.__getTabs().includes(clickedTab)) return;\n\n this.__clicking = true;\n try {\n this.__selectFromUser(clickedTab);\n } finally {\n this.__clicking = false;\n }\n };\n\n private __handleSlotChange = () => {\n this.roving.sync();\n this.__syncRole();\n };\n\n // ── Render\n\n render() {\n return html`\n <div\n class=\"tabs\"\n @keydown=${this.roving.handleKeyDown}\n @focusin=${this.roving.handleFocusIn}\n >\n <slot @slotchange=${this.__handleSlotChange}></slot>\n </div>\n `;\n }\n}\n"],"names":["LitElement","html","styles","property"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BG;AAEI,IAAM,IAAI,GAAA,MAAA,GAAV,M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import { property } from 'lit/decorators.js';\nimport styles from './tabs.scss';\nimport { Tab } from './tab.js';\nimport IndividualComponent from '@/IndividualComponent.js';\nimport { RovingFocusController } from '@/__internal/controllers/roving-focus-controller.js';\nimport { isLink } from '@/__internal/utils/is-link.js';\n\n/** Detail of the `change` event. */\nexport interface TabsChangeDetail {\n index: number;\n value?: string;\n}\n\n/**\n * @label Tabs\n * @tag wc-tabs\n * @rawTag tabs\n *\n * @summary The row of tabs, which the person moves between by clicking or with the arrow keys.\n * @overview\n * <p>Tabs holds the tab buttons and manages their layout. It follows the WAI-ARIA tabs pattern:\n * the host has <code>role=\"tablist\"</code> (give it an <code>aria-label</code>), only the selected\n * tab is a tab stop, and the Left and Right arrow keys (mirrored in right-to-left layouts), Home\n * and End move between tabs. Moving to a tab selects it, so its panel shows at once. Disabled\n * tabs are skipped.</p>\n * <p>With <code>managed</code>, the tabs do not change the selection themselves: they fire\n * <code>change</code> and the consumer sets <code>selected</code> on the chosen tab.</p>\n * <p>When every tab is a link (<code>href</code>), the tabs are navigation rather than a tablist:\n * the host gets no tablist role, so wrap it in a <code><nav></code>.</p>\n *\n * @fires {CustomEvent<{index: number, value: string | undefined}>} change - Dispatched when the user selects a tab, by click or with the arrow keys.\n *\n * @example\n * ```html\n * <wc-tabs aria-label=\"Sections\">\n * <wc-tab selected>Tab 1</wc-tab>\n * <wc-tab>Tab 2</wc-tab>\n * </wc-tabs>\n * ```\n * @tags navigation\n */\n@IndividualComponent\nexport class Tabs extends LitElement {\n // ── Static\n\n static styles = [styles];\n\n static Tab = Tab;\n\n // ── Properties\n\n /** The visual style of the tabs: `\"primary\"` (default), `\"secondary\"`, `\"contained\"` or `\"filled\"`. */\n @property({ reflect: true })\n variant: 'primary' | 'secondary' | 'contained' | 'filled' = 'primary';\n\n /** The consumer controls the selection: the tabs fire `change` but do not select a tab. */\n @property({ type: Boolean }) managed = false;\n\n // ── Private fields\n\n /** One tab stop, on the selected tab; the arrow keys move it and select the tab they reach. */\n private readonly roving = new RovingFocusController(this, {\n items: () => this.__getTabs(),\n orientation: () => 'horizontal',\n initialItem: items => items.find(tab => (tab as Tab).selected) ?? items[0],\n onMove: item => this.__selectFromUser(item as Tab),\n });\n\n private __mutationObserver?: MutationObserver;\n\n private __lastActiveTab?: Tab;\n\n /** Set while a click is handled, so a click on a link tab still selects it. */\n private __clicking = false;\n\n // ── Lifecycle\n\n connectedCallback() {\n super.connectedCallback();\n this.addEventListener('click', this.__handleTabClick);\n this.__syncRole();\n }\n\n firstUpdated() {\n this.__mutationObserver = new MutationObserver(() => {\n this.__syncIndicatorsFromActiveState();\n this.__syncRole();\n });\n\n this.__mutationObserver.observe(this, {\n subtree: true,\n childList: true,\n attributes: true,\n attributeFilter: ['selected', 'disabled', 'href'],\n });\n\n this.__lastActiveTab = this.__getActiveTab();\n this.__syncRole();\n }\n\n updated(changedProperties: Map<string, unknown>) {\n if (changedProperties.has('variant')) {\n this.__lastActiveTab = this.__getActiveTab();\n }\n }\n\n disconnectedCallback() {\n this.__mutationObserver?.disconnect();\n\n this.removeEventListener('click', this.__handleTabClick);\n super.disconnectedCallback();\n }\n\n // ── Private\n\n private __getTabs() {\n return Array.from(this.querySelectorAll('wc-tab')) as Tab[];\n }\n\n private __getActiveTab() {\n return this.__getTabs().find(tab => tab.selected && !tab.disabled);\n }\n\n /** A tablist, unless every tab is a link: then the tabs are navigation. */\n private __syncRole() {\n const tabs = this.__getTabs();\n const navigation = tabs.length > 0 && tabs.every(tab => isLink(tab));\n if (navigation) {\n if (this.getAttribute('role') === 'tablist') this.removeAttribute('role');\n } else if (!this.hasAttribute('role')) {\n this.setAttribute('role', 'tablist');\n }\n }\n\n private static __getTabIndicator(tab?: Tab) {\n if (!tab?.shadowRoot) return undefined;\n return tab.shadowRoot.querySelector('.indicator') as HTMLElement | null;\n }\n\n private static __getTabBackground(tab?: Tab) {\n if (!tab?.shadowRoot) return undefined;\n return tab.shadowRoot.querySelector('.background') as HTMLElement | null;\n }\n\n private __getAnimationElements(previousTab?: Tab, nextTab?: Tab) {\n if (this.variant === 'primary' || this.variant === 'secondary') {\n return {\n previous: Tabs.__getTabIndicator(previousTab),\n next: Tabs.__getTabIndicator(nextTab),\n };\n }\n\n if (this.variant === 'filled' || this.variant === 'contained') {\n return {\n previous: Tabs.__getTabBackground(previousTab),\n next: Tabs.__getTabBackground(nextTab),\n };\n }\n\n return {\n previous: undefined,\n next: undefined,\n };\n }\n\n private __animateIndicatorTransition(previousTab?: Tab, nextTab?: Tab) {\n if (!previousTab || !nextTab || previousTab === nextTab) return;\n\n const { previous: previousAnimationElement, next: nextAnimationElement } =\n this.__getAnimationElements(previousTab, nextTab);\n if (!previousAnimationElement || !nextAnimationElement) return;\n\n const previousRect = previousTab.getBoundingClientRect();\n const nextRect = nextTab.getBoundingClientRect();\n\n const incomingOffset = previousRect.left - nextRect.left;\n const outgoingOffset = nextRect.left - previousRect.left;\n const incomingScale = previousRect.width / nextRect.width;\n const outgoingScale = nextRect.width / previousRect.width;\n\n nextAnimationElement.style.transition = 'none';\n nextAnimationElement.style.opacity = '0';\n nextAnimationElement.style.transform = `translateX(${incomingOffset}px) scaleX(${incomingScale})`;\n\n previousAnimationElement.style.transition = 'none';\n previousAnimationElement.style.opacity = '1';\n previousAnimationElement.style.transform = 'translateX(0) scaleX(1)';\n\n requestAnimationFrame(() => {\n nextAnimationElement.style.transition = '';\n previousAnimationElement.style.transition = '';\n\n nextAnimationElement.style.opacity = '1';\n nextAnimationElement.style.transform = 'translateX(0) scaleX(1)';\n\n previousAnimationElement.style.opacity = '0';\n previousAnimationElement.style.transform = `translateX(${outgoingOffset}px) scaleX(${outgoingScale})`;\n });\n }\n\n private __syncIndicatorsFromActiveState() {\n const activeTab = this.__getActiveTab();\n if (\n this.__lastActiveTab &&\n activeTab &&\n this.__lastActiveTab !== activeTab\n ) {\n this.__animateIndicatorTransition(this.__lastActiveTab, activeTab);\n }\n\n this.__lastActiveTab = activeTab;\n // The tab stop follows the selection, also when it is set from outside.\n if (activeTab && this.roving.activeItem !== activeTab) {\n this.roving.setActive(activeTab, false);\n }\n }\n\n /** Selects `tab` (unless managed) and tells the consumer, after a click or an arrow key. */\n private __selectFromUser(tab: Tab) {\n if (tab.disabled) return;\n // Arrowing onto a link only moves focus; following it is the person's choice.\n if (isLink(tab) && !this.__clicking) return;\n\n const tabs = this.__getTabs();\n if (!this.managed) {\n const previousActiveTab = this.__getActiveTab();\n for (const other of tabs) other.selected = other === tab;\n this.__animateIndicatorTransition(previousActiveTab, tab);\n this.__lastActiveTab = tab;\n }\n\n const detail: TabsChangeDetail = {\n index: tabs.indexOf(tab),\n value: tab.value,\n };\n this.dispatchEvent(\n new CustomEvent('change', { bubbles: true, composed: true, detail }),\n );\n }\n\n private __handleTabClick = (event: Event) => {\n const clickedTab = event\n .composedPath()\n .find(node => node instanceof Element && node.localName === 'wc-tab') as\n | Tab\n | undefined;\n if (!clickedTab || !this.__getTabs().includes(clickedTab)) return;\n\n this.__clicking = true;\n try {\n this.__selectFromUser(clickedTab);\n } finally {\n this.__clicking = false;\n }\n };\n\n private __handleSlotChange = () => {\n this.roving.sync();\n this.__syncRole();\n };\n\n // ── Render\n\n render() {\n return html`\n <div\n class=\"tabs\"\n @keydown=${this.roving.handleKeyDown}\n @focusin=${this.roving.handleFocusIn}\n >\n <slot @slotchange=${this.__handleSlotChange}></slot>\n </div>\n `;\n }\n}\n"],"names":["LitElement","html","styles","property"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BG;AAEI,IAAM,IAAI,GAAA,MAAA,GAAV,MAAM,IAAK,SAAQA,GAAU,CAAA;AAA7B,IAAA,WAAA,GAAA;;;;;QAWL,IAAA,CAAA,OAAO,GAAqD,SAAS;;QAGxC,IAAA,CAAA,OAAO,GAAG,KAAK;;;AAK3B,QAAA,IA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,GAAG,CAAC;AACzD,YAAA,IAAI,CAAC,eAAe,GAAG,GAAG;QAC5B;AAEA,QAAA,MAAM,MAAM,GAAqB;AAC/B,YAAA,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC;YACxB,KAAK,EAAE,GAAG,CAAC,KAAK;SACjB;QACD,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CACrE;IACH;;IAyBA,MAAM,GAAA;AACJ,QAAA,OAAOC,CAAI,CAAA;;;mBAGI,IAAI,CAAC,MAAM,CAAC,aAAa;mBACzB,IAAI,CAAC,MAAM,CAAC,aAAa;;AAEhB,0BAAA,EAAA,IAAI,CAAC,kBAAkB,CAAA;;KAE9C;IACH;;AApOO,IAAA,CAAA,MAAM,GAAG,CAACC,QAAM,CAAC;AAEjB,IAAA,CAAA,GAAG,GAAG,GAAH;AAMV,UAAA,CAAA;AADC,IAAAC,CAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE;AAC2C,CAAA,EAAA,IAAA,CAAA,SAAA,EAAA,SAAA,EAAA,MAAA,CAAA;AAGzC,UAAA,CAAA;AAA5B,IAAAA,CAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE;AAAkB,CAAA,EAAA,IAAA,CAAA,SAAA,EAAA,SAAA,EAAA,MAAA,CAAA;AAdlC,IAAI,GAAA,MAAA,GAAA,UAAA,CAAA;IADhB;AACY,CAAA,EAAA,IAAI,CAwOhB;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Resolves after `ms` milliseconds (a macrotask, also for `0`). */
|
|
2
|
+
export declare function wait(ms?: number): Promise<unknown>;
|
|
3
|
+
/**
|
|
4
|
+
* Clicks `host` twice, a macrotask apart, and returns how many times that activated the inner
|
|
5
|
+
* control found by `selector` in its shadow root. With `throttle-delay` set, the second click
|
|
6
|
+
* falls inside the delay and must not activate the control again. `settleMs` waits that long
|
|
7
|
+
* after the second click before counting, so a click the throttle wrongly deferred shows up.
|
|
8
|
+
*/
|
|
9
|
+
export declare function countActivations(host: HTMLElement, selector: string, settleMs?: number): Promise<number>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/textarea.js
CHANGED
|
@@ -5,13 +5,16 @@ import { s as spread } from './spread-B5cgadZl.js';
|
|
|
5
5
|
import { o } from './style-map-CHOg6N_R.js';
|
|
6
6
|
import { A as AiController } from './ai-controller-DR_Tg0sN.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 './locale-DEsJZCQG.js';
|
|
13
13
|
import './strings-DeiQWMd9.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';
|
|
@@ -389,6 +392,10 @@ let Textarea = class Textarea extends BaseField {
|
|
|
389
392
|
get suggestionBadgeIconOnly() {
|
|
390
393
|
return true;
|
|
391
394
|
}
|
|
395
|
+
/** Multi-line: like a native textarea, it does not count for implicit submission. */
|
|
396
|
+
get singleLineTextField() {
|
|
397
|
+
return false;
|
|
398
|
+
}
|
|
392
399
|
// ── Public methods ───────────────────────────────────────────────────────
|
|
393
400
|
focus() {
|
|
394
401
|
this.inputElement?.focus();
|
package/dist/textarea.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textarea.js","sources":["../../src/__internal/ai/ghost-text-controller.ts","../../src/textarea/textarea.ts"],"sourcesContent":["import {\n html,\n nothing,\n type ReactiveController,\n type ReactiveControllerHost,\n type TemplateResult,\n} from 'lit';\nimport { styleMap } from 'lit/directives/style-map.js';\n\nimport type { I18nController } from '../i18n/i18n-controller.js';\nimport { AiController } from './ai-controller.js';\n\ninterface GhostHost extends ReactiveControllerHost, HTMLElement {\n readonly renderRoot: HTMLElement | DocumentFragment;\n sensitive?: boolean;\n noAi?: boolean;\n name?: string;\n label?: string;\n disabled: boolean;\n readonly: boolean;\n}\n\ninterface GhostOptions {\n /** The native control the ghost text belongs to. */\n control: () => HTMLTextAreaElement | null | undefined;\n /** Whether the host asked for ghost text (`ai-completion`). */\n enabled: () => boolean;\n /** Inserts accepted text at the caret and fires the host's `input`. */\n insert: (text: string) => void;\n i18n: I18nController;\n /** Milliseconds without typing before a suggestion is asked for. */\n delay?: number;\n}\n\n/** Computed styles copied onto the mirror so its text wraps exactly like the control's. */\nconst MIRRORED = [\n 'boxSizing',\n 'borderTopWidth',\n 'borderRightWidth',\n 'borderBottomWidth',\n 'borderLeftWidth',\n 'paddingTop',\n 'paddingRight',\n 'paddingBottom',\n 'paddingLeft',\n 'fontFamily',\n 'fontSize',\n 'fontWeight',\n 'fontStyle',\n 'lineHeight',\n 'letterSpacing',\n 'wordSpacing',\n 'textIndent',\n 'textTransform',\n 'tabSize',\n 'direction',\n 'textAlign',\n] as const;\n\nconst CONTEXT_BEFORE = 4000;\nconst CONTEXT_AFTER = 1000;\n\nlet ghostCount = 0;\n\n/**\n * Ghost text for a native textarea (ADR-030002): after a pause in typing at the end of a line, the\n * provider's `complete` suggests how to go on, shown in grey after the caret. Tab takes it, Mod+→\n * takes the next word, Escape or any other key dismisses it. Nothing is inserted until the person\n * takes it.\n *\n * The suggestion is drawn in a mirror laid over the control, with the control's text metrics, so\n * it wraps like real text. Screen readers get it through the control's description.\n *\n * Usage: wrap the control in an element with `position: relative`, render `render()` beside it,\n * call `onInput()` from the control's `input`, `onKeyDown()` from its `keydown`, and `clear()` on\n * blur, scroll and selection changes; spread `describedBy()` into its `aria-describedby`.\n */\nexport class GhostTextController implements ReactiveController {\n private readonly host: GhostHost;\n\n private readonly options: GhostOptions;\n\n private readonly ai: AiController;\n\n private readonly hintId = `wc-ghost-text-${(ghostCount += 1)}`;\n\n private timer?: number;\n\n private ghost: { text: string; position: number } | null = null;\n\n private mirrorStyle: Record<string, string> = {};\n\n constructor(host: GhostHost, options: GhostOptions) {\n this.host = host;\n this.options = options;\n this.ai = new AiController(host, 'complete');\n host.addController(this);\n }\n\n hostUpdated() {\n // Keep the mirror's scroll in step with the control's.\n const mirror =\n this.host.renderRoot.querySelector<HTMLElement>('.ghost-mirror');\n const control = this.options.control();\n if (mirror && control) mirror.scrollTop = control.scrollTop;\n }\n\n hostDisconnected() {\n this.clear();\n }\n\n /** Whether ghost text can be offered now. */\n get available(): boolean {\n return (\n this.options.enabled() &&\n this.ai.available &&\n !this.host.disabled &&\n !this.host.readonly\n );\n }\n\n /** The suggestion shown, or `''`. */\n get text(): string {\n return this.ghost?.text ?? '';\n }\n\n /** The id to add to the control's `aria-describedby` while a suggestion shows. */\n describedBy(): string | undefined {\n return this.ghost ? this.hintId : undefined;\n }\n\n /** The person typed: drop the suggestion and ask again after a pause. */\n onInput() {\n this.clear();\n if (!this.available) return;\n this.timer = window.setTimeout(\n () => this.request(),\n this.options.delay ?? 600,\n );\n }\n\n /** Tab takes the suggestion, Mod+→ a word, Escape dismisses; other keys dismiss it too. */\n onKeyDown(event: KeyboardEvent) {\n if (!this.ghost) return;\n const word = event.key === 'ArrowRight' && (event.ctrlKey || event.metaKey);\n const all =\n event.key === 'Tab' &&\n !event.shiftKey &&\n !event.altKey &&\n !event.ctrlKey &&\n !event.metaKey;\n if (all || word) {\n event.preventDefault();\n this.accept(all ? 'all' : 'word');\n return;\n }\n if (event.key === 'Escape') {\n // The suggestion takes this Escape, not a dialog around the field.\n event.preventDefault();\n event.stopPropagation();\n }\n if (!['Shift', 'Control', 'Alt', 'Meta'].includes(event.key)) this.clear();\n }\n\n /** Drops the suggestion and any request for it. */\n clear() {\n window.clearTimeout(this.timer);\n this.timer = undefined;\n this.ai.abort();\n if (!this.ghost) return;\n this.ghost = null;\n this.host.requestUpdate();\n }\n\n /** The mirror with the suggestion, and the screen-reader hint. */\n render(): TemplateResult | typeof nothing {\n const { ghost } = this;\n const control = this.options.control();\n if (!ghost || !control) return nothing;\n const before = control.value.slice(0, ghost.position);\n // No whitespace inside the mirror: it keeps white space, so any would show as text.\n // prettier-ignore\n return html`<div class=\"ghost-mirror\" aria-hidden=\"true\" style=${styleMap(this.mirrorStyle)}><span class=\"ghost-before\">${before}</span><span class=\"ghost-text\">${ghost.text}</span></div>\n <span id=${this.hintId} hidden\n >${this.options.i18n.t('aiGhostHint')(ghost.text)}</span\n >`;\n }\n\n private async request() {\n const control = this.options.control();\n const { provider } = this.ai;\n if (!control || !provider?.complete || !this.available) return;\n const { value, selectionStart, selectionEnd } = control;\n if (selectionStart !== selectionEnd) return;\n const position = selectionStart ?? value.length;\n const rest = value.slice(position);\n // Only at the end of a line, where text after the caret can't be in the way.\n if (rest.split('\\n')[0].trim()) return;\n if (!value.slice(0, position).trim()) return;\n const text = await this.ai.run(signal =>\n provider.complete!({\n signal,\n context: this.ai.context(),\n before: value.slice(0, position).slice(-CONTEXT_BEFORE),\n after: rest.slice(0, CONTEXT_AFTER),\n }),\n );\n if (!text || control.value !== value) return;\n if (control.selectionStart !== position) return;\n this.mirrorStyle = this.measure(control);\n this.ghost = { text, position };\n this.host.requestUpdate();\n }\n\n private accept(part: 'all' | 'word') {\n const { ghost } = this;\n if (!ghost) return;\n const taken =\n part === 'all' ? ghost.text : (/^\\s*\\S+/.exec(ghost.text)?.[0] ?? '');\n const rest = ghost.text.slice(taken.length);\n this.ghost = null;\n if (taken) this.options.insert(taken);\n this.ghost = rest\n ? { text: rest, position: ghost.position + taken.length }\n : null;\n this.host.requestUpdate();\n }\n\n private measure(control: HTMLTextAreaElement): Record<string, string> {\n const computed = getComputedStyle(control);\n const style: Record<string, string> = {};\n for (const property of MIRRORED) {\n style[property.replace(/[A-Z]/g, c => `-${c.toLowerCase()}`)] =\n computed[property];\n }\n style['border-color'] = 'transparent';\n style['border-style'] = 'solid';\n return style;\n }\n}\n","import { html, nothing, type PropertyValues } from 'lit';\nimport { property, query } from 'lit/decorators.js';\n\nimport { spread } from '@/__internal/directive/spread.js';\nimport { GhostTextController } from '@/__internal/ai/ghost-text-controller.js';\nimport { I18nController } from '@/__internal/i18n/i18n-controller.js';\n\nimport IndividualComponent from '@/IndividualComponent.js';\nimport BaseField from '../input/BaseField.js';\nimport { type ControlValidity, nativeValidity } from '../input/BaseInput.js';\nimport styles from './textarea.scss';\n\n/**\n * @label Textarea\n * @tag wc-textarea\n * @rawTag textarea\n * @summary A multi-line text field that can grow with its content.\n * @overview\n * <p>Textarea 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 textarea: <code>required</code>, <code>minlength</code> and\n * <code>maxlength</code> block form submission, and the message shows under the field once the\n * value is committed or the form is submitted. With <code>maxlength</code> a character counter\n * shows under the field.</p>\n * <p><code>rows</code> sets the starting height. With <code>auto-grow</code> the height follows the\n * content, up to <code>max-rows</code> when it is set; <code>resize</code> controls whether the\n * person can drag the corner to resize it.</p>\n * <p>With <code>ai-completion</code> and a provider that offers completions (ADR-030002), a pause\n * in typing at the end of a line shows ghost text: how the assistant would go on, in grey after the\n * caret. Tab takes it, Ctrl+→ (⌘→) takes a word, Escape or typing dismisses it. Nothing is inserted\n * until the person takes it, and <code>sensitive</code> fields never ask.</p>\n * @tags input\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-textarea label=\"Description\" placeholder=\"Enter text\"></wc-textarea>\n * ```\n * @example\n * ```html\n * <wc-textarea label=\"Bio\" maxlength=\"280\" auto-grow max-rows=\"8\"></wc-textarea>\n * ```\n */\n@IndividualComponent\nexport class Textarea extends BaseField {\n // ── Static ───────────────────────────────────────────────────────────────\n\n static styles = [styles];\n\n // ── Properties ───────────────────────────────────────────────────────────\n\n @property({ type: String })\n value = '';\n\n /** Whether the browser may autofill the field: `\"on\"` or `\"off\"` (default). */\n @property({ type: String }) autocomplete: 'on' | 'off' = 'off';\n\n /** Visible lines of text; the starting height with `auto-grow`. */\n @property({ type: Number }) rows = 3;\n\n /** Fewest characters allowed. */\n @property({ type: Number, attribute: 'minlength' })\n minLength?: number;\n\n /** Most characters allowed; the textarea stops taking more and shows a character counter. */\n @property({ type: Number, attribute: 'maxlength' })\n maxLength?: number;\n\n /** Grows the height with the content instead of scrolling. */\n @property({ type: Boolean, attribute: 'auto-grow', reflect: true })\n autoGrow = false;\n\n /** With `auto-grow`, the most lines it grows to before it scrolls; unset for no limit. */\n @property({ type: Number, attribute: 'max-rows' })\n maxRows?: number;\n\n /** Which way the person can resize it by dragging the corner. */\n @property({ type: String, reflect: true })\n resize: 'none' | 'vertical' | 'both' = 'vertical';\n\n /**\n * Suggests how to go on after a pause in typing, as ghost text after the caret: Tab takes it.\n * Needs a provider with `complete`.\n */\n @property({ type: Boolean, reflect: true, attribute: 'ai-completion' })\n aiCompletion = false;\n\n // ── Queries ──────────────────────────────────────────────────────────────\n\n @query('.input-element')\n private inputElement?: HTMLTextAreaElement;\n\n // ── Private fields ───────────────────────────────────────────────────────\n\n private readonly i18n = new I18nController(this);\n\n private readonly ghost = new GhostTextController(this, {\n control: () => this.inputElement,\n enabled: () => this.aiCompletion,\n insert: text => this.insertAtCaret(text),\n i18n: this.i18n,\n });\n\n // ── Lifecycle ────────────────────────────────────────────────────────────\n\n protected override updated(changed: PropertyValues<this>) {\n super.updated(changed);\n if (\n changed.has('value') ||\n changed.has('autoGrow') ||\n changed.has('maxRows') ||\n changed.has('rows')\n ) {\n this.fitToContent();\n }\n }\n\n // ── Protected methods ────────────────────────────────────────────────────\n\n /** Just the sparkle: a label beside the text would narrow every line. */\n protected override get suggestionBadgeIconOnly(): boolean {\n return true;\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 /** With `auto-grow`, sets the height to the content's, capped at `max-rows` lines. */\n private fitToContent() {\n const textarea = this.inputElement;\n if (!textarea) return;\n if (!this.autoGrow) {\n textarea.style.removeProperty('block-size');\n textarea.style.removeProperty('overflow-y');\n return;\n }\n textarea.style.blockSize = 'auto';\n const content = textarea.scrollHeight;\n let height = content;\n if (this.maxRows && this.maxRows > 0) {\n const style = getComputedStyle(textarea);\n const lineHeight =\n parseFloat(style.lineHeight) || parseFloat(style.fontSize) * 1.2;\n const padding =\n parseFloat(style.paddingBlockStart) + parseFloat(style.paddingBlockEnd);\n height = Math.min(content, lineHeight * this.maxRows + padding);\n }\n textarea.style.blockSize = `${height}px`;\n textarea.style.overflowY = content > height ? 'auto' : 'hidden';\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 = (event.target as HTMLTextAreaElement).value;\n this.emitValue('input');\n this.ghost.onInput();\n }\n\n private handleChange(event: Event) {\n event.stopPropagation();\n this.emitValue('change');\n }\n\n private handleKeyDown(event: KeyboardEvent) {\n this.ghost.onKeyDown(event);\n }\n\n private handleBlur(event: FocusEvent) {\n this.handleFieldFocus(event);\n this.ghost.clear();\n }\n\n /** Inserts accepted ghost text at the caret, as if typed: the value changes and `input` fires. */\n private insertAtCaret(text: string) {\n const textarea = this.inputElement;\n if (!textarea) return;\n const start = textarea.selectionStart ?? textarea.value.length;\n textarea.setRangeText(text, start, textarea.selectionEnd ?? start, 'end');\n this.value = textarea.value;\n this.emitValue('input');\n }\n\n // ── Render ───────────────────────────────────────────────────────────────\n\n render() {\n const aria = this.fieldAria();\n const ghostHint = this.ghost.describedBy();\n if (ghostHint) {\n aria['aria-describedby'] = [aria['aria-describedby'], ghostHint]\n .filter(Boolean)\n .join(' ');\n }\n const control = html`<textarea\n class=\"input input-element\"\n rows=${this.rows}\n placeholder=${this.placeholder}\n autocomplete=${this.autocomplete}\n minlength=${this.minLength ?? nothing}\n maxlength=${this.maxLength ?? 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 @keydown=${this.handleKeyDown}\n @pointerdown=${() => this.ghost.clear()}\n @scroll=${() => this.ghost.clear()}\n @focus=${this.handleFieldFocus}\n @blur=${this.handleBlur}\n ${spread(aria)}\n ></textarea>`;\n return this.renderField(\n // With ai-completion the ghost text's mirror sits over the textarea.\n this.aiCompletion\n ? html`<div class=\"ghost-wrap\">${control}${this.ghost.render()}</div>`\n : control,\n {\n populated: !!this.value,\n textCount: this.characterCount(this.maxLength),\n },\n );\n }\n}\n"],"names":["nothing","html","styleMap","styles","property","query"],"mappings":";;;;;;;;;;;;;;;;;;AAkCA;AACA,MAAM,QAAQ,GAAG;IACf,WAAW;IACX,gBAAgB;IAChB,kBAAkB;IAClB,mBAAmB;IACnB,iBAAiB;IACjB,YAAY;IACZ,cAAc;IACd,eAAe;IACf,aAAa;IACb,YAAY;IACZ,UAAU;IACV,YAAY;IACZ,WAAW;IACX,YAAY;IACZ,eAAe;IACf,aAAa;IACb,YAAY;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A,EAAA,cAAA,EAAA,MAAA,CAAA;AAKb,UAAA,CAAA;IADPC,CAAK,CAAC,gBAAgB;AACoB,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,cAAA,EAAA,MAAA,CAAA;AA9ChC,QAAQ,GAAA,UAAA,CAAA;IADpB;AACY,CAAA,EAAA,QAAQ,CA0MpB;;;;"}
|
|
1
|
+
{"version":3,"file":"textarea.js","sources":["../../src/__internal/ai/ghost-text-controller.ts","../../src/textarea/textarea.ts"],"sourcesContent":["import {\n html,\n nothing,\n type ReactiveController,\n type ReactiveControllerHost,\n type TemplateResult,\n} from 'lit';\nimport { styleMap } from 'lit/directives/style-map.js';\n\nimport type { I18nController } from '../i18n/i18n-controller.js';\nimport { AiController } from './ai-controller.js';\n\ninterface GhostHost extends ReactiveControllerHost, HTMLElement {\n readonly renderRoot: HTMLElement | DocumentFragment;\n sensitive?: boolean;\n noAi?: boolean;\n name?: string;\n label?: string;\n disabled: boolean;\n readonly: boolean;\n}\n\ninterface GhostOptions {\n /** The native control the ghost text belongs to. */\n control: () => HTMLTextAreaElement | null | undefined;\n /** Whether the host asked for ghost text (`ai-completion`). */\n enabled: () => boolean;\n /** Inserts accepted text at the caret and fires the host's `input`. */\n insert: (text: string) => void;\n i18n: I18nController;\n /** Milliseconds without typing before a suggestion is asked for. */\n delay?: number;\n}\n\n/** Computed styles copied onto the mirror so its text wraps exactly like the control's. */\nconst MIRRORED = [\n 'boxSizing',\n 'borderTopWidth',\n 'borderRightWidth',\n 'borderBottomWidth',\n 'borderLeftWidth',\n 'paddingTop',\n 'paddingRight',\n 'paddingBottom',\n 'paddingLeft',\n 'fontFamily',\n 'fontSize',\n 'fontWeight',\n 'fontStyle',\n 'lineHeight',\n 'letterSpacing',\n 'wordSpacing',\n 'textIndent',\n 'textTransform',\n 'tabSize',\n 'direction',\n 'textAlign',\n] as const;\n\nconst CONTEXT_BEFORE = 4000;\nconst CONTEXT_AFTER = 1000;\n\nlet ghostCount = 0;\n\n/**\n * Ghost text for a native textarea (ADR-030002): after a pause in typing at the end of a line, the\n * provider's `complete` suggests how to go on, shown in grey after the caret. Tab takes it, Mod+→\n * takes the next word, Escape or any other key dismisses it. Nothing is inserted until the person\n * takes it.\n *\n * The suggestion is drawn in a mirror laid over the control, with the control's text metrics, so\n * it wraps like real text. Screen readers get it through the control's description.\n *\n * Usage: wrap the control in an element with `position: relative`, render `render()` beside it,\n * call `onInput()` from the control's `input`, `onKeyDown()` from its `keydown`, and `clear()` on\n * blur, scroll and selection changes; spread `describedBy()` into its `aria-describedby`.\n */\nexport class GhostTextController implements ReactiveController {\n private readonly host: GhostHost;\n\n private readonly options: GhostOptions;\n\n private readonly ai: AiController;\n\n private readonly hintId = `wc-ghost-text-${(ghostCount += 1)}`;\n\n private timer?: number;\n\n private ghost: { text: string; position: number } | null = null;\n\n private mirrorStyle: Record<string, string> = {};\n\n constructor(host: GhostHost, options: GhostOptions) {\n this.host = host;\n this.options = options;\n this.ai = new AiController(host, 'complete');\n host.addController(this);\n }\n\n hostUpdated() {\n // Keep the mirror's scroll in step with the control's.\n const mirror =\n this.host.renderRoot.querySelector<HTMLElement>('.ghost-mirror');\n const control = this.options.control();\n if (mirror && control) mirror.scrollTop = control.scrollTop;\n }\n\n hostDisconnected() {\n this.clear();\n }\n\n /** Whether ghost text can be offered now. */\n get available(): boolean {\n return (\n this.options.enabled() &&\n this.ai.available &&\n !this.host.disabled &&\n !this.host.readonly\n );\n }\n\n /** The suggestion shown, or `''`. */\n get text(): string {\n return this.ghost?.text ?? '';\n }\n\n /** The id to add to the control's `aria-describedby` while a suggestion shows. */\n describedBy(): string | undefined {\n return this.ghost ? this.hintId : undefined;\n }\n\n /** The person typed: drop the suggestion and ask again after a pause. */\n onInput() {\n this.clear();\n if (!this.available) return;\n this.timer = window.setTimeout(\n () => this.request(),\n this.options.delay ?? 600,\n );\n }\n\n /** Tab takes the suggestion, Mod+→ a word, Escape dismisses; other keys dismiss it too. */\n onKeyDown(event: KeyboardEvent) {\n if (!this.ghost) return;\n const word = event.key === 'ArrowRight' && (event.ctrlKey || event.metaKey);\n const all =\n event.key === 'Tab' &&\n !event.shiftKey &&\n !event.altKey &&\n !event.ctrlKey &&\n !event.metaKey;\n if (all || word) {\n event.preventDefault();\n this.accept(all ? 'all' : 'word');\n return;\n }\n if (event.key === 'Escape') {\n // The suggestion takes this Escape, not a dialog around the field.\n event.preventDefault();\n event.stopPropagation();\n }\n if (!['Shift', 'Control', 'Alt', 'Meta'].includes(event.key)) this.clear();\n }\n\n /** Drops the suggestion and any request for it. */\n clear() {\n window.clearTimeout(this.timer);\n this.timer = undefined;\n this.ai.abort();\n if (!this.ghost) return;\n this.ghost = null;\n this.host.requestUpdate();\n }\n\n /** The mirror with the suggestion, and the screen-reader hint. */\n render(): TemplateResult | typeof nothing {\n const { ghost } = this;\n const control = this.options.control();\n if (!ghost || !control) return nothing;\n const before = control.value.slice(0, ghost.position);\n // No whitespace inside the mirror: it keeps white space, so any would show as text.\n // prettier-ignore\n return html`<div class=\"ghost-mirror\" aria-hidden=\"true\" style=${styleMap(this.mirrorStyle)}><span class=\"ghost-before\">${before}</span><span class=\"ghost-text\">${ghost.text}</span></div>\n <span id=${this.hintId} hidden\n >${this.options.i18n.t('aiGhostHint')(ghost.text)}</span\n >`;\n }\n\n private async request() {\n const control = this.options.control();\n const { provider } = this.ai;\n if (!control || !provider?.complete || !this.available) return;\n const { value, selectionStart, selectionEnd } = control;\n if (selectionStart !== selectionEnd) return;\n const position = selectionStart ?? value.length;\n const rest = value.slice(position);\n // Only at the end of a line, where text after the caret can't be in the way.\n if (rest.split('\\n')[0].trim()) return;\n if (!value.slice(0, position).trim()) return;\n const text = await this.ai.run(signal =>\n provider.complete!({\n signal,\n context: this.ai.context(),\n before: value.slice(0, position).slice(-CONTEXT_BEFORE),\n after: rest.slice(0, CONTEXT_AFTER),\n }),\n );\n if (!text || control.value !== value) return;\n if (control.selectionStart !== position) return;\n this.mirrorStyle = this.measure(control);\n this.ghost = { text, position };\n this.host.requestUpdate();\n }\n\n private accept(part: 'all' | 'word') {\n const { ghost } = this;\n if (!ghost) return;\n const taken =\n part === 'all' ? ghost.text : (/^\\s*\\S+/.exec(ghost.text)?.[0] ?? '');\n const rest = ghost.text.slice(taken.length);\n this.ghost = null;\n if (taken) this.options.insert(taken);\n this.ghost = rest\n ? { text: rest, position: ghost.position + taken.length }\n : null;\n this.host.requestUpdate();\n }\n\n private measure(control: HTMLTextAreaElement): Record<string, string> {\n const computed = getComputedStyle(control);\n const style: Record<string, string> = {};\n for (const property of MIRRORED) {\n style[property.replace(/[A-Z]/g, c => `-${c.toLowerCase()}`)] =\n computed[property];\n }\n style['border-color'] = 'transparent';\n style['border-style'] = 'solid';\n return style;\n }\n}\n","import { html, nothing, type PropertyValues } from 'lit';\nimport { property, query } from 'lit/decorators.js';\n\nimport { spread } from '@/__internal/directive/spread.js';\nimport { GhostTextController } from '@/__internal/ai/ghost-text-controller.js';\nimport { I18nController } from '@/__internal/i18n/i18n-controller.js';\n\nimport IndividualComponent from '@/IndividualComponent.js';\nimport BaseField from '../input/BaseField.js';\nimport { type ControlValidity, nativeValidity } from '../input/BaseInput.js';\nimport styles from './textarea.scss';\n\n/**\n * @label Textarea\n * @tag wc-textarea\n * @rawTag textarea\n * @summary A multi-line text field that can grow with its content.\n * @overview\n * <p>Textarea 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 textarea: <code>required</code>, <code>minlength</code> and\n * <code>maxlength</code> block form submission, and the message shows under the field once the\n * value is committed or the form is submitted. With <code>maxlength</code> a character counter\n * shows under the field.</p>\n * <p><code>rows</code> sets the starting height. With <code>auto-grow</code> the height follows the\n * content, up to <code>max-rows</code> when it is set; <code>resize</code> controls whether the\n * person can drag the corner to resize it.</p>\n * <p>With <code>ai-completion</code> and a provider that offers completions (ADR-030002), a pause\n * in typing at the end of a line shows ghost text: how the assistant would go on, in grey after the\n * caret. Tab takes it, Ctrl+→ (⌘→) takes a word, Escape or typing dismisses it. Nothing is inserted\n * until the person takes it, and <code>sensitive</code> fields never ask.</p>\n * @tags input\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-textarea label=\"Description\" placeholder=\"Enter text\"></wc-textarea>\n * ```\n * @example\n * ```html\n * <wc-textarea label=\"Bio\" maxlength=\"280\" auto-grow max-rows=\"8\"></wc-textarea>\n * ```\n */\n@IndividualComponent\nexport class Textarea extends BaseField {\n // ── Static ───────────────────────────────────────────────────────────────\n\n static styles = [styles];\n\n // ── Properties ───────────────────────────────────────────────────────────\n\n @property({ type: String })\n value = '';\n\n /** Whether the browser may autofill the field: `\"on\"` or `\"off\"` (default). */\n @property({ type: String }) autocomplete: 'on' | 'off' = 'off';\n\n /** Visible lines of text; the starting height with `auto-grow`. */\n @property({ type: Number }) rows = 3;\n\n /** Fewest characters allowed. */\n @property({ type: Number, attribute: 'minlength' })\n minLength?: number;\n\n /** Most characters allowed; the textarea stops taking more and shows a character counter. */\n @property({ type: Number, attribute: 'maxlength' })\n maxLength?: number;\n\n /** Grows the height with the content instead of scrolling. */\n @property({ type: Boolean, attribute: 'auto-grow', reflect: true })\n autoGrow = false;\n\n /** With `auto-grow`, the most lines it grows to before it scrolls; unset for no limit. */\n @property({ type: Number, attribute: 'max-rows' })\n maxRows?: number;\n\n /** Which way the person can resize it by dragging the corner. */\n @property({ type: String, reflect: true })\n resize: 'none' | 'vertical' | 'both' = 'vertical';\n\n /**\n * Suggests how to go on after a pause in typing, as ghost text after the caret: Tab takes it.\n * Needs a provider with `complete`.\n */\n @property({ type: Boolean, reflect: true, attribute: 'ai-completion' })\n aiCompletion = false;\n\n // ── Queries ──────────────────────────────────────────────────────────────\n\n @query('.input-element')\n private inputElement?: HTMLTextAreaElement;\n\n // ── Private fields ───────────────────────────────────────────────────────\n\n private readonly i18n = new I18nController(this);\n\n private readonly ghost = new GhostTextController(this, {\n control: () => this.inputElement,\n enabled: () => this.aiCompletion,\n insert: text => this.insertAtCaret(text),\n i18n: this.i18n,\n });\n\n // ── Lifecycle ────────────────────────────────────────────────────────────\n\n protected override updated(changed: PropertyValues<this>) {\n super.updated(changed);\n if (\n changed.has('value') ||\n changed.has('autoGrow') ||\n changed.has('maxRows') ||\n changed.has('rows')\n ) {\n this.fitToContent();\n }\n }\n\n // ── Protected methods ────────────────────────────────────────────────────\n\n /** Just the sparkle: a label beside the text would narrow every line. */\n protected override get suggestionBadgeIconOnly(): boolean {\n return true;\n }\n\n /** Multi-line: like a native textarea, it does not count for implicit submission. */\n protected override get singleLineTextField(): boolean {\n return false;\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 /** With `auto-grow`, sets the height to the content's, capped at `max-rows` lines. */\n private fitToContent() {\n const textarea = this.inputElement;\n if (!textarea) return;\n if (!this.autoGrow) {\n textarea.style.removeProperty('block-size');\n textarea.style.removeProperty('overflow-y');\n return;\n }\n textarea.style.blockSize = 'auto';\n const content = textarea.scrollHeight;\n let height = content;\n if (this.maxRows && this.maxRows > 0) {\n const style = getComputedStyle(textarea);\n const lineHeight =\n parseFloat(style.lineHeight) || parseFloat(style.fontSize) * 1.2;\n const padding =\n parseFloat(style.paddingBlockStart) + parseFloat(style.paddingBlockEnd);\n height = Math.min(content, lineHeight * this.maxRows + padding);\n }\n textarea.style.blockSize = `${height}px`;\n textarea.style.overflowY = content > height ? 'auto' : 'hidden';\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 = (event.target as HTMLTextAreaElement).value;\n this.emitValue('input');\n this.ghost.onInput();\n }\n\n private handleChange(event: Event) {\n event.stopPropagation();\n this.emitValue('change');\n }\n\n private handleKeyDown(event: KeyboardEvent) {\n this.ghost.onKeyDown(event);\n }\n\n private handleBlur(event: FocusEvent) {\n this.handleFieldFocus(event);\n this.ghost.clear();\n }\n\n /** Inserts accepted ghost text at the caret, as if typed: the value changes and `input` fires. */\n private insertAtCaret(text: string) {\n const textarea = this.inputElement;\n if (!textarea) return;\n const start = textarea.selectionStart ?? textarea.value.length;\n textarea.setRangeText(text, start, textarea.selectionEnd ?? start, 'end');\n this.value = textarea.value;\n this.emitValue('input');\n }\n\n // ── Render ───────────────────────────────────────────────────────────────\n\n render() {\n const aria = this.fieldAria();\n const ghostHint = this.ghost.describedBy();\n if (ghostHint) {\n aria['aria-describedby'] = [aria['aria-describedby'], ghostHint]\n .filter(Boolean)\n .join(' ');\n }\n const control = html`<textarea\n class=\"input input-element\"\n rows=${this.rows}\n placeholder=${this.placeholder}\n autocomplete=${this.autocomplete}\n minlength=${this.minLength ?? nothing}\n maxlength=${this.maxLength ?? 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 @keydown=${this.handleKeyDown}\n @pointerdown=${() => this.ghost.clear()}\n @scroll=${() => this.ghost.clear()}\n @focus=${this.handleFieldFocus}\n @blur=${this.handleBlur}\n ${spread(aria)}\n ></textarea>`;\n return this.renderField(\n // With ai-completion the ghost text's mirror sits over the textarea.\n this.aiCompletion\n ? html`<div class=\"ghost-wrap\">${control}${this.ghost.render()}</div>`\n : control,\n {\n populated: !!this.value,\n textCount: this.characterCount(this.maxLength),\n },\n );\n }\n}\n"],"names":["nothing","html","styleMap","styles","property","query"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAkCA;AACA,MAAM,QAAQ,GAAG;IACf,W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AE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE;AACS,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,QAAA,EAAA,MAAA,CAAA;AAOlD,UAAA,CAAA;AADC,IAAAA,CAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,eAAe,EAAE;AACjD,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,cAAA,EAAA,MAAA,CAAA;AAKb,UAAA,CAAA;IADPC,CAAK,CAAC,gBAAgB;AACoB,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,cAAA,EAAA,MAAA,CAAA;AA9ChC,QAAQ,GAAA,UAAA,CAAA;IADpB;AACY,CAAA,EAAA,QAAQ,CA+MpB;;;;"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
function throttle(func, delay, options = { leading: true, trailing: true }) {
|
|
2
|
+
let timerId;
|
|
3
|
+
let lastExec = 0;
|
|
4
|
+
return function (...args) {
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
const context = this;
|
|
7
|
+
const now = Date.now();
|
|
8
|
+
const shouldCallNow = options.leading && now - lastExec >= delay;
|
|
9
|
+
if (shouldCallNow) {
|
|
10
|
+
func.apply(context, args);
|
|
11
|
+
lastExec = now;
|
|
12
|
+
}
|
|
13
|
+
else if (options.trailing && !timerId) {
|
|
14
|
+
timerId = setTimeout(() => {
|
|
15
|
+
func.apply(context, args);
|
|
16
|
+
lastExec = Date.now();
|
|
17
|
+
timerId = null;
|
|
18
|
+
}, delay);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { throttle as t };
|
|
24
|
+
//# sourceMappingURL=throttle-C7ZAPqtu.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"throttle-C7ZAPqtu.js","sources":["../../src/__internal/utils/throttle.ts"],"sourcesContent":["export function throttle(\n func: Function,\n delay: number,\n options = { leading: true, trailing: true },\n) {\n let timerId: any;\n let lastExec = 0;\n\n return function (...args: any[]) {\n // @ts-ignore\n const context = this;\n const now = Date.now();\n\n const shouldCallNow = options.leading && now - lastExec >= delay;\n\n if (shouldCallNow) {\n func.apply(context, args);\n lastExec = now;\n } else if (options.trailing && !timerId) {\n timerId = setTimeout(() => {\n func.apply(context, args);\n lastExec = Date.now();\n timerId = null;\n }, delay);\n }\n };\n}\n"],"names":[],"mappings":"SAAgB,QAAQ,CACtB,IAAc,EACd,KAAa,EACb,OAAO,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAA;AAE3C,IAAA,IAAI,OAAY;IAChB,IAAI,QAAQ,GAAG,CAAC;IAEhB,OAAO,UAAU,GAAG,IAAW,EAAA;;QAE7B,MAAM,OAAO,GAAG,IAAI;AACpB,QAAA,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE;QAEtB,MAAM,aAAa,GAAG,OAAO,CAAC,OAAO,IAAI,GAAG,GAAG,QAAQ,IAAI,KAAK;QAEhE,IAAI,aAAa,EAAE;AACjB,YAAA,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC;YACzB,QAAQ,GAAG,GAAG;QAChB;AAAO,aAAA,IAAI,OAAO,CAAC,QAAQ,IAAI,CAAC,OAAO,EAAE;AACvC,YAAA,OAAO,GAAG,UAAU,CAAC,MAAK;AACxB,gBAAA,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC;AACzB,gBAAA,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE;gBACrB,OAAO,GAAG,IAAI;YAChB,CAAC,EAAE,KAAK,CAAC;QACX;AACF,IAAA,CAAC;AACH;;;;"}
|
package/dist/time-field.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { i, _ as __decorate, I as IndividualComponent, b } from './IndividualComponent-BK7XZjE2.js';
|
|
2
2
|
import { n } from './property-B2TG3KEE.js';
|
|
3
|
-
import { P as PickerField } from './picker-field-
|
|
4
|
-
import { c as parseTimeText, b as parseIsoTime, e as formatTime, r as resolveHourCycle } from './date-
|
|
3
|
+
import { P as PickerField } from './picker-field-BiM3iXAQ.js';
|
|
4
|
+
import { c as parseTimeText, b as parseIsoTime, e as formatTime, r as resolveHourCycle } from './date-DPQOY8Zd.js';
|
|
5
5
|
import './state-BCeDVCI9.js';
|
|
6
6
|
import './query-CHb9Ft_d.js';
|
|
7
7
|
import './base-Cl6v8-BZ.js';
|
|
@@ -10,13 +10,16 @@ import './directive-ZPhl09Yt.js';
|
|
|
10
10
|
import './i18n-controller-BTeChxE0.js';
|
|
11
11
|
import './strings-DeiQWMd9.js';
|
|
12
12
|
import './locale-DEsJZCQG.js';
|
|
13
|
-
import './BaseField-
|
|
13
|
+
import './BaseField-DOCmylob.js';
|
|
14
|
+
import './implicit-submission-ChLdbxaR.js';
|
|
15
|
+
import './dispatch-hooks-J_godlHh.js';
|
|
16
|
+
import './form-submission-h40coUI8.js';
|
|
14
17
|
import './BaseInput-Cv03GZLu.js';
|
|
15
18
|
import './element-internals-QME0yEz4.js';
|
|
16
19
|
import './form-associated-BHbg72PG.js';
|
|
17
20
|
import './suggestion-controller-7YRQqkaI.js';
|
|
18
21
|
import './ai-controller-DR_Tg0sN.js';
|
|
19
|
-
import './utils-
|
|
22
|
+
import './utils-CQzycr9J.js';
|
|
20
23
|
|
|
21
24
|
var css_248z = i`* {
|
|
22
25
|
box-sizing: border-box;
|
package/dist/time-field.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time-field.js","sources":["../../src/time-field/time-field.ts"],"sourcesContent":["import { html } from 'lit';\nimport { property } from 'lit/decorators.js';\n\nimport IndividualComponent from '@/IndividualComponent.js';\nimport PickerField, { type ValueProblem } from '@/__internal/picker-field.js';\nimport {\n type HourCycle,\n formatTime,\n parseIsoTime,\n parseTimeText,\n resolveHourCycle,\n} from '@/__internal/utils/date.js';\nimport styles from './time-field.scss';\n\n/** Compares two ISO times, with or without seconds. */\nfunction compareTime(a: string, b: string): number {\n const pa = parseIsoTime(a);\n const pb = parseIsoTime(b);\n if (!pa || !pb) return 0;\n const sa = pa.hour * 3600 + pa.minute * 60 + pa.second;\n const sb = pb.hour * 3600 + pb.minute * 60 + pb.second;\n return sa - sb;\n}\n\n/**\n * @label Time Field\n * @tag wc-time-field\n * @rawTag time-field\n *\n * @summary A text field for a time of day, with columns to pick from.\n * @overview\n * <p>Time field shows the time in the locale's format. Type a time (<code>9:30</code>,\n * <code>930</code>, <code>9:30 pm</code>, <code>21:30</code>), or open the time picker\n * (<code>wc-time-picker</code>) from the button or with Alt+Down. Typed text is read when the\n * field loses focus or on Enter.</p>\n * <p>The value is always a 24-hour ISO time (<code>09:30</code>), and it is form-associated.</p>\n *\n * @fires {CustomEvent<{value: string}>} input - Dispatched while the time changes in the picker.\n * @fires {CustomEvent<{value: string}>} change - Dispatched when a time is committed, by typing, picking the last column, or closing the picker.\n *\n * @example\n * ```html\n * <wc-time-field label=\"Start time\" value=\"09:30\" minute-step=\"15\"></wc-time-field>\n * ```\n * @tags input, form\n */\n@IndividualComponent\nexport class TimeField extends PickerField {\n // ── Static ───────────────────────────────────────────────────────────────\n\n static styles = [styles];\n\n // ── Properties ───────────────────────────────────────────────────────────\n\n /** Minutes between entries in the picker's minute column. */\n @property({ type: Number, attribute: 'minute-step' }) minuteStep = 1;\n\n /** The value's format: `HH:mm:ss` with seconds (and a seconds column), else `HH:mm`. */\n @property({ type: Boolean }) seconds = false;\n\n /** `h12` or `h23`; defaults to the locale's. */\n @property({ type: String, attribute: 'hour-cycle' }) hourCycle?: HourCycle;\n\n /** Earliest allowed time (`HH:mm`). */\n @property({ type: String }) min = '';\n\n /** Latest allowed time (`HH:mm`). */\n @property({ type: String }) max = '';\n\n // ── Protected fields ─────────────────────────────────────────────────────\n\n protected readonly pickerIcon = 'schedule';\n\n protected get pickerLabel(): string {\n return this.i18n.t('chooseTime');\n }\n\n // ── Protected methods ────────────────────────────────────────────────────\n\n protected closeOnCommit(): boolean {\n return true;\n }\n\n protected parseText(text: string): string | null {\n return parseTimeText(text, this.seconds);\n }\n\n protected formatValue(value: string): string {\n return parseIsoTime(value)\n ? formatTime(\n value,\n this.resolvedLocale,\n this.resolvedHourCycle,\n this.seconds,\n )\n : '';\n }\n\n protected formatHint(): string {\n const h12 = this.resolvedHourCycle === 'h12';\n const base = this.seconds ? 'hh:mm:ss' : 'hh:mm';\n return h12 ? `${base} AM` : base;\n }\n\n protected validateValue(value: string): ValueProblem | null {\n const locale = this.resolvedLocale;\n if (this.min && compareTime(value, this.min) < 0) {\n return {\n flag: 'rangeUnderflow',\n message: this.i18n.t('pickTimeAtOrAfter')(\n formatTime(this.min, locale, this.resolvedHourCycle),\n ),\n };\n }\n if (this.max && compareTime(value, this.max) > 0) {\n return {\n flag: 'rangeOverflow',\n message: this.i18n.t('pickTimeAtOrBefore')(\n formatTime(this.max, locale, this.resolvedHourCycle),\n ),\n };\n }\n return null;\n }\n\n protected renderPicker() {\n return html`\n <wc-time-picker\n class=\"picker\"\n .value=${this.value}\n minute-step=${this.minuteStep}\n ?seconds=${this.seconds}\n .hourCycle=${this.hourCycle}\n min=${this.min}\n max=${this.max}\n locale=${this.locale}\n ?disabled=${this.disabled}\n ?readonly=${this.readonly}\n @input=${this.handlePickerInput}\n @change=${this.handlePickerChange}\n ></wc-time-picker>\n `;\n }\n\n // ── Private getters ──────────────────────────────────────────────────────\n\n private get resolvedHourCycle(): HourCycle {\n return resolveHourCycle(this.hourCycle, this.resolvedLocale);\n }\n}\n"],"names":["html","styles","property"],"mappings":"
|
|
1
|
+
{"version":3,"file":"time-field.js","sources":["../../src/time-field/time-field.ts"],"sourcesContent":["import { html } from 'lit';\nimport { property } from 'lit/decorators.js';\n\nimport IndividualComponent from '@/IndividualComponent.js';\nimport PickerField, { type ValueProblem } from '@/__internal/picker-field.js';\nimport {\n type HourCycle,\n formatTime,\n parseIsoTime,\n parseTimeText,\n resolveHourCycle,\n} from '@/__internal/utils/date.js';\nimport styles from './time-field.scss';\n\n/** Compares two ISO times, with or without seconds. */\nfunction compareTime(a: string, b: string): number {\n const pa = parseIsoTime(a);\n const pb = parseIsoTime(b);\n if (!pa || !pb) return 0;\n const sa = pa.hour * 3600 + pa.minute * 60 + pa.second;\n const sb = pb.hour * 3600 + pb.minute * 60 + pb.second;\n return sa - sb;\n}\n\n/**\n * @label Time Field\n * @tag wc-time-field\n * @rawTag time-field\n *\n * @summary A text field for a time of day, with columns to pick from.\n * @overview\n * <p>Time field shows the time in the locale's format. Type a time (<code>9:30</code>,\n * <code>930</code>, <code>9:30 pm</code>, <code>21:30</code>), or open the time picker\n * (<code>wc-time-picker</code>) from the button or with Alt+Down. Typed text is read when the\n * field loses focus or on Enter.</p>\n * <p>The value is always a 24-hour ISO time (<code>09:30</code>), and it is form-associated.</p>\n *\n * @fires {CustomEvent<{value: string}>} input - Dispatched while the time changes in the picker.\n * @fires {CustomEvent<{value: string}>} change - Dispatched when a time is committed, by typing, picking the last column, or closing the picker.\n *\n * @example\n * ```html\n * <wc-time-field label=\"Start time\" value=\"09:30\" minute-step=\"15\"></wc-time-field>\n * ```\n * @tags input, form\n */\n@IndividualComponent\nexport class TimeField extends PickerField {\n // ── Static ───────────────────────────────────────────────────────────────\n\n static styles = [styles];\n\n // ── Properties ───────────────────────────────────────────────────────────\n\n /** Minutes between entries in the picker's minute column. */\n @property({ type: Number, attribute: 'minute-step' }) minuteStep = 1;\n\n /** The value's format: `HH:mm:ss` with seconds (and a seconds column), else `HH:mm`. */\n @property({ type: Boolean }) seconds = false;\n\n /** `h12` or `h23`; defaults to the locale's. */\n @property({ type: String, attribute: 'hour-cycle' }) hourCycle?: HourCycle;\n\n /** Earliest allowed time (`HH:mm`). */\n @property({ type: String }) min = '';\n\n /** Latest allowed time (`HH:mm`). */\n @property({ type: String }) max = '';\n\n // ── Protected fields ─────────────────────────────────────────────────────\n\n protected readonly pickerIcon = 'schedule';\n\n protected get pickerLabel(): string {\n return this.i18n.t('chooseTime');\n }\n\n // ── Protected methods ────────────────────────────────────────────────────\n\n protected closeOnCommit(): boolean {\n return true;\n }\n\n protected parseText(text: string): string | null {\n return parseTimeText(text, this.seconds);\n }\n\n protected formatValue(value: string): string {\n return parseIsoTime(value)\n ? formatTime(\n value,\n this.resolvedLocale,\n this.resolvedHourCycle,\n this.seconds,\n )\n : '';\n }\n\n protected formatHint(): string {\n const h12 = this.resolvedHourCycle === 'h12';\n const base = this.seconds ? 'hh:mm:ss' : 'hh:mm';\n return h12 ? `${base} AM` : base;\n }\n\n protected validateValue(value: string): ValueProblem | null {\n const locale = this.resolvedLocale;\n if (this.min && compareTime(value, this.min) < 0) {\n return {\n flag: 'rangeUnderflow',\n message: this.i18n.t('pickTimeAtOrAfter')(\n formatTime(this.min, locale, this.resolvedHourCycle),\n ),\n };\n }\n if (this.max && compareTime(value, this.max) > 0) {\n return {\n flag: 'rangeOverflow',\n message: this.i18n.t('pickTimeAtOrBefore')(\n formatTime(this.max, locale, this.resolvedHourCycle),\n ),\n };\n }\n return null;\n }\n\n protected renderPicker() {\n return html`\n <wc-time-picker\n class=\"picker\"\n .value=${this.value}\n minute-step=${this.minuteStep}\n ?seconds=${this.seconds}\n .hourCycle=${this.hourCycle}\n min=${this.min}\n max=${this.max}\n locale=${this.locale}\n ?disabled=${this.disabled}\n ?readonly=${this.readonly}\n @input=${this.handlePickerInput}\n @change=${this.handlePickerChange}\n ></wc-time-picker>\n `;\n }\n\n // ── Private getters ──────────────────────────────────────────────────────\n\n private get resolvedHourCycle(): HourCycle {\n return resolveHourCycle(this.hourCycle, this.resolvedLocale);\n }\n}\n"],"names":["html","styles","property"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA;AACA,SAAS,WAAW,CAAC,CAAS,EAAE,CAAS,EAAA;AACvC,IAAA,MAAM,EAAE,GAAG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ualComponent, a as i$1, A, b } from './
|
|
|
2
2
|
import { n } from './property-B2TG3KEE.js';
|
|
3
3
|
import { r } from './state-BCeDVCI9.js';
|
|
4
4
|
import { e } from './class-map-NDIkZErE.js';
|
|
5
|
-
import { r as resolveHourCycle, b as parseIsoTime, d as dayPeriodNames, t as toIsoTime } from './date-
|
|
5
|
+
import { r as resolveHourCycle, b as parseIsoTime, d as dayPeriodNames, t as toIsoTime } from './date-DPQOY8Zd.js';
|
|
6
6
|
import { I as I18nController } from './i18n-controller-BTeChxE0.js';
|
|
7
7
|
import './directive-ZPhl09Yt.js';
|
|
8
|
-
import './utils-
|
|
8
|
+
import './utils-CQzycr9J.js';
|
|
9
9
|
import './locale-DEsJZCQG.js';
|
|
10
10
|
import './strings-DeiQWMd9.js';
|
|
11
11
|
|
package/dist/toolbar.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { i, _ as __decorate, I as IndividualComponent, a as i$1, A, b } from './IndividualComponent-BK7XZjE2.js';
|
|
2
2
|
import { n } from './property-B2TG3KEE.js';
|
|
3
3
|
import { e } from './class-map-NDIkZErE.js';
|
|
4
|
-
import { R as RovingFocusController } from './roving-focus-controller-
|
|
4
|
+
import { R as RovingFocusController } from './roving-focus-controller-YtNbxH95.js';
|
|
5
5
|
import './directive-ZPhl09Yt.js';
|
|
6
6
|
|
|
7
7
|
var css_248z$1 = i`* {
|
|
@@ -159,7 +159,9 @@ const SEPARATOR_SELECTOR = 'wc-divider, hr, [role="separator"]';
|
|
|
159
159
|
*
|
|
160
160
|
* <p>The toolbar follows the WAI-ARIA toolbar pattern: it is a single tab stop, and the arrow
|
|
161
161
|
* keys along its orientation move focus between actions (Home and End jump to the first and last).
|
|
162
|
-
* Disabled actions and dividers are skipped
|
|
162
|
+
* Disabled actions and dividers are skipped, and when the action that holds the tab stop becomes
|
|
163
|
+
* disabled or hidden, the next enabled action (else the previous one) takes it over. Give the
|
|
164
|
+
* toolbar an <code>aria-label</code>.</p>
|
|
163
165
|
*
|
|
164
166
|
* @cssprop --toolbar-container-color - Background color of the toolbar.
|
|
165
167
|
* @cssprop --toolbar-container-shape - Border radius of the floating toolbar.
|
|
@@ -226,6 +228,13 @@ let Toolbar = class Toolbar extends i$1 {
|
|
|
226
228
|
items: () => this.__getItems(),
|
|
227
229
|
orientation: () => this.orientation,
|
|
228
230
|
});
|
|
231
|
+
/**
|
|
232
|
+
* Re-applies the tab stop when an action becomes disabled, aria-disabled or hidden, so it moves
|
|
233
|
+
* to the next enabled action instead of leaving the toolbar out of the Tab order.
|
|
234
|
+
*/
|
|
235
|
+
this.__actionStateObserver = new MutationObserver(() => {
|
|
236
|
+
this.roving.sync();
|
|
237
|
+
});
|
|
229
238
|
this.__handleSlotChange = () => {
|
|
230
239
|
this.roving.sync();
|
|
231
240
|
};
|
|
@@ -235,6 +244,15 @@ let Toolbar = class Toolbar extends i$1 {
|
|
|
235
244
|
super.connectedCallback();
|
|
236
245
|
// The role lives on the host so the host's aria-label names the toolbar.
|
|
237
246
|
this.setAttribute('role', 'toolbar');
|
|
247
|
+
this.__actionStateObserver.observe(this, {
|
|
248
|
+
subtree: true,
|
|
249
|
+
attributes: true,
|
|
250
|
+
attributeFilter: ['disabled', 'aria-disabled', 'hidden'],
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
disconnectedCallback() {
|
|
254
|
+
super.disconnectedCallback();
|
|
255
|
+
this.__actionStateObserver.disconnect();
|
|
238
256
|
}
|
|
239
257
|
updated(changed) {
|
|
240
258
|
if (changed.has('orientation')) {
|
|
@@ -242,18 +260,17 @@ let Toolbar = class Toolbar extends i$1 {
|
|
|
242
260
|
}
|
|
243
261
|
}
|
|
244
262
|
// ── Private methods
|
|
245
|
-
/**
|
|
263
|
+
/**
|
|
264
|
+
* The actions, in slot order. Disabled and hidden ones are included: the roving controller skips
|
|
265
|
+
* them, takes the tab stop off them and hands it to the next enabled action.
|
|
266
|
+
*/
|
|
246
267
|
__getItems() {
|
|
247
268
|
const slot = this.shadowRoot?.querySelector('slot');
|
|
248
269
|
if (!slot)
|
|
249
270
|
return [];
|
|
250
271
|
return slot
|
|
251
272
|
.assignedElements({ flatten: true })
|
|
252
|
-
.filter((el) => el instanceof HTMLElement &&
|
|
253
|
-
!el.matches(SEPARATOR_SELECTOR) &&
|
|
254
|
-
!el.hasAttribute('disabled') &&
|
|
255
|
-
el.getAttribute('aria-disabled') !== 'true' &&
|
|
256
|
-
!el.hidden);
|
|
273
|
+
.filter((el) => el instanceof HTMLElement && !el.matches(SEPARATOR_SELECTOR));
|
|
257
274
|
}
|
|
258
275
|
// ── Render
|
|
259
276
|
render() {
|
package/dist/toolbar.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolbar.js","sources":["../../src/toolbar/toolbar.ts"],"sourcesContent":["import { LitElement, html, nothing } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport IndividualComponent from '@/IndividualComponent.js';\nimport { RovingFocusController } from '@/__internal/controllers/roving-focus-controller.js';\nimport styles from './toolbar.scss';\nimport colorStyles from './toolbar-colors.scss';\n\n/** Slotted elements that separate groups and never take focus. */\nconst SEPARATOR_SELECTOR = 'wc-divider, hr, [role=\"separator\"]';\n\n/**\n * @label Toolbar\n * @tag wc-toolbar\n * @rawTag toolbar\n *\n * @summary A group of related actions, such as editor formatting controls.\n * @overview\n * <p>The toolbar groups related actions into one control. The <code>floating</code> variant\n * (default) is an elevated pill that sits over content, such as a canvas or a selection. The\n * <code>flat</code> variant has no container of its own, for embedding in existing chrome like a\n * card or editor header. Both variants lay their actions out horizontally or vertically.</p>\n *\n * <p>Render actions directly as children. Use a <code>wc-divider</code> to separate groups of\n * actions; in a horizontal toolbar give it <code>orientation=\"vertical\"</code>.</p>\n *\n * <p>The toolbar follows the WAI-ARIA toolbar pattern: it is a single tab stop, and the arrow\n * keys along its orientation move focus between actions (Home and End jump to the first and last).\n * Disabled actions and dividers are skipped. Give the toolbar an <code>aria-label</code>.</p>\n *\n * @cssprop --toolbar-container-color - Background color of the toolbar.\n * @cssprop --toolbar-container-shape - Border radius of the floating toolbar.\n * @cssprop --toolbar-padding - Padding of the floating toolbar.\n * @cssprop --toolbar-gap - Gap between toolbar actions.\n * @cssprop --toolbar-icon-color - Color of icons inside the toolbar.\n * @cssprop --toolbar-content-color - Color of text inside the toolbar.\n * @cssprop --toolbar-wrap - `wrap` lets actions flow onto more lines when the toolbar is narrow. Defaults to `nowrap`.\n *\n * @example\n * ```html\n * <!-- Floating toolbar -->\n * <wc-toolbar aria-label=\"Formatting\">\n * <wc-icon-button variant=\"text\" color=\"surface\" aria-label=\"Undo\"><wc-icon name=\"undo\"></wc-icon></wc-icon-button>\n * <wc-icon-button variant=\"text\" color=\"surface\" aria-label=\"Redo\"><wc-icon name=\"redo\"></wc-icon></wc-icon-button>\n * <wc-divider orientation=\"vertical\"></wc-divider>\n * <wc-icon-button variant=\"tonal\" aria-label=\"Bold\"><wc-icon name=\"format_bold\"></wc-icon></wc-icon-button>\n * <wc-icon-button variant=\"text\" color=\"surface\" aria-label=\"Italic\"><wc-icon name=\"format_italic\"></wc-icon></wc-icon-button>\n * </wc-toolbar>\n * ```\n *\n * @example\n * ```html\n * <!-- Vertical floating toolbar -->\n * <wc-toolbar orientation=\"vertical\" aria-label=\"Tools\">\n * <wc-icon-button variant=\"tonal\" aria-label=\"Select\"><wc-icon name=\"arrow_selector_tool\"></wc-icon></wc-icon-button>\n * <wc-icon-button variant=\"text\" color=\"surface\" aria-label=\"Draw\"><wc-icon name=\"draw\"></wc-icon></wc-icon-button>\n * <wc-icon-button variant=\"text\" color=\"surface\" aria-label=\"Text\"><wc-icon name=\"text_fields\"></wc-icon></wc-icon-button>\n * </wc-toolbar>\n * ```\n *\n * @example\n * ```html\n * <!-- Flat toolbar inside existing chrome -->\n * <wc-toolbar variant=\"flat\" aria-label=\"Row actions\">\n * <wc-icon-button variant=\"text\" color=\"surface\" aria-label=\"Edit\"><wc-icon name=\"edit\"></wc-icon></wc-icon-button>\n * <wc-icon-button variant=\"text\" color=\"surface\" aria-label=\"Delete\"><wc-icon name=\"delete\"></wc-icon></wc-icon-button>\n * </wc-toolbar>\n * ```\n * @tags display\n */\n@IndividualComponent\nexport class Toolbar extends LitElement {\n // ── Static\n static styles = [styles, colorStyles];\n\n // ── Properties\n\n /**\n * Visual variant of the toolbar.\n * - `\"floating\"`: An elevated pill that floats over content (default).\n * - `\"flat\"`: No container, fill or elevation; for embedding in existing chrome.\n */\n @property({ type: String, reflect: true })\n variant: 'floating' | 'flat' = 'floating';\n\n /**\n * Orientation of the toolbar. It sets the layout direction and the arrow keys that move focus\n * (Left/Right for horizontal, Up/Down for vertical).\n */\n @property({ type: String, reflect: true })\n orientation: 'horizontal' | 'vertical' = 'horizontal';\n\n /**\n * Raises the floating toolbar to a higher elevation. Has no effect on the flat variant.\n */\n @property({ type: Boolean, reflect: true })\n elevated: boolean = false;\n\n // ── Private fields\n\n /** The toolbar's single tab stop, moved with the arrow keys along its orientation. */\n private readonly roving = new RovingFocusController(this, {\n items: () => this.__getItems(),\n orientation: () => this.orientation,\n });\n\n // ── Lifecycle\n\n override connectedCallback() {\n super.connectedCallback();\n // The role lives on the host so the host's aria-label names the toolbar.\n this.setAttribute('role', 'toolbar');\n }\n\n override updated(changed: Map<string, unknown>) {\n if (changed.has('orientation')) {\n this.setAttribute('aria-orientation', this.orientation);\n }\n }\n\n // ── Private methods\n\n /** Actions that can take focus, in slot order. */\n private __getItems(): HTMLElement[] {\n const slot = this.shadowRoot?.querySelector('slot');\n if (!slot) return [];\n return slot\n .assignedElements({ flatten: true })\n .filter(\n (el): el is HTMLElement =>\n el instanceof HTMLElement &&\n !el.matches(SEPARATOR_SELECTOR) &&\n !el.hasAttribute('disabled') &&\n el.getAttribute('aria-disabled') !== 'true' &&\n !el.hidden,\n );\n }\n\n private __handleSlotChange = () => {\n this.roving.sync();\n };\n\n // ── Render\n\n override render() {\n const floating = this.variant === 'floating';\n const cssClasses = {\n toolbar: true,\n [`variant-${this.variant}`]: true,\n [`orientation-${this.orientation}`]: true,\n elevated: floating && this.elevated,\n };\n\n return html`\n <div\n class=${classMap(cssClasses)}\n @keydown=${this.roving.handleKeyDown}\n @focusin=${this.roving.handleFocusIn}\n >\n ${floating\n ? html`<wc-elevation class=\"elevation\"></wc-elevation>`\n : nothing}\n <div class=\"background\"></div>\n <div class=\"toolbar-content\">\n <slot @slotchange=${this.__handleSlotChange}></slot>\n </div>\n </div>\n `;\n }\n}\n"],"names":["LitElement","html","classMap","nothing","styles","colorStyles","property"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA;AACA,MAAM,kBAAkB,GAAG,oCAAoC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DG;AAEI,IAAM,OAAO,GAAb,MAAM,OAAQ,SAAQA,GAAU,CAAA;AAAhC,IAAA,WAAA,GAAA;;;AAML;;;;AAIG;QAEH,IAAA,CAAA,OAAO,GAAwB,UAAU;AAEzC;;;AAGG;QAEH,IAAA,CAAA,WAAW,GAA8B,YAAY;AAErD;;AAEG;QAEH,IAAA,CAAA,QAAQ,GAAY,KAAK;;;AAKR,QAAA,IAAA,CAAA,MAAM,GAAG,IAAI,qBAAqB,CAAC,IAAI,EAAE;AACxD,YAAA,KAAK,EAAE,MAAM,IAAI,CAAC,UAAU,EAAE;AAC9B,YAAA,WAAW,EAAE,MAAM,IAAI,CAAC,WAAW;AACpC,SAAA,CAAC;QAkCM,IAAA,CAAA,kBAAkB,GAAG,MAAK;AAChC,YAAA,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE;AACpB,QAAA,CAAC;IA6BH;;IA7DW,iBAAiB,GAAA;QACxB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AAC,aAAa;;UAElC;cACED,CAAI,CAAA,CAAA,+CAAA;AACN,cAAEE,CAAO;;;AAGW,4BAAA,EAAA,IAAI,CAAC,kBAAkB,CAAA;;;KAGhD;IACH;;AAhGA;AACO,OAAA,CAAA,MAAM,GAAG,CAACC,UAAM,EAAEC,QAAW,CAAC;AAUrC,UAAA,CAAA;IADCC,CAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE;AACC,CAAA,EAAA,OAAA,CAAA,SAAA,EAAA,SAAA,EAAA,MAAA,CAAA;AAO1C,UAAA,CAAA;IADCA,CAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE;AACa,CAAA,EAAA,OAAA,CAAA,SAAA,EAAA,aAAA,EAAA,MAAA,CAAA;AAMtD,UAAA,CAAA;IADCA,CAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE;AAChB,CAAA,EAAA,OAAA,CAAA,SAAA,EAAA,UAAA,EAAA,MAAA,CAAA;AAzBf,OAAO,GAAA,UAAA,CAAA;IADnB;AACY,CAAA,EAAA,OAAO,CAkGnB;;;;"}
|
|
1
|
+
{"version":3,"file":"toolbar.js","sources":["../../src/toolbar/toolbar.ts"],"sourcesContent":["import { LitElement, html, nothing } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport IndividualComponent from '@/IndividualComponent.js';\nimport { RovingFocusController } from '@/__internal/controllers/roving-focus-controller.js';\nimport styles from './toolbar.scss';\nimport colorStyles from './toolbar-colors.scss';\n\n/** Slotted elements that separate groups and never take focus. */\nconst SEPARATOR_SELECTOR = 'wc-divider, hr, [role=\"separator\"]';\n\n/**\n * @label Toolbar\n * @tag wc-toolbar\n * @rawTag toolbar\n *\n * @summary A group of related actions, such as editor formatting controls.\n * @overview\n * <p>The toolbar groups related actions into one control. The <code>floating</code> variant\n * (default) is an elevated pill that sits over content, such as a canvas or a selection. The\n * <code>flat</code> variant has no container of its own, for embedding in existing chrome like a\n * card or editor header. Both variants lay their actions out horizontally or vertically.</p>\n *\n * <p>Render actions directly as children. Use a <code>wc-divider</code> to separate groups of\n * actions; in a horizontal toolbar give it <code>orientation=\"vertical\"</code>.</p>\n *\n * <p>The toolbar follows the WAI-ARIA toolbar pattern: it is a single tab stop, and the arrow\n * keys along its orientation move focus between actions (Home and End jump to the first and last).\n * Disabled actions and dividers are skipped, and when the action that holds the tab stop becomes\n * disabled or hidden, the next enabled action (else the previous one) takes it over. Give the\n * toolbar an <code>aria-label</code>.</p>\n *\n * @cssprop --toolbar-container-color - Background color of the toolbar.\n * @cssprop --toolbar-container-shape - Border radius of the floating toolbar.\n * @cssprop --toolbar-padding - Padding of the floating toolbar.\n * @cssprop --toolbar-gap - Gap between toolbar actions.\n * @cssprop --toolbar-icon-color - Color of icons inside the toolbar.\n * @cssprop --toolbar-content-color - Color of text inside the toolbar.\n * @cssprop --toolbar-wrap - `wrap` lets actions flow onto more lines when the toolbar is narrow. Defaults to `nowrap`.\n *\n * @example\n * ```html\n * <!-- Floating toolbar -->\n * <wc-toolbar aria-label=\"Formatting\">\n * <wc-icon-button variant=\"text\" color=\"surface\" aria-label=\"Undo\"><wc-icon name=\"undo\"></wc-icon></wc-icon-button>\n * <wc-icon-button variant=\"text\" color=\"surface\" aria-label=\"Redo\"><wc-icon name=\"redo\"></wc-icon></wc-icon-button>\n * <wc-divider orientation=\"vertical\"></wc-divider>\n * <wc-icon-button variant=\"tonal\" aria-label=\"Bold\"><wc-icon name=\"format_bold\"></wc-icon></wc-icon-button>\n * <wc-icon-button variant=\"text\" color=\"surface\" aria-label=\"Italic\"><wc-icon name=\"format_italic\"></wc-icon></wc-icon-button>\n * </wc-toolbar>\n * ```\n *\n * @example\n * ```html\n * <!-- Vertical floating toolbar -->\n * <wc-toolbar orientation=\"vertical\" aria-label=\"Tools\">\n * <wc-icon-button variant=\"tonal\" aria-label=\"Select\"><wc-icon name=\"arrow_selector_tool\"></wc-icon></wc-icon-button>\n * <wc-icon-button variant=\"text\" color=\"surface\" aria-label=\"Draw\"><wc-icon name=\"draw\"></wc-icon></wc-icon-button>\n * <wc-icon-button variant=\"text\" color=\"surface\" aria-label=\"Text\"><wc-icon name=\"text_fields\"></wc-icon></wc-icon-button>\n * </wc-toolbar>\n * ```\n *\n * @example\n * ```html\n * <!-- Flat toolbar inside existing chrome -->\n * <wc-toolbar variant=\"flat\" aria-label=\"Row actions\">\n * <wc-icon-button variant=\"text\" color=\"surface\" aria-label=\"Edit\"><wc-icon name=\"edit\"></wc-icon></wc-icon-button>\n * <wc-icon-button variant=\"text\" color=\"surface\" aria-label=\"Delete\"><wc-icon name=\"delete\"></wc-icon></wc-icon-button>\n * </wc-toolbar>\n * ```\n * @tags display\n */\n@IndividualComponent\nexport class Toolbar extends LitElement {\n // ── Static\n static styles = [styles, colorStyles];\n\n // ── Properties\n\n /**\n * Visual variant of the toolbar.\n * - `\"floating\"`: An elevated pill that floats over content (default).\n * - `\"flat\"`: No container, fill or elevation; for embedding in existing chrome.\n */\n @property({ type: String, reflect: true })\n variant: 'floating' | 'flat' = 'floating';\n\n /**\n * Orientation of the toolbar. It sets the layout direction and the arrow keys that move focus\n * (Left/Right for horizontal, Up/Down for vertical).\n */\n @property({ type: String, reflect: true })\n orientation: 'horizontal' | 'vertical' = 'horizontal';\n\n /**\n * Raises the floating toolbar to a higher elevation. Has no effect on the flat variant.\n */\n @property({ type: Boolean, reflect: true })\n elevated: boolean = false;\n\n // ── Private fields\n\n /** The toolbar's single tab stop, moved with the arrow keys along its orientation. */\n private readonly roving = new RovingFocusController(this, {\n items: () => this.__getItems(),\n orientation: () => this.orientation,\n });\n\n /**\n * Re-applies the tab stop when an action becomes disabled, aria-disabled or hidden, so it moves\n * to the next enabled action instead of leaving the toolbar out of the Tab order.\n */\n private readonly __actionStateObserver = new MutationObserver(() => {\n this.roving.sync();\n });\n\n // ── Lifecycle\n\n override connectedCallback() {\n super.connectedCallback();\n // The role lives on the host so the host's aria-label names the toolbar.\n this.setAttribute('role', 'toolbar');\n this.__actionStateObserver.observe(this, {\n subtree: true,\n attributes: true,\n attributeFilter: ['disabled', 'aria-disabled', 'hidden'],\n });\n }\n\n override disconnectedCallback() {\n super.disconnectedCallback();\n this.__actionStateObserver.disconnect();\n }\n\n override updated(changed: Map<string, unknown>) {\n if (changed.has('orientation')) {\n this.setAttribute('aria-orientation', this.orientation);\n }\n }\n\n // ── Private methods\n\n /**\n * The actions, in slot order. Disabled and hidden ones are included: the roving controller skips\n * them, takes the tab stop off them and hands it to the next enabled action.\n */\n private __getItems(): HTMLElement[] {\n const slot = this.shadowRoot?.querySelector('slot');\n if (!slot) return [];\n return slot\n .assignedElements({ flatten: true })\n .filter(\n (el): el is HTMLElement =>\n el instanceof HTMLElement && !el.matches(SEPARATOR_SELECTOR),\n );\n }\n\n private __handleSlotChange = () => {\n this.roving.sync();\n };\n\n // ── Render\n\n override render() {\n const floating = this.variant === 'floating';\n const cssClasses = {\n toolbar: true,\n [`variant-${this.variant}`]: true,\n [`orientation-${this.orientation}`]: true,\n elevated: floating && this.elevated,\n };\n\n return html`\n <div\n class=${classMap(cssClasses)}\n @keydown=${this.roving.handleKeyDown}\n @focusin=${this.roving.handleFocusIn}\n >\n ${floating\n ? html`<wc-elevation class=\"elevation\"></wc-elevation>`\n : nothing}\n <div class=\"background\"></div>\n <div class=\"toolbar-content\">\n <slot @slotchange=${this.__handleSlotChange}></slot>\n </div>\n </div>\n `;\n }\n}\n"],"names":["LitElement","html","classMap","nothing","styles","colorStyles","property"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA;AACA,MAAM,kBAAkB,GAAG,oCAAoC;AAE/D;;;;;;;;;;;;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AAO,EAAE,IAAI,EAAE;AACC,CAAA,EAAA,OAAA,CAAA,SAAA,EAAA,SAAA,EAAA,MAAA,CAAA;AAO1C,UAAA,CAAA;IADCA,CAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE;AACa,CAAA,EAAA,OAAA,CAAA,SAAA,EAAA,aAAA,EAAA,MAAA,CAAA;AAMtD,UAAA,CAAA;IADCA,CAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE;AAChB,CAAA,EAAA,OAAA,CAAA,SAAA,EAAA,UAAA,EAAA,MAAA,CAAA;AAzBf,OAAO,GAAA,UAAA,CAAA;IADnB;AACY,CAAA,EAAA,OAAO,CAmHnB;;;;"}
|
package/dist/tree.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { i, _ as __decorate, I as IndividualComponent, a as i$1, b } from './IndividualComponent-BK7XZjE2.js';
|
|
2
2
|
import { n } from './property-B2TG3KEE.js';
|
|
3
|
-
import { R as RovingFocusController } from './roving-focus-controller-
|
|
3
|
+
import { R as RovingFocusController } from './roving-focus-controller-YtNbxH95.js';
|
|
4
4
|
import { TreeItem, isTreeItem } from './tree-item.js';
|
|
5
5
|
import './state-BCeDVCI9.js';
|
|
6
6
|
import './query-CHb9Ft_d.js';
|