@material/web 2.2.1-nightly.c27bdee.0 → 2.2.1-nightly.d69f2f2.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/button/elevated-button.js +2 -1
- package/button/elevated-button.js.map +1 -1
- package/button/filled-button.js +2 -1
- package/button/filled-button.js.map +1 -1
- package/button/filled-tonal-button.js +2 -1
- package/button/filled-tonal-button.js.map +1 -1
- package/button/internal/button.js.map +1 -1
- package/button/outlined-button.js +2 -1
- package/button/outlined-button.js.map +1 -1
- package/button/text-button.js +2 -1
- package/button/text-button.js.map +1 -1
- package/checkbox/checkbox.js +2 -1
- package/checkbox/checkbox.js.map +1 -1
- package/checkbox/internal/checkbox.d.ts +1 -0
- package/checkbox/internal/checkbox.js.map +1 -1
- package/chips/assist-chip.js +2 -1
- package/chips/assist-chip.js.map +1 -1
- package/chips/chip-set.js +2 -1
- package/chips/chip-set.js.map +1 -1
- package/chips/filter-chip.js +2 -1
- package/chips/filter-chip.js.map +1 -1
- package/chips/harness.js.map +1 -1
- package/chips/input-chip.js +2 -1
- package/chips/input-chip.js.map +1 -1
- package/chips/internal/assist-chip.js.map +1 -1
- package/chips/internal/chip-set.js.map +1 -1
- package/chips/internal/chip.d.ts +1 -0
- package/chips/internal/chip.js.map +1 -1
- package/chips/internal/filter-chip.js.map +1 -1
- package/chips/internal/input-chip.js.map +1 -1
- package/chips/internal/multi-action-chip.js.map +1 -1
- package/chips/internal/trailing-icons.js.map +1 -1
- package/chips/suggestion-chip.js +2 -1
- package/chips/suggestion-chip.js.map +1 -1
- package/dialog/dialog.js +2 -1
- package/dialog/dialog.js.map +1 -1
- package/dialog/internal/dialog.js.map +1 -1
- package/divider/divider.js +2 -1
- package/divider/divider.js.map +1 -1
- package/elevation/elevation.js +2 -1
- package/elevation/elevation.js.map +1 -1
- package/fab/branded-fab.js +2 -1
- package/fab/branded-fab.js.map +1 -1
- package/fab/fab.js +2 -1
- package/fab/fab.js.map +1 -1
- package/field/filled-field.js +2 -1
- package/field/filled-field.js.map +1 -1
- package/field/internal/field.js.map +1 -1
- package/field/outlined-field.js +2 -1
- package/field/outlined-field.js.map +1 -1
- package/focus/internal/focus-ring.js.map +1 -1
- package/focus/md-focus-ring.js +2 -1
- package/focus/md-focus-ring.js.map +1 -1
- package/icon/icon.js +2 -1
- package/icon/icon.js.map +1 -1
- package/icon/internal/icon.js.map +1 -1
- package/iconbutton/filled-icon-button.js +2 -1
- package/iconbutton/filled-icon-button.js.map +1 -1
- package/iconbutton/filled-tonal-icon-button.js +2 -1
- package/iconbutton/filled-tonal-icon-button.js.map +1 -1
- package/iconbutton/harness.js.map +1 -1
- package/iconbutton/icon-button.js +2 -1
- package/iconbutton/icon-button.js.map +1 -1
- package/iconbutton/internal/_shared.scss +2 -0
- package/iconbutton/internal/icon-button.js +4 -3
- package/iconbutton/internal/icon-button.js.map +1 -1
- package/iconbutton/internal/shared-styles.css +1 -1
- package/iconbutton/internal/shared-styles.css.map +1 -1
- package/iconbutton/internal/shared-styles.js +1 -1
- package/iconbutton/internal/shared-styles.js.map +1 -1
- package/iconbutton/outlined-icon-button.js +2 -1
- package/iconbutton/outlined-icon-button.js.map +1 -1
- package/internal/aria/aria.d.ts +1 -1
- package/internal/aria/delegate.js.map +1 -1
- package/internal/controller/attachable-controller.js.map +1 -1
- package/internal/controller/form-submitter.js.map +1 -1
- package/internal/events/dispatch-hooks.js.map +1 -1
- package/internal/events/form-label-activation.js.map +1 -1
- package/internal/events/redispatch-event.js.map +1 -1
- package/internal/motion/animation.js.map +1 -1
- package/labs/badge/badge.js +2 -1
- package/labs/badge/badge.js.map +1 -1
- package/labs/behaviors/constraint-validation.js.map +1 -1
- package/labs/behaviors/custom-state-set.d.ts +107 -0
- package/labs/behaviors/custom-state-set.js +121 -0
- package/labs/behaviors/custom-state-set.js.map +1 -0
- package/labs/behaviors/element-internals.js.map +1 -1
- package/labs/behaviors/focusable.js.map +1 -1
- package/labs/behaviors/form-associated.js.map +1 -1
- package/labs/behaviors/on-report-validity.js.map +1 -1
- package/labs/behaviors/validators/checkbox-validator.js.map +1 -1
- package/labs/behaviors/validators/radio-validator.js.map +1 -1
- package/labs/behaviors/validators/select-validator.js.map +1 -1
- package/labs/behaviors/validators/text-field-validator.js.map +1 -1
- package/labs/behaviors/validators/validator.js.map +1 -1
- package/labs/card/elevated-card.js +2 -1
- package/labs/card/elevated-card.js.map +1 -1
- package/labs/card/filled-card.js +2 -1
- package/labs/card/filled-card.js.map +1 -1
- package/labs/card/outlined-card.js +2 -1
- package/labs/card/outlined-card.js.map +1 -1
- package/labs/item/internal/item.js.map +1 -1
- package/labs/item/item.js +2 -1
- package/labs/item/item.js.map +1 -1
- package/labs/navigationbar/internal/navigation-bar.js.map +1 -1
- package/labs/navigationbar/navigation-bar.js +2 -1
- package/labs/navigationbar/navigation-bar.js.map +1 -1
- package/labs/navigationdrawer/internal/navigation-drawer-modal.js.map +1 -1
- package/labs/navigationdrawer/internal/navigation-drawer.js.map +1 -1
- package/labs/navigationdrawer/navigation-drawer-modal.js +2 -1
- package/labs/navigationdrawer/navigation-drawer-modal.js.map +1 -1
- package/labs/navigationdrawer/navigation-drawer.js +2 -1
- package/labs/navigationdrawer/navigation-drawer.js.map +1 -1
- package/labs/navigationtab/internal/navigation-tab.js.map +1 -1
- package/labs/navigationtab/navigation-tab.js +2 -1
- package/labs/navigationtab/navigation-tab.js.map +1 -1
- package/labs/segmentedbutton/internal/segmented-button.js.map +1 -1
- package/labs/segmentedbutton/outlined-segmented-button.js +2 -1
- package/labs/segmentedbutton/outlined-segmented-button.js.map +1 -1
- package/labs/segmentedbuttonset/internal/segmented-button-set.js.map +1 -1
- package/labs/segmentedbuttonset/outlined-segmented-button-set.js +2 -1
- package/labs/segmentedbuttonset/outlined-segmented-button-set.js.map +1 -1
- package/list/internal/list-controller.js.map +1 -1
- package/list/internal/list-navigation-helpers.js.map +1 -1
- package/list/internal/list.js.map +1 -1
- package/list/internal/listitem/list-item.d.ts +1 -0
- package/list/internal/listitem/list-item.js.map +1 -1
- package/list/list-item.js +2 -1
- package/list/list-item.js.map +1 -1
- package/list/list.js +2 -1
- package/list/list.js.map +1 -1
- package/menu/harness.js.map +1 -1
- package/menu/internal/controllers/menuItemController.js.map +1 -1
- package/menu/internal/controllers/surfacePositionController.js.map +1 -1
- package/menu/internal/controllers/typeaheadController.js.map +1 -1
- package/menu/internal/menu.js.map +1 -1
- package/menu/internal/menuitem/menu-item.d.ts +1 -0
- package/menu/internal/menuitem/menu-item.js.map +1 -1
- package/menu/internal/submenu/sub-menu.js.map +1 -1
- package/menu/menu-item.js +2 -1
- package/menu/menu-item.js.map +1 -1
- package/menu/menu.js +2 -1
- package/menu/menu.js.map +1 -1
- package/menu/sub-menu.js +2 -1
- package/menu/sub-menu.js.map +1 -1
- package/migrations/v2/query-selector-aria.js.map +1 -1
- package/package.json +5 -3
- package/progress/circular-progress.js +2 -1
- package/progress/circular-progress.js.map +1 -1
- package/progress/internal/circular-progress.js.map +1 -1
- package/progress/linear-progress.js +2 -1
- package/progress/linear-progress.js.map +1 -1
- package/radio/internal/radio.js.map +1 -1
- package/radio/internal/single-selection-controller.js.map +1 -1
- package/radio/radio.js +2 -1
- package/radio/radio.js.map +1 -1
- package/ripple/internal/ripple.js.map +1 -1
- package/ripple/ripple.js +2 -1
- package/ripple/ripple.js.map +1 -1
- package/select/filled-select.js +2 -1
- package/select/filled-select.js.map +1 -1
- package/select/harness.js.map +1 -1
- package/select/internal/select.d.ts +1 -0
- package/select/internal/select.js +2 -1
- package/select/internal/select.js.map +1 -1
- package/select/internal/selectoption/select-option.d.ts +1 -0
- package/select/internal/selectoption/selectOptionController.js.map +1 -1
- package/select/internal/shared.js.map +1 -1
- package/select/outlined-select.js +2 -1
- package/select/outlined-select.js.map +1 -1
- package/select/select-option.js +2 -1
- package/select/select-option.js.map +1 -1
- package/slider/harness.js.map +1 -1
- package/slider/internal/slider.js.map +1 -1
- package/slider/slider.js +2 -1
- package/slider/slider.js.map +1 -1
- package/switch/internal/switch.js.map +1 -1
- package/switch/switch.js +2 -1
- package/switch/switch.js.map +1 -1
- package/tabs/harness.js.map +1 -1
- package/tabs/internal/tab.js.map +1 -1
- package/tabs/internal/tabs.js.map +1 -1
- package/tabs/primary-tab.js +2 -1
- package/tabs/primary-tab.js.map +1 -1
- package/tabs/secondary-tab.js +2 -1
- package/tabs/secondary-tab.js.map +1 -1
- package/tabs/tabs.js +2 -1
- package/tabs/tabs.js.map +1 -1
- package/testing/harness.js.map +1 -1
- package/testing/transform-pseudo-classes.js.map +1 -1
- package/textfield/filled-text-field.js +2 -1
- package/textfield/filled-text-field.js.map +1 -1
- package/textfield/harness.js.map +1 -1
- package/textfield/internal/text-field.js.map +1 -1
- package/textfield/outlined-text-field.js +2 -1
- package/textfield/outlined-text-field.js.map +1 -1
|
@@ -14,10 +14,11 @@ import { styles as sharedStyles } from './internal/shared-styles.js';
|
|
|
14
14
|
* @final
|
|
15
15
|
* @suppress {visibility}
|
|
16
16
|
*/
|
|
17
|
-
|
|
17
|
+
let MdOutlinedSegmentedButtonSet = class MdOutlinedSegmentedButtonSet extends OutlinedSegmentedButtonSet {
|
|
18
18
|
};
|
|
19
19
|
MdOutlinedSegmentedButtonSet.styles = [sharedStyles, outlinedStyles];
|
|
20
20
|
MdOutlinedSegmentedButtonSet = __decorate([
|
|
21
21
|
customElement('md-outlined-segmented-button-set')
|
|
22
22
|
], MdOutlinedSegmentedButtonSet);
|
|
23
|
+
export { MdOutlinedSegmentedButtonSet };
|
|
23
24
|
//# sourceMappingURL=outlined-segmented-button-set.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outlined-segmented-button-set.js","sourceRoot":"","sources":["outlined-segmented-button-set.ts"],"names":[],"mappings":"AAAA;;;;GAIG;;AAGH,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAC,0BAA0B,EAAC,MAAM,6CAA6C,CAAC;AACvF,OAAO,EAAC,MAAM,IAAI,cAAc,EAAC,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAC,MAAM,IAAI,YAAY,EAAC,MAAM,6BAA6B,CAAC;AAQnE;;;;;GAKG;AAEI,
|
|
1
|
+
{"version":3,"file":"outlined-segmented-button-set.js","sourceRoot":"","sources":["outlined-segmented-button-set.ts"],"names":[],"mappings":"AAAA;;;;GAIG;;AAGH,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAC,0BAA0B,EAAC,MAAM,6CAA6C,CAAC;AACvF,OAAO,EAAC,MAAM,IAAI,cAAc,EAAC,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAC,MAAM,IAAI,YAAY,EAAC,MAAM,6BAA6B,CAAC;AAQnE;;;;;GAKG;AAEI,IAAM,4BAA4B,GAAlC,MAAM,4BAA6B,SAAQ,0BAA0B;;AAC1D,mCAAM,GAAwB,CAAC,YAAY,EAAE,cAAc,CAAC,AAAtD,CAAuD;AADlE,4BAA4B;IADxC,aAAa,CAAC,kCAAkC,CAAC;GACrC,4BAA4B,CAExC","sourcesContent":["/**\n * @license\n * Copyright 2022 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {CSSResultOrNative} from 'lit';\nimport {customElement} from 'lit/decorators.js';\n\nimport {OutlinedSegmentedButtonSet} from './internal/outlined-segmented-button-set.js';\nimport {styles as outlinedStyles} from './internal/outlined-styles.js';\nimport {styles as sharedStyles} from './internal/shared-styles.js';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'md-outlined-segmented-button-set': MdOutlinedSegmentedButtonSet;\n }\n}\n\n/**\n * MdOutlinedSegmentedButtonSet is the custom element for the Material\n * Design outlined segmented button set component.\n * @final\n * @suppress {visibility}\n */\n@customElement('md-outlined-segmented-button-set')\nexport class MdOutlinedSegmentedButtonSet extends OutlinedSegmentedButtonSet {\n static override styles: CSSResultOrNative[] = [sharedStyles, outlinedStyles];\n}\n"]}
|
|
@@ -1 +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,GAAG,IAAI,CAAC,KAAK,CAAC;QACzB,MAAM,gBAAgB,GAAG,aAAa,CAAC,KAAK,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QAClE,IAAI,gBAAgB,EAAE;YACpB,gBAAgB,CAAC,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;SACrC;QACD,OAAO,oBAAoB,CACzB,KAAK,EACL,gBAAgB,EAChB,IAAI,CAAC,aAAa,EAClB,IAAI,CAAC,cAAc,EAAE,CACtB,CAAC;IACJ,CAAC;CA4DF","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n activateFirstItem,\n activateLastItem,\n activateNextItem,\n activatePreviousItem,\n getActiveItem,\n getFirstActivatableItem,\n ListItem,\n} from './list-navigation-helpers.js';\n\n// TODO: move this file to List and make List use this\n\n/**\n * Default keys that trigger navigation.\n */\n// tslint:disable:enforce-name-casing Following Enum style\nexport const NavigableKeys = {\n ArrowDown: 'ArrowDown',\n ArrowLeft: 'ArrowLeft',\n ArrowUp: 'ArrowUp',\n ArrowRight: 'ArrowRight',\n Home: 'Home',\n End: 'End',\n} as const;\n// tslint:enable:enforce-name-casing\n\n/**\n * Default set of navigable keys.\n */\nexport type NavigableKeys = (typeof NavigableKeys)[keyof typeof NavigableKeys];\n\n/**\n * The configuration object to customize the behavior of the List Controller\n */\nexport interface ListControllerConfig<Item extends ListItem> {\n /**\n * A function that determines whether or not the given element is an Item\n */\n isItem: (item: HTMLElement) => item is Item;\n /**\n * A function that returns an array of elements to consider as items. For\n * example, all the slotted elements.\n */\n getPossibleItems: () => HTMLElement[];\n /**\n * A function that returns whether or not the list is in an RTL context.\n */\n isRtl: () => boolean;\n /**\n * Deactivates an item such as setting the tabindex to -1 and or sets selected\n * to false.\n */\n deactivateItem: (item: Item) => void;\n /**\n * Activates an item such as setting the tabindex to 1 and or sets selected to\n * true (but does not focus).\n */\n activateItem: (item: Item) => void;\n /**\n * Whether or not the key should be handled by the list for navigation.\n */\n isNavigableKey: (key: string) => boolean;\n /**\n * Whether or not the item can be activated. Defaults to items that are not\n * disabled.\n */\n isActivatable?: (item: Item) => boolean;\n /**\n * Whether or not navigating past the end of the list wraps to the beginning\n * and vice versa. Defaults to true.\n */\n wrapNavigation?: () => boolean;\n}\n\n/**\n * A controller that handles list keyboard navigation and item management.\n */\nexport class ListController<Item extends ListItem> {\n isItem: (item: HTMLElement) => item is Item;\n private readonly getPossibleItems: () => HTMLElement[];\n private readonly isRtl: () => boolean;\n private readonly deactivateItem: (item: Item) => void;\n private readonly activateItem: (item: Item) => void;\n private readonly isNavigableKey: (key: string) => boolean;\n private readonly isActivatable?: (item: Item) => boolean;\n private readonly wrapNavigation: () => boolean;\n\n constructor(config: ListControllerConfig<Item>) {\n const {\n isItem,\n getPossibleItems,\n isRtl,\n deactivateItem,\n activateItem,\n isNavigableKey,\n isActivatable,\n wrapNavigation,\n } = config;\n this.isItem = isItem;\n this.getPossibleItems = getPossibleItems;\n this.isRtl = isRtl;\n this.deactivateItem = deactivateItem;\n this.activateItem = activateItem;\n this.isNavigableKey = isNavigableKey;\n this.isActivatable = isActivatable;\n this.wrapNavigation = wrapNavigation ?? (() => true);\n }\n\n /**\n * The items being managed by the list. Additionally, attempts to see if the\n * object has a sub-item in the `.item` property.\n */\n get items(): Item[] {\n const maybeItems = this.getPossibleItems();\n const items: Item[] = [];\n\n for (const itemOrParent of maybeItems) {\n const isItem = this.isItem(itemOrParent);\n // if the item is a list item, add it to the list of items\n if (isItem) {\n items.push(itemOrParent);\n continue;\n }\n\n // If the item exposes an `item` property check if it is a list item.\n const subItem = (itemOrParent as HTMLElement & {item?: Item}).item;\n if (subItem && this.isItem(subItem)) {\n items.push(subItem);\n }\n }\n\n return items;\n }\n\n /**\n * Handles keyboard navigation. Should be bound to the node that will act as\n * the List.\n */\n handleKeydown = (event: KeyboardEvent) => {\n const key = event.key;\n if (event.defaultPrevented || !this.isNavigableKey(key)) {\n return;\n }\n // do not use this.items directly in upcoming calculations so we don't\n // re-query the DOM unnecessarily\n const items = this.items;\n\n if (!items.length) {\n return;\n }\n\n const activeItemRecord = getActiveItem(items, this.isActivatable);\n\n event.preventDefault();\n\n const isRtl = this.isRtl();\n const inlinePrevious = isRtl\n ? NavigableKeys.ArrowRight\n : NavigableKeys.ArrowLeft;\n const inlineNext = isRtl\n ? NavigableKeys.ArrowLeft\n : NavigableKeys.ArrowRight;\n\n let nextActiveItem: Item | null = null;\n switch (key) {\n // Activate the next item\n case NavigableKeys.ArrowDown:\n case inlineNext:\n nextActiveItem = activateNextItem(\n items,\n activeItemRecord,\n this.isActivatable,\n this.wrapNavigation(),\n );\n break;\n\n // Activate the previous item\n case NavigableKeys.ArrowUp:\n case inlinePrevious:\n nextActiveItem = activatePreviousItem(\n items,\n activeItemRecord,\n this.isActivatable,\n this.wrapNavigation(),\n );\n break;\n\n // Activate the first item\n case NavigableKeys.Home:\n nextActiveItem = activateFirstItem(items, this.isActivatable);\n break;\n\n // Activate the last item\n case NavigableKeys.End:\n nextActiveItem = activateLastItem(items, this.isActivatable);\n break;\n\n default:\n break;\n }\n\n if (\n nextActiveItem &&\n activeItemRecord &&\n activeItemRecord.item !== nextActiveItem\n ) {\n // If a new item was activated, remove the tabindex of the previous\n // activated item.\n activeItemRecord.item.tabIndex = -1;\n }\n };\n\n /**\n * Activates the next item in the list. If at the end of the list, the first\n * item will be activated.\n *\n * @return The activated list item or `null` if there are no items.\n */\n activateNextItem(): Item | null {\n const items = this.items;\n const activeItemRecord = getActiveItem(items, this.isActivatable);\n if (activeItemRecord) {\n activeItemRecord.item.tabIndex = -1;\n }\n return activateNextItem(\n items,\n activeItemRecord,\n this.isActivatable,\n this.wrapNavigation(),\n );\n }\n\n /**\n * Activates the previous item in the list. If at the start of the list, the\n * last item will be activated.\n *\n * @return The activated list item or `null` if there are no items.\n */\n activatePreviousItem(): Item | null {\n const items = this.items;\n const activeItemRecord = getActiveItem(items, this.isActivatable);\n if (activeItemRecord) {\n activeItemRecord.item.tabIndex = -1;\n }\n return activatePreviousItem(\n items,\n activeItemRecord,\n this.isActivatable,\n this.wrapNavigation(),\n );\n }\n\n /**\n * Listener to be bound to the `deactivate-items` item event.\n */\n onDeactivateItems = () => {\n const items = this.items;\n\n for (const item of items) {\n this.deactivateItem(item);\n }\n };\n\n /**\n * Listener to be bound to the `request-activation` item event..\n */\n onRequestActivation = (event: Event) => {\n this.onDeactivateItems();\n const target = event.target as Item;\n this.activateItem(target);\n target.focus();\n };\n\n /**\n * Listener to be bound to the `slotchange` event for the slot that renders\n * the items.\n */\n onSlotchange = () => {\n const items = this.items;\n // Whether we have encountered an item that has been activated\n let encounteredActivated = false;\n\n for (const item of items) {\n const isActivated = !item.disabled && item.tabIndex > -1;\n\n if (isActivated && !encounteredActivated) {\n encounteredActivated = true;\n item.tabIndex = 0;\n continue;\n }\n\n // Deactivate the rest including disabled\n item.tabIndex = -1;\n }\n\n if (encounteredActivated) {\n return;\n }\n\n const firstActivatableItem = getFirstActivatableItem(\n items,\n this.isActivatable,\n );\n\n if (!firstActivatableItem) {\n return;\n }\n\n firstActivatableItem.tabIndex = 0;\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"list-controller.js","sourceRoot":"","sources":["list-controller.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,EACpB,aAAa,EACb,uBAAuB,GAExB,MAAM,8BAA8B,CAAC;AAEtC,sDAAsD;AAEtD;;GAEG;AACH,0DAA0D;AAC1D,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,SAAS,EAAE,WAAW;IACtB,SAAS,EAAE,WAAW;IACtB,OAAO,EAAE,SAAS;IAClB,UAAU,EAAE,YAAY;IACxB,IAAI,EAAE,MAAM;IACZ,GAAG,EAAE,KAAK;CACF,CAAC;AAmDX;;GAEG;AACH,MAAM,OAAO,cAAc;IAUzB,YAAY,MAAkC;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cesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n activateFirstItem,\n activateLastItem,\n activateNextItem,\n activatePreviousItem,\n getActiveItem,\n getFirstActivatableItem,\n ListItem,\n} from './list-navigation-helpers.js';\n\n// TODO: move this file to List and make List use this\n\n/**\n * Default keys that trigger navigation.\n */\n// tslint:disable:enforce-name-casing Following Enum style\nexport const NavigableKeys = {\n ArrowDown: 'ArrowDown',\n ArrowLeft: 'ArrowLeft',\n ArrowUp: 'ArrowUp',\n ArrowRight: 'ArrowRight',\n Home: 'Home',\n End: 'End',\n} as const;\n// tslint:enable:enforce-name-casing\n\n/**\n * Default set of navigable keys.\n */\nexport type NavigableKeys = (typeof NavigableKeys)[keyof typeof NavigableKeys];\n\n/**\n * The configuration object to customize the behavior of the List Controller\n */\nexport interface ListControllerConfig<Item extends ListItem> {\n /**\n * A function that determines whether or not the given element is an Item\n */\n isItem: (item: HTMLElement) => item is Item;\n /**\n * A function that returns an array of elements to consider as items. For\n * example, all the slotted elements.\n */\n getPossibleItems: () => HTMLElement[];\n /**\n * A function that returns whether or not the list is in an RTL context.\n */\n isRtl: () => boolean;\n /**\n * Deactivates an item such as setting the tabindex to -1 and or sets selected\n * to false.\n */\n deactivateItem: (item: Item) => void;\n /**\n * Activates an item such as setting the tabindex to 1 and or sets selected to\n * true (but does not focus).\n */\n activateItem: (item: Item) => void;\n /**\n * Whether or not the key should be handled by the list for navigation.\n */\n isNavigableKey: (key: string) => boolean;\n /**\n * Whether or not the item can be activated. Defaults to items that are not\n * disabled.\n */\n isActivatable?: (item: Item) => boolean;\n /**\n * Whether or not navigating past the end of the list wraps to the beginning\n * and vice versa. Defaults to true.\n */\n wrapNavigation?: () => boolean;\n}\n\n/**\n * A controller that handles list keyboard navigation and item management.\n */\nexport class ListController<Item extends ListItem> {\n isItem: (item: HTMLElement) => item is Item;\n private readonly getPossibleItems: () => HTMLElement[];\n private readonly isRtl: () => boolean;\n private readonly deactivateItem: (item: Item) => void;\n private readonly activateItem: (item: Item) => void;\n private readonly isNavigableKey: (key: string) => boolean;\n private readonly isActivatable?: (item: Item) => boolean;\n private readonly wrapNavigation: () => boolean;\n\n constructor(config: ListControllerConfig<Item>) {\n const {\n isItem,\n getPossibleItems,\n isRtl,\n deactivateItem,\n activateItem,\n isNavigableKey,\n isActivatable,\n wrapNavigation,\n } = config;\n this.isItem = isItem;\n this.getPossibleItems = getPossibleItems;\n this.isRtl = isRtl;\n this.deactivateItem = deactivateItem;\n this.activateItem = activateItem;\n this.isNavigableKey = isNavigableKey;\n this.isActivatable = isActivatable;\n this.wrapNavigation = wrapNavigation ?? (() => true);\n }\n\n /**\n * The items being managed by the list. Additionally, attempts to see if the\n * object has a sub-item in the `.item` property.\n */\n get items(): Item[] {\n const maybeItems = this.getPossibleItems();\n const items: Item[] = [];\n\n for (const itemOrParent of maybeItems) {\n const isItem = this.isItem(itemOrParent);\n // if the item is a list item, add it to the list of items\n if (isItem) {\n items.push(itemOrParent);\n continue;\n }\n\n // If the item exposes an `item` property check if it is a list item.\n const subItem = (itemOrParent as HTMLElement & {item?: Item}).item;\n if (subItem && this.isItem(subItem)) {\n items.push(subItem);\n }\n }\n\n return items;\n }\n\n /**\n * Handles keyboard navigation. Should be bound to the node that will act as\n * the List.\n */\n handleKeydown = (event: KeyboardEvent) => {\n const key = event.key;\n if (event.defaultPrevented || !this.isNavigableKey(key)) {\n return;\n }\n // do not use this.items directly in upcoming calculations so we don't\n // re-query the DOM unnecessarily\n const items = this.items;\n\n if (!items.length) {\n return;\n }\n\n const activeItemRecord = getActiveItem(items, this.isActivatable);\n\n event.preventDefault();\n\n const isRtl = this.isRtl();\n const inlinePrevious = isRtl\n ? NavigableKeys.ArrowRight\n : NavigableKeys.ArrowLeft;\n const inlineNext = isRtl\n ? NavigableKeys.ArrowLeft\n : NavigableKeys.ArrowRight;\n\n let nextActiveItem: Item | null = null;\n switch (key) {\n // Activate the next item\n case NavigableKeys.ArrowDown:\n case inlineNext:\n nextActiveItem = activateNextItem(\n items,\n activeItemRecord,\n this.isActivatable,\n this.wrapNavigation(),\n );\n break;\n\n // Activate the previous item\n case NavigableKeys.ArrowUp:\n case inlinePrevious:\n nextActiveItem = activatePreviousItem(\n items,\n activeItemRecord,\n this.isActivatable,\n this.wrapNavigation(),\n );\n break;\n\n // Activate the first item\n case NavigableKeys.Home:\n nextActiveItem = activateFirstItem(items, this.isActivatable);\n break;\n\n // Activate the last item\n case NavigableKeys.End:\n nextActiveItem = activateLastItem(items, this.isActivatable);\n break;\n\n default:\n break;\n }\n\n if (\n nextActiveItem &&\n activeItemRecord &&\n activeItemRecord.item !== nextActiveItem\n ) {\n // If a new item was activated, remove the tabindex of the previous\n // activated item.\n activeItemRecord.item.tabIndex = -1;\n }\n };\n\n /**\n * Activates the next item in the list. If at the end of the list, the first\n * item will be activated.\n *\n * @return The activated list item or `null` if there are no items.\n */\n activateNextItem(): Item | null {\n const items = this.items;\n const activeItemRecord = getActiveItem(items, this.isActivatable);\n if (activeItemRecord) {\n activeItemRecord.item.tabIndex = -1;\n }\n return activateNextItem(\n items,\n activeItemRecord,\n this.isActivatable,\n this.wrapNavigation(),\n );\n }\n\n /**\n * Activates the previous item in the list. If at the start of the list, the\n * last item will be activated.\n *\n * @return The activated list item or `null` if there are no items.\n */\n activatePreviousItem(): Item | null {\n const items = this.items;\n const activeItemRecord = getActiveItem(items, this.isActivatable);\n if (activeItemRecord) {\n activeItemRecord.item.tabIndex = -1;\n }\n return activatePreviousItem(\n items,\n activeItemRecord,\n this.isActivatable,\n this.wrapNavigation(),\n );\n }\n\n /**\n * Listener to be bound to the `deactivate-items` item event.\n */\n onDeactivateItems = () => {\n const items = this.items;\n\n for (const item of items) {\n this.deactivateItem(item);\n }\n };\n\n /**\n * Listener to be bound to the `request-activation` item event..\n */\n onRequestActivation = (event: Event) => {\n this.onDeactivateItems();\n const target = event.target as Item;\n this.activateItem(target);\n target.focus();\n };\n\n /**\n * Listener to be bound to the `slotchange` event for the slot that renders\n * the items.\n */\n onSlotchange = () => {\n const items = this.items;\n // Whether we have encountered an item that has been activated\n let encounteredActivated = false;\n\n for (const item of items) {\n const isActivated = !item.disabled && item.tabIndex > -1;\n\n if (isActivated && !encounteredActivated) {\n encounteredActivated = true;\n item.tabIndex = 0;\n continue;\n }\n\n // Deactivate the rest including disabled\n item.tabIndex = -1;\n }\n\n if (encounteredActivated) {\n return;\n }\n\n const firstActivatableItem = getFirstActivatableItem(\n items,\n this.isActivatable,\n );\n\n if (!firstActivatableItem) {\n return;\n }\n\n firstActivatableItem.tabIndex = 0;\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-navigation-helpers.js","sourceRoot":"","sources":["list-navigation-helpers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAeH;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAC/B,KAAa,EACb,gBAAgB,CAAA,iBAAuB,CAAA;IAEvC,yEAAyE;IACzE,yEAAyE;IACzE,UAAU;IACV,MAAM,SAAS,GAAG,uBAAuB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IAChE,IAAI,SAAS,EAAE;QACb,SAAS,CAAC,QAAQ,GAAG,CAAC,CAAC;QACvB,SAAS,CAAC,KAAK,EAAE,CAAC;KACnB;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAC9B,KAAa,EACb,gBAAgB,CAAA,iBAAuB,CAAA;IAEvC,MAAM,QAAQ,GAAG,sBAAsB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IAC9D,IAAI,QAAQ,EAAE;QACZ,QAAQ,CAAC,QAAQ,GAAG,CAAC,CAAC;QACtB,QAAQ,CAAC,KAAK,EAAE,CAAC;KAClB;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,oBAAoB,CAClC,KAAa,EACb,g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AOG;AACH,MAAM,UAAU,4BAA4B;IAC1C,OAAO,IAAI,KAAK,CAAC,oBAAoB,EAAE,EAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAC;AAC1E,CAAC;AASD;;;;;;GAMG;AACH,SAAS,iBAAiB,CAAwB,IAAU;IAC1D,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC;AACxB,CAAC","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nexport interface ListItem extends HTMLElement {\n disabled: boolean;\n}\n\n/**\n * A record that describes a list item in a list with metadata such a reference\n * to the item and its index in the list.\n */\nexport interface ItemRecord<Item extends ListItem> {\n item: Item;\n index: number;\n}\n\n/**\n * Activates the first non-disabled item of a given array of items.\n *\n * @param items {Array<ListItem>} The items from which to activate the\n * first item.\n * @param isActivatable Function to determine if an item can be activated.\n * Defaults to non-disabled items.\n */\nexport function activateFirstItem<Item extends ListItem>(\n items: Item[],\n isActivatable = isItemNotDisabled<Item>,\n) {\n // NOTE: These selector functions are static and not on the instance such\n // that multiple operations can be chained and we do not have to re-query\n // the DOM\n const firstItem = getFirstActivatableItem(items, isActivatable);\n if (firstItem) {\n firstItem.tabIndex = 0;\n firstItem.focus();\n }\n return firstItem;\n}\n\n/**\n * Activates the last non-disabled item of a given array of items.\n *\n * @param items {Array<ListItem>} The items from which to activate the\n * last item.\n * @param isActivatable Function to determine if an item can be activated.\n * Defaults to non-disabled items.\n * @nocollapse\n */\nexport function activateLastItem<Item extends ListItem>(\n items: Item[],\n isActivatable = isItemNotDisabled<Item>,\n) {\n const lastItem = getLastActivatableItem(items, isActivatable);\n if (lastItem) {\n lastItem.tabIndex = 0;\n lastItem.focus();\n }\n return lastItem;\n}\n\n/**\n * Deactivates the currently active item of a given array of items.\n *\n * @param items {Array<ListItem>} The items from which to deactivate the\n * active item.\n * @param isActivatable Function to determine if an item can be activated.\n * Defaults to non-disabled items.\n * @return A record of the deleselcted activated item including the item and\n * the index of the item or `null` if none are deactivated.\n * @nocollapse\n */\nexport function deactivateActiveItem<Item extends ListItem>(\n items: Item[],\n isActivatable = isItemNotDisabled<Item>,\n) {\n const activeItem = getActiveItem(items, isActivatable);\n if (activeItem) {\n activeItem.item.tabIndex = -1;\n }\n return activeItem;\n}\n\n/**\n * Retrieves the first activated item of a given array of items.\n *\n * @param items {Array<ListItem>} The items to search.\n * @param isActivatable Function to determine if an item can be activated.\n * Defaults to non-disabled items.\n * @return A record of the first activated item including the item and the\n * index of the item or `null` if none are activated.\n * @nocollapse\n */\nexport function getActiveItem<Item extends ListItem>(\n items: Item[],\n isActivatable = isItemNotDisabled<Item>,\n) {\n for (let i = 0; i < items.length; i++) {\n const item = items[i];\n if (item.tabIndex === 0 && isActivatable(item)) {\n return {\n item,\n index: i,\n } as ItemRecord<Item>;\n }\n }\n return null;\n}\n\n/**\n * Retrieves the first non-disabled item of a given array of items. This\n * the first item that is not disabled.\n *\n * @param items {Array<ListItem>} The items to search.\n * @param isActivatable Function to determine if an item can be activated.\n * Defaults to non-disabled items.\n * @return The first activatable item or `null` if none are activatable.\n * @nocollapse\n */\nexport function getFirstActivatableItem<Item extends ListItem>(\n items: Item[],\n isActivatable = isItemNotDisabled<Item>,\n) {\n for (const item of items) {\n if (isActivatable(item)) {\n return item;\n }\n }\n\n return null;\n}\n\n/**\n * Retrieves the last non-disabled item of a given array of items.\n *\n * @param items {Array<ListItem>} The items to search.\n * @param isActivatable Function to determine if an item can be activated.\n * Defaults to non-disabled items.\n * @return The last activatable item or `null` if none are activatable.\n * @nocollapse\n */\nexport function getLastActivatableItem<Item extends ListItem>(\n items: Item[],\n isActivatable = isItemNotDisabled<Item>,\n) {\n for (let i = items.length - 1; i >= 0; i--) {\n const item = items[i];\n if (isActivatable(item)) {\n return item;\n }\n }\n\n return null;\n}\n\n/**\n * Retrieves the next non-disabled item of a given array of items.\n *\n * @param items {Array<ListItem>} The items to search.\n * @param index {{index: number}} The index to search from.\n * @param isActivatable Function to determine if an item can be activated.\n * Defaults to non-disabled items.\n * @param wrap If true, then the next item at the end of the list is the first\n * item. Defaults to true.\n * @return The next activatable item or `null` if none are activatable.\n */\nexport function getNextItem<Item extends ListItem>(\n items: Item[],\n index: number,\n isActivatable = isItemNotDisabled<Item>,\n wrap = true,\n) {\n for (let i = 1; i < items.length; i++) {\n const nextIndex = (i + index) % items.length;\n if (nextIndex < index && !wrap) {\n // Return if the index loops back to the beginning and not wrapping.\n return null;\n }\n\n const item = items[nextIndex];\n if (isActivatable(item)) {\n return item;\n }\n }\n\n return items[index] ? items[index] : null;\n}\n\n/**\n * Retrieves the previous non-disabled item of a given array of items.\n *\n * @param items {Array<ListItem>} The items to search.\n * @param index {{index: number}} The index to search from.\n * @param isActivatable Function to determine if an item can be activated.\n * Defaults to non-disabled items.\n * @param wrap If true, then the previous item at the beginning of the list is\n * the last item. Defaults to true.\n * @return The previous activatable item or `null` if none are activatable.\n */\nexport function getPrevItem<Item extends ListItem>(\n items: Item[],\n index: number,\n isActivatable = isItemNotDisabled<Item>,\n wrap = true,\n) {\n for (let i = 1; i < items.length; i++) {\n const prevIndex = (index - i + items.length) % items.length;\n if (prevIndex > index && !wrap) {\n // Return if the index loops back to the end and not wrapping.\n return null;\n }\n\n const item = items[prevIndex];\n\n if (isActivatable(item)) {\n return item;\n }\n }\n\n return items[index] ? items[index] : null;\n}\n\n/**\n * Activates the next item and focuses it. If nothing is currently activated,\n * activates the first item.\n */\nexport function activateNextItem<Item extends ListItem>(\n items: Item[],\n activeItemRecord: null | ItemRecord<Item>,\n isActivatable = isItemNotDisabled<Item>,\n wrap = true,\n): Item | null {\n if (activeItemRecord) {\n const next = getNextItem(\n items,\n activeItemRecord.index,\n isActivatable,\n wrap,\n );\n\n if (next) {\n next.tabIndex = 0;\n next.focus();\n }\n\n return next;\n } else {\n return activateFirstItem(items, isActivatable);\n }\n}\n\n/**\n * Activates the previous item and focuses it. If nothing is currently\n * activated, activates the last item.\n */\nexport function activatePreviousItem<Item extends ListItem>(\n items: Item[],\n activeItemRecord: null | ItemRecord<Item>,\n isActivatable = isItemNotDisabled<Item>,\n wrap = true,\n): Item | null {\n if (activeItemRecord) {\n const prev = getPrevItem(\n items,\n activeItemRecord.index,\n isActivatable,\n wrap,\n );\n if (prev) {\n prev.tabIndex = 0;\n prev.focus();\n }\n return prev;\n } else {\n return activateLastItem(items, isActivatable);\n }\n}\n\n/**\n * Creates an event that requests the parent md-list to deactivate all other\n * items.\n */\nexport function createDeactivateItemsEvent() {\n return new Event('deactivate-items', {bubbles: true, composed: true});\n}\n\n/**\n * The type of the event that requests the parent md-list to deactivate all\n * other items.\n */\nexport type DeactivateItemsEvent = ReturnType<\n typeof createDeactivateItemsEvent\n>;\n\n/**\n * Creates an event that requests the menu to set `tabindex=0` on the item and\n * focus it. We use this pattern because List keeps track of what element is\n * active in the List by maintaining tabindex. We do not want list items\n * to set tabindex on themselves or focus themselves so that we can organize all\n * that logic in the parent List and Menus, and list item stays as dumb as\n * possible.\n */\nexport function createRequestActivationEvent() {\n return new Event('request-activation', {bubbles: true, composed: true});\n}\n\n/**\n * The type of the event that requests the list activates and focuses the item.\n */\nexport type RequestActivationEvent = ReturnType<\n typeof createRequestActivationEvent\n>;\n\n/**\n * The default `isActivatable` function, which checks if an item is not\n * disabled.\n *\n * @param item The item to check.\n * @return true if `item.disabled` is `false.\n */\nfunction isItemNotDisabled<Item extends ListItem>(item: Item) {\n return !item.disabled;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"list-navigation-helpers.js","sourceRoot":"","sources":["list-navigation-helpers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAeH;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAC/B,KAAa,EACb,gBAAgB,CAAA,iBAAuB,CAAA;IAEvC,yEAAyE;IACzE,yEAAyE;IACzE,UAAU;IACV,MAAM,SAAS,GAAG,uBAAuB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IAChE,IAA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,CAAC;QACN,OAAO,iBAAiB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IACjD,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAClC,KAAa,EACb,gBAAyC,EACzC,gBAAgB,CAAA,iBAAuB,CAAA,EACvC,IAAI,GAAG,IAAI;IAEX,IAAI,gBAAgB,EAAE,CAAC;QACrB,MAAM,IAAI,GAAG,WAAW,CACtB,KAAK,EACL,gBAAgB,CAAC,KAAK,EACtB,aAAa,EACb,IAAI,CACL,CAAC;QACF,IAAI,IAAI,EAAE,CAAC;YACT,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;YAClB,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;SAAM,CAAC;QACN,OAAO,gBAAgB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IAChD,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,0BAA0B;IACxC,OAAO,IAAI,KAAK,CAAC,kBAAkB,EAAE,EAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAC;AACxE,CAAC;AAUD;;;;;;;GAOG;AACH,MAAM,UAAU,4BAA4B;IAC1C,OAAO,IAAI,KAAK,CAAC,oBAAoB,EAAE,EAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAC;AAC1E,CAAC;AASD;;;;;;GAMG;AACH,SAAS,iBAAiB,CAAwB,IAAU;IAC1D,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC;AACxB,CAAC","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nexport interface ListItem extends HTMLElement {\n disabled: boolean;\n}\n\n/**\n * A record that describes a list item in a list with metadata such a reference\n * to the item and its index in the list.\n */\nexport interface ItemRecord<Item extends ListItem> {\n item: Item;\n index: number;\n}\n\n/**\n * Activates the first non-disabled item of a given array of items.\n *\n * @param items {Array<ListItem>} The items from which to activate the\n * first item.\n * @param isActivatable Function to determine if an item can be activated.\n * Defaults to non-disabled items.\n */\nexport function activateFirstItem<Item extends ListItem>(\n items: Item[],\n isActivatable = isItemNotDisabled<Item>,\n) {\n // NOTE: These selector functions are static and not on the instance such\n // that multiple operations can be chained and we do not have to re-query\n // the DOM\n const firstItem = getFirstActivatableItem(items, isActivatable);\n if (firstItem) {\n firstItem.tabIndex = 0;\n firstItem.focus();\n }\n return firstItem;\n}\n\n/**\n * Activates the last non-disabled item of a given array of items.\n *\n * @param items {Array<ListItem>} The items from which to activate the\n * last item.\n * @param isActivatable Function to determine if an item can be activated.\n * Defaults to non-disabled items.\n * @nocollapse\n */\nexport function activateLastItem<Item extends ListItem>(\n items: Item[],\n isActivatable = isItemNotDisabled<Item>,\n) {\n const lastItem = getLastActivatableItem(items, isActivatable);\n if (lastItem) {\n lastItem.tabIndex = 0;\n lastItem.focus();\n }\n return lastItem;\n}\n\n/**\n * Deactivates the currently active item of a given array of items.\n *\n * @param items {Array<ListItem>} The items from which to deactivate the\n * active item.\n * @param isActivatable Function to determine if an item can be activated.\n * Defaults to non-disabled items.\n * @return A record of the deleselcted activated item including the item and\n * the index of the item or `null` if none are deactivated.\n * @nocollapse\n */\nexport function deactivateActiveItem<Item extends ListItem>(\n items: Item[],\n isActivatable = isItemNotDisabled<Item>,\n) {\n const activeItem = getActiveItem(items, isActivatable);\n if (activeItem) {\n activeItem.item.tabIndex = -1;\n }\n return activeItem;\n}\n\n/**\n * Retrieves the first activated item of a given array of items.\n *\n * @param items {Array<ListItem>} The items to search.\n * @param isActivatable Function to determine if an item can be activated.\n * Defaults to non-disabled items.\n * @return A record of the first activated item including the item and the\n * index of the item or `null` if none are activated.\n * @nocollapse\n */\nexport function getActiveItem<Item extends ListItem>(\n items: Item[],\n isActivatable = isItemNotDisabled<Item>,\n) {\n for (let i = 0; i < items.length; i++) {\n const item = items[i];\n if (item.tabIndex === 0 && isActivatable(item)) {\n return {\n item,\n index: i,\n } as ItemRecord<Item>;\n }\n }\n return null;\n}\n\n/**\n * Retrieves the first non-disabled item of a given array of items. This\n * the first item that is not disabled.\n *\n * @param items {Array<ListItem>} The items to search.\n * @param isActivatable Function to determine if an item can be activated.\n * Defaults to non-disabled items.\n * @return The first activatable item or `null` if none are activatable.\n * @nocollapse\n */\nexport function getFirstActivatableItem<Item extends ListItem>(\n items: Item[],\n isActivatable = isItemNotDisabled<Item>,\n) {\n for (const item of items) {\n if (isActivatable(item)) {\n return item;\n }\n }\n\n return null;\n}\n\n/**\n * Retrieves the last non-disabled item of a given array of items.\n *\n * @param items {Array<ListItem>} The items to search.\n * @param isActivatable Function to determine if an item can be activated.\n * Defaults to non-disabled items.\n * @return The last activatable item or `null` if none are activatable.\n * @nocollapse\n */\nexport function getLastActivatableItem<Item extends ListItem>(\n items: Item[],\n isActivatable = isItemNotDisabled<Item>,\n) {\n for (let i = items.length - 1; i >= 0; i--) {\n const item = items[i];\n if (isActivatable(item)) {\n return item;\n }\n }\n\n return null;\n}\n\n/**\n * Retrieves the next non-disabled item of a given array of items.\n *\n * @param items {Array<ListItem>} The items to search.\n * @param index {{index: number}} The index to search from.\n * @param isActivatable Function to determine if an item can be activated.\n * Defaults to non-disabled items.\n * @param wrap If true, then the next item at the end of the list is the first\n * item. Defaults to true.\n * @return The next activatable item or `null` if none are activatable.\n */\nexport function getNextItem<Item extends ListItem>(\n items: Item[],\n index: number,\n isActivatable = isItemNotDisabled<Item>,\n wrap = true,\n) {\n for (let i = 1; i < items.length; i++) {\n const nextIndex = (i + index) % items.length;\n if (nextIndex < index && !wrap) {\n // Return if the index loops back to the beginning and not wrapping.\n return null;\n }\n\n const item = items[nextIndex];\n if (isActivatable(item)) {\n return item;\n }\n }\n\n return items[index] ? items[index] : null;\n}\n\n/**\n * Retrieves the previous non-disabled item of a given array of items.\n *\n * @param items {Array<ListItem>} The items to search.\n * @param index {{index: number}} The index to search from.\n * @param isActivatable Function to determine if an item can be activated.\n * Defaults to non-disabled items.\n * @param wrap If true, then the previous item at the beginning of the list is\n * the last item. Defaults to true.\n * @return The previous activatable item or `null` if none are activatable.\n */\nexport function getPrevItem<Item extends ListItem>(\n items: Item[],\n index: number,\n isActivatable = isItemNotDisabled<Item>,\n wrap = true,\n) {\n for (let i = 1; i < items.length; i++) {\n const prevIndex = (index - i + items.length) % items.length;\n if (prevIndex > index && !wrap) {\n // Return if the index loops back to the end and not wrapping.\n return null;\n }\n\n const item = items[prevIndex];\n\n if (isActivatable(item)) {\n return item;\n }\n }\n\n return items[index] ? items[index] : null;\n}\n\n/**\n * Activates the next item and focuses it. If nothing is currently activated,\n * activates the first item.\n */\nexport function activateNextItem<Item extends ListItem>(\n items: Item[],\n activeItemRecord: null | ItemRecord<Item>,\n isActivatable = isItemNotDisabled<Item>,\n wrap = true,\n): Item | null {\n if (activeItemRecord) {\n const next = getNextItem(\n items,\n activeItemRecord.index,\n isActivatable,\n wrap,\n );\n\n if (next) {\n next.tabIndex = 0;\n next.focus();\n }\n\n return next;\n } else {\n return activateFirstItem(items, isActivatable);\n }\n}\n\n/**\n * Activates the previous item and focuses it. If nothing is currently\n * activated, activates the last item.\n */\nexport function activatePreviousItem<Item extends ListItem>(\n items: Item[],\n activeItemRecord: null | ItemRecord<Item>,\n isActivatable = isItemNotDisabled<Item>,\n wrap = true,\n): Item | null {\n if (activeItemRecord) {\n const prev = getPrevItem(\n items,\n activeItemRecord.index,\n isActivatable,\n wrap,\n );\n if (prev) {\n prev.tabIndex = 0;\n prev.focus();\n }\n return prev;\n } else {\n return activateLastItem(items, isActivatable);\n }\n}\n\n/**\n * Creates an event that requests the parent md-list to deactivate all other\n * items.\n */\nexport function createDeactivateItemsEvent() {\n return new Event('deactivate-items', {bubbles: true, composed: true});\n}\n\n/**\n * The type of the event that requests the parent md-list to deactivate all\n * other items.\n */\nexport type DeactivateItemsEvent = ReturnType<\n typeof createDeactivateItemsEvent\n>;\n\n/**\n * Creates an event that requests the menu to set `tabindex=0` on the item and\n * focus it. We use this pattern because List keeps track of what element is\n * active in the List by maintaining tabindex. We do not want list items\n * to set tabindex on themselves or focus themselves so that we can organize all\n * that logic in the parent List and Menus, and list item stays as dumb as\n * possible.\n */\nexport function createRequestActivationEvent() {\n return new Event('request-activation', {bubbles: true, composed: true});\n}\n\n/**\n * The type of the event that requests the list activates and focuses the item.\n */\nexport type RequestActivationEvent = ReturnType<\n typeof createRequestActivationEvent\n>;\n\n/**\n * The default `isActivatable` function, which checks if an item is not\n * disabled.\n *\n * @param item The item to check.\n * @return true if `item.disabled` is `false.\n */\nfunction isItemNotDisabled<Item extends ListItem>(item: Item) {\n return !item.disabled;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.js","sourceRoot":"","sources":["list.ts"],"names":[],"mappings":"AAAA;;;;GAIG;;AAEH,OAAO,EAAC,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAC,MAAM,KAAK,CAAC;AAC/C,OAAO,EAAC,qBAAqB,EAAC,MAAM,mBAAmB,CAAC;AAExD,OAAO,EAAC,cAAc,EAAE,aAAa,EAAC,MAAM,sBAAsB,CAAC;AAGnE,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAS,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC;AAMxE,gEAAgE;AAChE,MAAM,OAAO,IAAK,SAAQ,UAAU;IAYlC,cAAc;IACd,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC;IACnC,CAAC;IAqBD;QACE,KAAK,EAAE,CAAC;QApBO,mBAAc,GAAG,IAAI,cAAc,CAAW;YAC7D,MAAM,EAAE,CAAC,IAAiB,EAAoB,EAAE,CAC9C,IAAI,CAAC,YAAY,CAAC,cAAc,CAAC;YACnC,gBAAgB,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS;YACtC,KAAK,EAAE,GAAG,EAAE,CAAC,gBA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AO,EAAE,IAAI,EAAC,CAAC;uCACmC","sourcesContent":["/**\n * @license\n * Copyright 2021 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {html, isServer, LitElement} from 'lit';\nimport {queryAssignedElements} from 'lit/decorators.js';\n\nimport {ListController, NavigableKeys} from './list-controller.js';\nimport {ListItem as SharedListItem} from './list-navigation-helpers.js';\n\nconst NAVIGABLE_KEY_SET = new Set<string>(Object.values(NavigableKeys));\n\ninterface ListItem extends SharedListItem {\n type: 'text' | 'button' | 'link';\n}\n\n// tslint:disable-next-line:enforce-comments-on-exported-symbols\nexport class List extends LitElement {\n /**\n * An array of activatable and disableable list items. Queries every assigned\n * element that has the `md-list-item` attribute.\n *\n * _NOTE:_ This is a shallow, flattened query via\n * `HTMLSlotElement.queryAssignedElements` and thus will _only_ include direct\n * children / directly slotted elements.\n */\n @queryAssignedElements({flatten: true})\n protected slotItems!: Array<ListItem | (HTMLElement & {item?: ListItem})>;\n\n /** @export */\n get items() {\n return this.listController.items;\n }\n\n private readonly listController = new ListController<ListItem>({\n isItem: (item: HTMLElement): item is ListItem =>\n item.hasAttribute('md-list-item'),\n getPossibleItems: () => this.slotItems,\n isRtl: () => getComputedStyle(this).direction === 'rtl',\n deactivateItem: (item) => {\n item.tabIndex = -1;\n },\n activateItem: (item) => {\n item.tabIndex = 0;\n },\n isNavigableKey: (key) => NAVIGABLE_KEY_SET.has(key),\n isActivatable: (item) => !item.disabled && item.type !== 'text',\n });\n\n private readonly internals =\n // Cast needed for closure\n (this as HTMLElement).attachInternals();\n\n constructor() {\n super();\n if (!isServer) {\n this.internals.role = 'list';\n this.addEventListener('keydown', this.listController.handleKeydown);\n }\n }\n\n protected override render() {\n return html`\n <slot\n @deactivate-items=${this.listController.onDeactivateItems}\n @request-activation=${this.listController.onRequestActivation}\n @slotchange=${this.listController.onSlotchange}>\n </slot>\n `;\n }\n\n /**\n * Activates the next item in the list. If at the end of the list, the first\n * item will be activated.\n *\n * @return The activated list item or `null` if there are no items.\n */\n activateNextItem(): ListItem | null {\n return this.listController.activateNextItem();\n }\n\n /**\n * Activates the previous item in the list. If at the start of the list, the\n * last item will be activated.\n *\n * @return The activated list item or `null` if there are no items.\n */\n activatePreviousItem(): ListItem | null {\n return this.listController.activatePreviousItem();\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-item.js","sourceRoot":"","sources":["list-item.ts"],"names":[],"mappings":"AAAA;;;;GAIG;;AAEH,OAAO,iCAAiC,CAAC;AACzC,OAAO,4BAA4B,CAAC;AACpC,OAAO,2BAA2B,CAAC;AAEnC,OAAO,EAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAiC,MAAM,KAAK,CAAC;AAC9E,OAAO,EAAC,QAAQ,EAAE,KAAK,EAAC,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAY,QAAQ,EAAC,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAC,OAAO,EAAE,IAAI,IAAI,UAAU,EAAc,MAAM,oBAAoB,CAAC;AAG5E,OAAO,EAAC,kBAAkB,EAAC,MAAM,oCAAoC,CAAC;AACtE,OAAO,EACL,4BAA4B,GAE7B,MAAM,+BAA+B,CAAC;AAOvC,wCAAwC;AACxC,MAAM,iBAAiB,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAC;AAEzD;;;GAGG;AACH,MAAM,OAAO,UAAW,SAAQ,iBAAiB;IAAjD;;QAOE;;WAEG;QACuC,aAAQ,GAAG,KAAK,CAAC;QAE3D;;;WAGG;QACwB,SAAI,GAAiB,MAAM,CAAC;QAEvD;;WAEG;QAEH,eAAU,GAAG,IAAI,CAAC;QAElB;;WAEG;QACS,SAAI,GAAG,EAAE,CAAC;QAEtB;;;WAGG;QACS,WAAM,GAAiD,EAAE,CAAC;IA0IxE,CAAC;IAtIC,IAAY,UAAU;QACpB,OAAO,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC;IAC/C,CAAC;I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AQ,CAAC,EAAC,OAAO,EAAE,IAAI,EAAC,CAAC;wCAA6B;AAMvD;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;8CAClD;AAKN;IAAX,QAAQ,EAAE;wCAAW;AAMV;IAAX,QAAQ,EAAE;0CAA2D;AAE9B;IAAvC,KAAK,CAAC,YAAY,CAAC;gDAAsD","sourcesContent":["/**\n * @license\n * Copyright 2022 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport '../../../focus/md-focus-ring.js';\nimport '../../../labs/item/item.js';\nimport '../../../ripple/ripple.js';\n\nimport {html, LitElement, nothing, PropertyValues, TemplateResult} from 'lit';\nimport {property, query} from 'lit/decorators.js';\nimport {ClassInfo, classMap} from 'lit/directives/class-map.js';\nimport {literal, html as staticHtml, StaticValue} from 'lit/static-html.js';\n\nimport {ARIAMixinStrict} from '../../../internal/aria/aria.js';\nimport {mixinDelegatesAria} from '../../../internal/aria/delegate.js';\nimport {\n createRequestActivationEvent,\n ListItem,\n} from '../list-navigation-helpers.js';\n\n/**\n * Supported behaviors for a list item.\n */\nexport type ListItemType = 'text' | 'button' | 'link';\n\n// Separate variable needed for closure.\nconst listItemBaseClass = mixinDelegatesAria(LitElement);\n\n/**\n * @fires request-activation {Event} Requests the list to set `tabindex=0` on\n * the item and focus it. --bubbles --composed\n */\nexport class ListItemEl extends listItemBaseClass implements ListItem {\n /** @nocollapse */\n static override shadowRootOptions = {\n ...LitElement.shadowRootOptions,\n delegatesFocus: true,\n };\n\n /**\n * Disables the item and makes it non-selectable and non-interactive.\n */\n @property({type: Boolean, reflect: true}) disabled = false;\n\n /**\n * Sets the behavior of the list item, defaults to \"text\". Change to \"link\" or\n * \"button\" for interactive items.\n */\n @property({reflect: true}) type: ListItemType = 'text';\n\n /**\n * READONLY. Sets the `md-list-item` attribute on the element.\n */\n @property({type: Boolean, attribute: 'md-list-item', reflect: true})\n isListItem = true;\n\n /**\n * Sets the underlying `HTMLAnchorElement`'s `href` resource attribute.\n */\n @property() href = '';\n\n /**\n * Sets the underlying `HTMLAnchorElement`'s `target` attribute when `href` is\n * set.\n */\n @property() target: '_blank' | '_parent' | '_self' | '_top' | '' = '';\n\n @query('.list-item') protected readonly listItemRoot!: HTMLElement | null;\n\n private get isDisabled() {\n return this.disabled && this.type !== 'link';\n }\n\n protected override willUpdate(changed: PropertyValues<ListItemEl>) {\n if (this.href) {\n this.type = 'link';\n }\n\n super.willUpdate(changed);\n }\n\n protected override render() {\n return this.renderListItem(html`\n <md-item>\n <div slot=\"container\">\n ${this.renderRipple()} ${this.renderFocusRing()}\n </div>\n <slot name=\"start\" slot=\"start\"></slot>\n <slot name=\"end\" slot=\"end\"></slot>\n ${this.renderBody()}\n </md-item>\n `);\n }\n\n /**\n * Renders the root list item.\n *\n * @param content the child content of the list item.\n */\n protected renderListItem(content: unknown) {\n const isAnchor = this.type === 'link';\n let tag: StaticValue;\n switch (this.type) {\n case 'link':\n tag = literal`a`;\n break;\n case 'button':\n tag = literal`button`;\n break;\n default:\n case 'text':\n tag = literal`li`;\n break;\n }\n\n const isInteractive = this.type !== 'text';\n // TODO(b/265339866): announce \"button\"/\"link\" inside of a list item. Until\n // then all are \"listitem\" roles for correct announcement.\n const target = isAnchor && !!this.target ? this.target : nothing;\n return staticHtml`\n <${tag}\n id=\"item\"\n tabindex=\"${this.isDisabled || !isInteractive ? -1 : 0}\"\n ?disabled=${this.isDisabled}\n role=\"listitem\"\n aria-selected=${(this as ARIAMixinStrict).ariaSelected || nothing}\n aria-checked=${(this as ARIAMixinStrict).ariaChecked || nothing}\n aria-expanded=${(this as ARIAMixinStrict).ariaExpanded || nothing}\n aria-haspopup=${(this as ARIAMixinStrict).ariaHasPopup || nothing}\n class=\"list-item ${classMap(this.getRenderClasses())}\"\n href=${this.href || nothing}\n target=${target}\n @focus=${this.onFocus}\n >${content}</${tag}>\n `;\n }\n\n /**\n * Handles rendering of the ripple element.\n */\n protected renderRipple(): TemplateResult | typeof nothing {\n if (this.type === 'text') {\n return nothing;\n }\n\n return html` <md-ripple\n part=\"ripple\"\n for=\"item\"\n ?disabled=${this.isDisabled}></md-ripple>`;\n }\n\n /**\n * Handles rendering of the focus ring.\n */\n protected renderFocusRing(): TemplateResult | typeof nothing {\n if (this.type === 'text') {\n return nothing;\n }\n\n return html` <md-focus-ring\n @visibility-changed=${this.onFocusRingVisibilityChanged}\n part=\"focus-ring\"\n for=\"item\"\n inward></md-focus-ring>`;\n }\n\n protected onFocusRingVisibilityChanged(e: Event) {}\n\n /**\n * Classes applied to the list item root.\n */\n protected getRenderClasses(): ClassInfo {\n return {'disabled': this.isDisabled};\n }\n\n /**\n * Handles rendering the headline and supporting text.\n */\n protected renderBody() {\n return html`\n <slot></slot>\n <slot name=\"overline\" slot=\"overline\"></slot>\n <slot name=\"headline\" slot=\"headline\"></slot>\n <slot name=\"supporting-text\" slot=\"supporting-text\"></slot>\n <slot\n name=\"trailing-supporting-text\"\n slot=\"trailing-supporting-text\"></slot>\n `;\n }\n\n protected onFocus() {\n if (this.tabIndex !== -1) {\n return;\n }\n // Handles the case where the user clicks on the element and then tabs.\n this.dispatchEvent(createRequestActivationEvent());\n }\n\n override focus() {\n // TODO(b/300334509): needed for some cases where delegatesFocus doesn't\n // work programmatically like in FF and select-option\n this.listItemRoot?.focus();\n }\n}\n"]}
|
package/list/list-item.js
CHANGED
|
@@ -45,10 +45,11 @@ import { styles } from './internal/listitem/list-item-styles.js';
|
|
|
45
45
|
* @final
|
|
46
46
|
* @suppress {visibility}
|
|
47
47
|
*/
|
|
48
|
-
|
|
48
|
+
let MdListItem = class MdListItem extends ListItem {
|
|
49
49
|
};
|
|
50
50
|
MdListItem.styles = [styles];
|
|
51
51
|
MdListItem = __decorate([
|
|
52
52
|
customElement('md-list-item')
|
|
53
53
|
], MdListItem);
|
|
54
|
+
export { MdListItem };
|
|
54
55
|
//# sourceMappingURL=list-item.js.map
|
package/list/list-item.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-item.js","sourceRoot":"","sources":["list-item.ts"],"names":[],"mappings":"AAAA;;;;GAIG;;AAGH,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAC,UAAU,IAAI,QAAQ,EAAC,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAC,MAAM,EAAC,MAAM,yCAAyC,CAAC;AAU/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEI,
|
|
1
|
+
{"version":3,"file":"list-item.js","sourceRoot":"","sources":["list-item.ts"],"names":[],"mappings":"AAAA;;;;GAIG;;AAGH,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAC,UAAU,IAAI,QAAQ,EAAC,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAC,MAAM,EAAC,MAAM,yCAAyC,CAAC;AAU/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEI,IAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,QAAQ;;AACtB,iBAAM,GAAwB,CAAC,MAAM,CAAC,AAAhC,CAAiC;AAD5C,UAAU;IADtB,aAAa,CAAC,cAAc,CAAC;GACjB,UAAU,CAEtB","sourcesContent":["/**\n * @license\n * Copyright 2022 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {CSSResultOrNative} from 'lit';\nimport {customElement} from 'lit/decorators.js';\n\nimport {ListItemEl as ListItem} from './internal/listitem/list-item.js';\nimport {styles} from './internal/listitem/list-item-styles.js';\n\nexport {type ListItemType} from './internal/listitem/list-item.js';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'md-list-item': MdListItem;\n }\n}\n\n/**\n * @summary\n * Lists are continuous, vertical indexes of text or images. Items are placed\n * inside the list.\n *\n * @description\n * Lists consist of one or more list items, and can contain actions represented\n * by icons and text. List items come in three sizes: one-line, two-line, and\n * three-line.\n *\n * __Takeaways:__\n *\n * - Lists should be sorted in logical ways that make content easy to scan, such\n * as alphabetical, numerical, chronological, or by user preference.\n * - Lists present content in a way that makes it easy to identify a specific\n * item in a collection and act on it.\n * - Lists should present icons, text, and actions in a consistent format.\n *\n * Acceptable slot child variants are:\n *\n * - `img[slot=end]`\n * - `img[slot=start]`\n *\n * @example\n * ```html\n * <md-list-item\n * headline=\"User Name\"\n * supportingText=\"user@name.com\">\n * <md-icon slot=\"start\">account_circle</md-icon>\n * <md-icon slot=\"end\">check</md-icon>\n * </md-list-item>\n * ```\n *\n * @example\n *\n * @final\n * @suppress {visibility}\n */\n@customElement('md-list-item')\nexport class MdListItem extends ListItem {\n static override styles: CSSResultOrNative[] = [styles];\n}\n"]}
|
package/list/list.js
CHANGED
|
@@ -26,10 +26,11 @@ import { styles } from './internal/list-styles.js';
|
|
|
26
26
|
* @final
|
|
27
27
|
* @suppress {visibility}
|
|
28
28
|
*/
|
|
29
|
-
|
|
29
|
+
let MdList = class MdList extends List {
|
|
30
30
|
};
|
|
31
31
|
MdList.styles = [styles];
|
|
32
32
|
MdList = __decorate([
|
|
33
33
|
customElement('md-list')
|
|
34
34
|
], MdList);
|
|
35
|
+
export { MdList };
|
|
35
36
|
//# sourceMappingURL=list.js.map
|
package/list/list.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.js","sourceRoot":"","sources":["list.ts"],"names":[],"mappings":"AAAA;;;;GAIG;;AAGH,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAC,IAAI,EAAC,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAC,MAAM,EAAC,MAAM,2BAA2B,CAAC;AAQjD;;;;;;;;;;;;;;;;;;GAkBG;AAEI,
|
|
1
|
+
{"version":3,"file":"list.js","sourceRoot":"","sources":["list.ts"],"names":[],"mappings":"AAAA;;;;GAIG;;AAGH,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAC,IAAI,EAAC,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAC,MAAM,EAAC,MAAM,2BAA2B,CAAC;AAQjD;;;;;;;;;;;;;;;;;;GAkBG;AAEI,IAAM,MAAM,GAAZ,MAAM,MAAO,SAAQ,IAAI;;AACd,aAAM,GAAwB,CAAC,MAAM,CAAC,AAAhC,CAAiC;AAD5C,MAAM;IADlB,aAAa,CAAC,SAAS,CAAC;GACZ,MAAM,CAElB","sourcesContent":["/**\n * @license\n * Copyright 2021 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {CSSResultOrNative} from 'lit';\nimport {customElement} from 'lit/decorators.js';\n\nimport {List} from './internal/list.js';\nimport {styles} from './internal/list-styles.js';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'md-list': MdList;\n }\n}\n\n/**\n * @summary Lists are continuous, vertical indexes of text or images.\n *\n * @description\n * Lists consist of one or more list items, and can contain actions represented\n * by icons and text. List items come in three sizes: one-line, two-line, and\n * three-line.\n *\n * __Takeaways:__\n *\n * - Lists should be sorted in logical ways that make content easy to scan, such\n * as alphabetical, numerical, chronological, or by user preference.\n * - Lists present content in a way that makes it easy to identify a specific\n * item in a collection and act on it.\n * - Lists should present icons, text, and actions in a consistent format.\n *\n * @final\n * @suppress {visibility}\n */\n@customElement('md-list')\nexport class MdList extends List {\n static override styles: CSSResultOrNative[] = [styles];\n}\n"]}
|
package/menu/harness.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"harness.js","sourceRoot":"","sources":["harness.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAC,OAAO,EAAC,MAAM,uBAAuB,CAAC;AAG9C,OAAO,EAAC,eAAe,EAAC,MAAM,gCAAgC,CAAC;AAE/D,OAAO,EAAC,eAAe,EAAC,MAAM,gCAAgC,CAAC;AAE/D;;GAEG;AACH,MAAM,OAAO,WAA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E;YACrC,IAAI,CAAC,gBAAgB,CACnB,QAAQ,EACR,GAAG,EAAE;gBACH,OAAO,CAAC,IAAI,CAAC,CAAC;YAChB,CAAC,EACD,EAAC,IAAI,EAAE,IAAI,EAAC,CACb,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,IAAI,EAAE,CAAC;QACZ,MAAM,MAAM,CAAC;IACf,CAAC;CACF","sourcesContent":["/**\n * @license\n * Copyright 2022 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {LitElement} from 'lit';\n\nimport {Harness} from '../testing/harness.js';\n\nimport {Menu} from './internal/menu.js';\nimport {MenuItemHarness} from './internal/menuitem/harness.js';\n\nexport {MenuItemHarness} from './internal/menuitem/harness.js';\n\n/**\n * Test harness for menu.\n */\nexport class MenuHarness extends Harness<Menu> {\n /**\n * Shows the menu and returns the first list item element.\n */\n protected override async getInteractiveElement() {\n await this.element.updateComplete;\n return this.element as Menu;\n }\n\n /** @return ListItem harnesses for the menu's items. */\n getItems() {\n return this.element.items.map(\n (item) => new MenuItemHarness(item as typeof item & LitElement),\n );\n }\n\n async show() {\n const menu = this.element;\n if (menu.open) {\n return;\n }\n\n const opened = new Promise((resolve) => {\n menu.addEventListener(\n 'opened',\n () => {\n resolve(true);\n },\n {once: true},\n );\n });\n\n menu.show();\n await opened;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menuItemController.js","sourceRoot":"","sources":["menuItemController.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EACL,WAAW,EACX,2BAA2B,EAC3B,aAAa,GACd,MAAM,aAAa,CAAC;AAgFrB;;;GAGG;AACH,MAAM,OAAO,kBAAkB;IAO7B;;;OAGG;IACH,YACmB,IAAuC,EACxD,MAAgC;QADf,SAAI,GAAJ,IAAI,CAAmC;QAXlD,0BAAqB,GAAkB,IAAI,CAAC;QAqGpD;;;WAGG;QACH,YAAO,GAAG,GAAG,EAAE;YACb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CAAC,CAAC;SACJ;QAED,OAAO,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,IAAI,OAAO;QACT,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;QAE5B,QAAQ,IAAI,EAAE;YACZ,KAAK,MAAM;gBACT,OAAO,GAAY,CAAC;YACtB,KAAK,QAAQ;gBACX,OAAO,QAAiB,CAAC;YAC3B,QAAQ;YACR,KAAK,UAAU,CAAC;YAChB,KAAK,QAAQ;gBACX,OAAO,IAAa,CAAC;SACxB;IACH,CAAC;IAED;;OAEG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC;IAC7D,CAAC;IAED,aAAa;QACX,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;IAClD,CAAC;IAED,UAAU;QACR,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;YAClB,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC;SACzB;IACH,CAAC;IAgDD;;OAEG;IACH,gBAAgB,CAAC,IAAY;QAC3B,IAAI,CAAC,qBAAqB,GAAG,IAAI,CAAC;IACpC,CAAC;CACF","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {ReactiveController, ReactiveControllerHost} from 'lit';\n\nimport {\n CloseReason,\n createDefaultCloseMenuEvent,\n isClosableKey,\n} from './shared.js';\n\n/**\n * Interface specific to menu item and not HTMLElement.\n *\n * NOTE: required properties are expected to be reactive.\n */\ninterface MenuItemAdditions {\n /**\n * Whether or not the item is in the disabled state.\n */\n disabled: boolean;\n /**\n * The text of the item that will be used for typeahead. If not set, defaults\n * to the textContent of the element slotted into the headline.\n */\n typeaheadText: string;\n /**\n * Whether or not the item is in the selected visual state.\n */\n selected: boolean;\n /**\n * Sets the behavior and role of the menu item, defaults to \"menuitem\".\n */\n type: MenuItemType;\n /**\n * Whether it should keep the menu open after click.\n */\n keepOpen?: boolean;\n /**\n * Sets the underlying `HTMLAnchorElement`'s `href` resource attribute.\n */\n href?: string;\n /**\n * Focuses the item.\n */\n focus: () => void;\n}\n\n/**\n * The interface of every menu item interactive with a menu. All menu items\n * should implement this interface to be compatible with md-menu. Additionally\n * it should have the `md-menu-item` attribute set.\n *\n * NOTE, the required properties are recommended to be reactive properties.\n */\nexport type MenuItem = MenuItemAdditions & HTMLElement;\n\n/**\n * Supported behaviors for a menu item.\n */\nexport type MenuItemType = 'menuitem' | 'option' | 'button' | 'link';\n\n/**\n * The options used to inialize MenuItemController.\n */\nexport interface MenuItemControllerConfig {\n /**\n * A function that returns the headline element of the menu item.\n */\n getHeadlineElements: () => HTMLElement[];\n\n /**\n * A function that returns the supporting-text element of the menu item.\n */\n getSupportingTextElements: () => HTMLElement[];\n\n /**\n * A function that returns the default slot / misc content.\n */\n getDefaultElements: () => Node[];\n\n /**\n * The HTML Element that accepts user interactions like click. Used for\n * occasions like programmatically clicking anchor tags when `Enter` is\n * pressed.\n */\n getInteractiveElement: () => HTMLElement | null;\n}\n\n/**\n * A controller that provides most functionality of an element that implements\n * the MenuItem interface.\n */\nexport class MenuItemController implements ReactiveController {\n private internalTypeaheadText: string | null = null;\n private readonly getHeadlineElements: MenuItemControllerConfig['getHeadlineElements'];\n private readonly getSupportingTextElements: MenuItemControllerConfig['getSupportingTextElements'];\n private readonly getDefaultElements: MenuItemControllerConfig['getDefaultElements'];\n private readonly getInteractiveElement: MenuItemControllerConfig['getInteractiveElement'];\n\n /**\n * @param host The MenuItem in which to attach this controller to.\n * @param config The object that configures this controller's behavior.\n */\n constructor(\n private readonly host: ReactiveControllerHost & MenuItem,\n config: MenuItemControllerConfig,\n ) {\n this.getHeadlineElements = config.getHeadlineElements;\n this.getSupportingTextElements = config.getSupportingTextElements;\n this.getDefaultElements = config.getDefaultElements;\n this.getInteractiveElement = config.getInteractiveElement;\n this.host.addController(this);\n }\n\n /**\n * The text that is selectable via typeahead. If not set, defaults to the\n * innerText of the item slotted into the `\"headline\"` slot, and if there are\n * no slotted elements into headline, then it checks the _default_ slot, and\n * then the `\"supporting-text\"` slot if nothing is in _default_.\n */\n get typeaheadText() {\n if (this.internalTypeaheadText !== null) {\n return this.internalTypeaheadText;\n }\n\n const headlineElements = this.getHeadlineElements();\n\n const textParts: string[] = [];\n headlineElements.forEach((headlineElement) => {\n if (headlineElement.textContent && headlineElement.textContent.trim()) {\n textParts.push(headlineElement.textContent.trim());\n }\n });\n\n // If there are no headline elements, check the default slot's text content\n if (textParts.length === 0) {\n this.getDefaultElements().forEach((defaultElement) => {\n if (defaultElement.textContent && defaultElement.textContent.trim()) {\n textParts.push(defaultElement.textContent.trim());\n }\n });\n }\n\n // If there are no headline nor default slot elements, check the\n //supporting-text slot's text content\n if (textParts.length === 0) {\n this.getSupportingTextElements().forEach((supportingTextElement) => {\n if (\n supportingTextElement.textContent &&\n supportingTextElement.textContent.trim()\n ) {\n textParts.push(supportingTextElement.textContent.trim());\n }\n });\n }\n\n return textParts.join(' ');\n }\n\n /**\n * The recommended tag name to render as the list item.\n */\n get tagName() {\n const type = this.host.type;\n\n switch (type) {\n case 'link':\n return 'a' as const;\n case 'button':\n return 'button' as const;\n default:\n case 'menuitem':\n case 'option':\n return 'li' as const;\n }\n }\n\n /**\n * The recommended role of the menu item.\n */\n get role() {\n return this.host.type === 'option' ? 'option' : 'menuitem';\n }\n\n hostConnected() {\n this.host.toggleAttribute('md-menu-item', true);\n }\n\n hostUpdate() {\n if (this.host.href) {\n this.host.type = 'link';\n }\n }\n\n /**\n * Bind this click listener to the interactive element. Handles closing the\n * menu.\n */\n onClick = () => {\n if (this.host.keepOpen) return;\n\n this.host.dispatchEvent(\n createDefaultCloseMenuEvent(this.host, {\n kind: CloseReason.CLICK_SELECTION,\n }),\n );\n };\n\n /**\n * Bind this click listener to the interactive element. Handles closing the\n * menu.\n */\n onKeydown = (event: KeyboardEvent) => {\n // Check if the interactive element is an anchor tag. If so, click it.\n if (this.host.href && event.code === 'Enter') {\n const interactiveElement = this.getInteractiveElement();\n if (interactiveElement instanceof HTMLAnchorElement) {\n interactiveElement.click();\n }\n }\n\n if (event.defaultPrevented) return;\n\n // If the host has keepOpen = true we should ignore clicks & Space/Enter,\n // however we always maintain the ability to close a menu with a explicit\n // `escape` keypress.\n const keyCode = event.code;\n if (this.host.keepOpen && keyCode !== 'Escape') return;\n\n if (isClosableKey(keyCode)) {\n event.preventDefault();\n this.host.dispatchEvent(\n createDefaultCloseMenuEvent(this.host, {\n kind: CloseReason.KEYDOWN,\n key: keyCode,\n }),\n );\n }\n };\n\n /**\n * Use to set the typeaheadText when it changes.\n */\n setTypeaheadText(text: string) {\n this.internalTypeaheadText = text;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"menuItemController.js","sourceRoot":"","sources":["menuItemController.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EACL,WAAW,EACX,2BAA2B,EAC3B,aAAa,GACd,MAAM,aAAa,CAAC;AAgFrB;;;GAGG;AACH,MAAM,OAAO,kBAAkB;IAO7B;;;OAGG;IACH,YACmB,IAAuC,EACxD,MAAgC;QADf,SAAI,GAAJ,IAAI,CAAmC;QAXlD,0BAAqB,GAAkB,IAAI,CAAC;QAqGpD;;;WAGG;QACH,YAAO,GAAG,GAAG,EAAE;YACb,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ;gBAAE,OAAO;YAE/B,IAAI,CAAC,IAAI,CAAC,aAAa,CACrB,2BAA2B,CAAC,IAAI,CAAC,IAAI,EAAE;gBACrC,IAAI,EAAE,WAAW,CAAC,eAAe;aAClC,CAAC,CACH,CAAC;QACJ,CAAC,CAAC;QAEF;;;WAGG;QACH,cAAS,GAAG,CAAC,KAAoB,EAAE,EAAE;YACnC,sEAAsE;YACtE,IAA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,IAAI,EAAE,CAAC;YACb,KAAK,MAAM;gBACT,OAAO,GAAY,CAAC;YACtB,KAAK,QAAQ;gBACX,OAAO,QAAiB,CAAC;YAC3B,QAAQ;YACR,KAAK,UAAU,CAAC;YAChB,KAAK,QAAQ;gBACX,OAAO,IAAa,CAAC;QACzB,CAAC;IACH,CAAC;IAED;;OAEG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC;IAC7D,CAAC;IAED,aAAa;QACX,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;IAClD,CAAC;IAED,UAAU;QACR,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACnB,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC;QAC1B,CAAC;IACH,CAAC;IAgDD;;OAEG;IACH,gBAAgB,CAAC,IAAY;QAC3B,IAAI,CAAC,qBAAqB,GAAG,IAAI,CAAC;IACpC,CAAC;CACF","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {ReactiveController, ReactiveControllerHost} from 'lit';\n\nimport {\n CloseReason,\n createDefaultCloseMenuEvent,\n isClosableKey,\n} from './shared.js';\n\n/**\n * Interface specific to menu item and not HTMLElement.\n *\n * NOTE: required properties are expected to be reactive.\n */\ninterface MenuItemAdditions {\n /**\n * Whether or not the item is in the disabled state.\n */\n disabled: boolean;\n /**\n * The text of the item that will be used for typeahead. If not set, defaults\n * to the textContent of the element slotted into the headline.\n */\n typeaheadText: string;\n /**\n * Whether or not the item is in the selected visual state.\n */\n selected: boolean;\n /**\n * Sets the behavior and role of the menu item, defaults to \"menuitem\".\n */\n type: MenuItemType;\n /**\n * Whether it should keep the menu open after click.\n */\n keepOpen?: boolean;\n /**\n * Sets the underlying `HTMLAnchorElement`'s `href` resource attribute.\n */\n href?: string;\n /**\n * Focuses the item.\n */\n focus: () => void;\n}\n\n/**\n * The interface of every menu item interactive with a menu. All menu items\n * should implement this interface to be compatible with md-menu. Additionally\n * it should have the `md-menu-item` attribute set.\n *\n * NOTE, the required properties are recommended to be reactive properties.\n */\nexport type MenuItem = MenuItemAdditions & HTMLElement;\n\n/**\n * Supported behaviors for a menu item.\n */\nexport type MenuItemType = 'menuitem' | 'option' | 'button' | 'link';\n\n/**\n * The options used to inialize MenuItemController.\n */\nexport interface MenuItemControllerConfig {\n /**\n * A function that returns the headline element of the menu item.\n */\n getHeadlineElements: () => HTMLElement[];\n\n /**\n * A function that returns the supporting-text element of the menu item.\n */\n getSupportingTextElements: () => HTMLElement[];\n\n /**\n * A function that returns the default slot / misc content.\n */\n getDefaultElements: () => Node[];\n\n /**\n * The HTML Element that accepts user interactions like click. Used for\n * occasions like programmatically clicking anchor tags when `Enter` is\n * pressed.\n */\n getInteractiveElement: () => HTMLElement | null;\n}\n\n/**\n * A controller that provides most functionality of an element that implements\n * the MenuItem interface.\n */\nexport class MenuItemController implements ReactiveController {\n private internalTypeaheadText: string | null = null;\n private readonly getHeadlineElements: MenuItemControllerConfig['getHeadlineElements'];\n private readonly getSupportingTextElements: MenuItemControllerConfig['getSupportingTextElements'];\n private readonly getDefaultElements: MenuItemControllerConfig['getDefaultElements'];\n private readonly getInteractiveElement: MenuItemControllerConfig['getInteractiveElement'];\n\n /**\n * @param host The MenuItem in which to attach this controller to.\n * @param config The object that configures this controller's behavior.\n */\n constructor(\n private readonly host: ReactiveControllerHost & MenuItem,\n config: MenuItemControllerConfig,\n ) {\n this.getHeadlineElements = config.getHeadlineElements;\n this.getSupportingTextElements = config.getSupportingTextElements;\n this.getDefaultElements = config.getDefaultElements;\n this.getInteractiveElement = config.getInteractiveElement;\n this.host.addController(this);\n }\n\n /**\n * The text that is selectable via typeahead. If not set, defaults to the\n * innerText of the item slotted into the `\"headline\"` slot, and if there are\n * no slotted elements into headline, then it checks the _default_ slot, and\n * then the `\"supporting-text\"` slot if nothing is in _default_.\n */\n get typeaheadText() {\n if (this.internalTypeaheadText !== null) {\n return this.internalTypeaheadText;\n }\n\n const headlineElements = this.getHeadlineElements();\n\n const textParts: string[] = [];\n headlineElements.forEach((headlineElement) => {\n if (headlineElement.textContent && headlineElement.textContent.trim()) {\n textParts.push(headlineElement.textContent.trim());\n }\n });\n\n // If there are no headline elements, check the default slot's text content\n if (textParts.length === 0) {\n this.getDefaultElements().forEach((defaultElement) => {\n if (defaultElement.textContent && defaultElement.textContent.trim()) {\n textParts.push(defaultElement.textContent.trim());\n }\n });\n }\n\n // If there are no headline nor default slot elements, check the\n //supporting-text slot's text content\n if (textParts.length === 0) {\n this.getSupportingTextElements().forEach((supportingTextElement) => {\n if (\n supportingTextElement.textContent &&\n supportingTextElement.textContent.trim()\n ) {\n textParts.push(supportingTextElement.textContent.trim());\n }\n });\n }\n\n return textParts.join(' ');\n }\n\n /**\n * The recommended tag name to render as the list item.\n */\n get tagName() {\n const type = this.host.type;\n\n switch (type) {\n case 'link':\n return 'a' as const;\n case 'button':\n return 'button' as const;\n default:\n case 'menuitem':\n case 'option':\n return 'li' as const;\n }\n }\n\n /**\n * The recommended role of the menu item.\n */\n get role() {\n return this.host.type === 'option' ? 'option' : 'menuitem';\n }\n\n hostConnected() {\n this.host.toggleAttribute('md-menu-item', true);\n }\n\n hostUpdate() {\n if (this.host.href) {\n this.host.type = 'link';\n }\n }\n\n /**\n * Bind this click listener to the interactive element. Handles closing the\n * menu.\n */\n onClick = () => {\n if (this.host.keepOpen) return;\n\n this.host.dispatchEvent(\n createDefaultCloseMenuEvent(this.host, {\n kind: CloseReason.CLICK_SELECTION,\n }),\n );\n };\n\n /**\n * Bind this click listener to the interactive element. Handles closing the\n * menu.\n */\n onKeydown = (event: KeyboardEvent) => {\n // Check if the interactive element is an anchor tag. If so, click it.\n if (this.host.href && event.code === 'Enter') {\n const interactiveElement = this.getInteractiveElement();\n if (interactiveElement instanceof HTMLAnchorElement) {\n interactiveElement.click();\n }\n }\n\n if (event.defaultPrevented) return;\n\n // If the host has keepOpen = true we should ignore clicks & Space/Enter,\n // however we always maintain the ability to close a menu with a explicit\n // `escape` keypress.\n const keyCode = event.code;\n if (this.host.keepOpen && keyCode !== 'Escape') return;\n\n if (isClosableKey(keyCode)) {\n event.preventDefault();\n this.host.dispatchEvent(\n createDefaultCloseMenuEvent(this.host, {\n kind: CloseReason.KEYDOWN,\n key: keyCode,\n }),\n );\n }\n };\n\n /**\n * Use to set the typeaheadText when it changes.\n */\n setTypeaheadText(text: string) {\n this.internalTypeaheadText = text;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"surfacePositionController.js","sourceRoot":"","sources":["surfacePositionController.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAoBH;;GAEG;AACH,2EAA2E;AAC3E,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,SAAS,EAAE,WAAW;IACtB,OAAO,EAAE,SAAS;IAClB,WAAW,EAAE,aAAa;IAC1B,SAAS,EAAE,WAAW;CACd,CAAC;AAkGX;;;;;GAKG;AACH,MAAM,OAAO,yBAAyB;IAWpC;;;;OAIG;IACH,YACmB,IAA4B,EAC5B,aAAwD;QADxD,SAAI,GAAJ,IAAI,CAAwB;QAC5B,kBAAa,GAAb,aAAa,CAA2C;QAjB3E,8CAA8C;QACtC,0BAAqB,GAAc;YACzC,SAAS,EAAE,MAAM;SAClB,CAAC;QACF,wEAAwE;QACxE,+CAA+C;QACvC,eAAU,GAAwC;YACxD,MAAM,EAAE,KAAK;SACyB,CAAC;QAWvC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,qBAAqB,CAAC;IACpC,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,QAAQ;QACZ,MAAM,EACJ,SAAS,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B,sEAAsE;gBACtE,kBAAkB;gBAClB,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;gBAExB,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACtB,KAAK,CAAC,MAAM,EAAE,CAAC;aAChB;iBAAM,IAAI,WAAW,EAAE;gBACtB,MAAM,KAAK,CAAC,WAAW,EAAE,CAAC;gBAC1B,IAAI,CAAC,KAAK,EAAE,CAAC;gBACb,KAAK,CAAC,OAAO,EAAE,CAAC;aACjB;SACF;IACH,CAAC;IAED;;OAEG;IACK,KAAK;QACX,IAAI,CAAC,qBAAqB,GAAG;YAC3B,SAAS,EAAE,MAAM;SAClB,CAAC;QACF,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;QAC1B,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC,SAAS,CAAC;QAEjD,4EAA4E;QAC5E,mBAAmB;QACnB,IACG,SAA2C,EAAE,OAAO;YACrD,SAAS,EAAE,WAAW,EACtB;YACC,SAAkD,CAAC,WAAW,EAAE,CAAC;SACnE;IACH,CAAC;CACF","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {ReactiveController, ReactiveControllerHost} from 'lit';\nimport {StyleInfo} from 'lit/directives/style-map.js';\n\n/**\n * Declare popoverAPI functions and properties. See\n * https://developer.mozilla.org/en-US/docs/Web/API/Popover_API\n * Without this, closure will rename these functions. Can remove once these\n * functions make it into the typescript lib.\n */\ndeclare global {\n interface HTMLElement {\n showPopover(): void;\n hidePopover(): void;\n togglePopover(force: boolean): void;\n popover: string | null;\n }\n}\n\n/**\n * An enum of supported Menu corners\n */\n// tslint:disable-next-line:enforce-name-casing We are mimicking enum style\nexport const Corner = {\n END_START: 'end-start',\n END_END: 'end-end',\n START_START: 'start-start',\n START_END: 'start-end',\n} as const;\n\n/**\n * A corner of a box in the standard logical property style of <block>_<inline>\n */\nexport type Corner = (typeof Corner)[keyof typeof Corner];\n\n/**\n * An interface that provides a method to customize the rect from which to\n * calculate the anchor positioning. Useful for when you want a surface to\n * anchor to an element in your shadow DOM rather than the host element.\n */\nexport interface SurfacePositionTarget extends HTMLElement {\n getSurfacePositionClientRect?: () => DOMRect;\n}\n\n/**\n * The configurable options for the surface position controller.\n */\nexport interface SurfacePositionControllerProperties {\n /**\n * Disable the `flip` behavior on the block axis of the surface's corner\n */\n disableBlockFlip: boolean;\n /**\n * Disable the `flip` behavior on the inline axis of the surface's corner\n */\n disableInlineFlip: boolean;\n /**\n * The corner of the anchor to align the surface's position.\n */\n anchorCorner: Corner;\n /**\n * The corner of the surface to align to the given anchor corner.\n */\n surfaceCorner: Corner;\n /**\n * The HTMLElement reference of the surface to be positioned.\n */\n surfaceEl: SurfacePositionTarget | null;\n /**\n * The HTMLElement reference of the anchor to align to.\n */\n anchorEl: SurfacePositionTarget | null;\n /**\n * Whether the positioning algorithim should calculate relative to the parent\n * of the anchor element (absolute) or relative to the window (fixed).\n *\n * Examples for `position = 'fixed'`:\n *\n * - If there is no `position:relative` in the given parent tree and the\n * surface is `position:absolute`\n * - If the surface is `position:fixed`\n * - If the surface is in the \"top layer\"\n * - The anchor and the surface do not share a common `position:relative`\n * ancestor\n */\n positioning: 'absolute' | 'fixed' | 'document';\n /**\n * Whether or not the surface should be \"open\" and visible\n */\n isOpen: boolean;\n /**\n * The number of pixels in which to offset from the inline axis relative to\n * logical property.\n *\n * Positive is right in LTR and left in RTL.\n */\n xOffset: number;\n /**\n * The number of pixes in which to offset the block axis.\n *\n * Positive is down and negative is up.\n */\n yOffset: number;\n /**\n * The strategy to follow when repositioning the menu to stay inside the\n * viewport. \"move\" will simply move the surface to stay in the viewport.\n * \"resize\" will attempt to resize the surface.\n *\n * Both strategies will still attempt to flip the anchor and surface corners.\n */\n repositionStrategy: 'move' | 'resize';\n /**\n * A function to call after the surface has been positioned.\n */\n onOpen: () => void;\n /**\n * A function to call before the surface should be closed. (A good time to\n * perform animations while the surface is still visible)\n */\n beforeClose: () => Promise<void>;\n /**\n * A function to call after the surface has been closed.\n */\n onClose: () => void;\n}\n\n/**\n * Given a surface, an anchor, corners, and some options, this surface will\n * calculate the position of a surface to align the two given corners and keep\n * the surface inside the window viewport. It also provides a StyleInfo map that\n * can be applied to the surface to handle visiblility and position.\n */\nexport class SurfacePositionController implements ReactiveController {\n // The current styles to apply to the surface.\n private surfaceStylesInternal: StyleInfo = {\n 'display': 'none',\n };\n // Previous values stored for change detection. Open change detection is\n // calculated separately so initialize it here.\n private lastValues: SurfacePositionControllerProperties = {\n isOpen: false,\n } as SurfacePositionControllerProperties;\n\n /**\n * @param host The host to connect the controller to.\n * @param getProperties A function that returns the properties for the\n * controller.\n */\n constructor(\n private readonly host: ReactiveControllerHost,\n private readonly getProperties: () => SurfacePositionControllerProperties,\n ) {\n this.host.addController(this);\n }\n\n /**\n * The StyleInfo map to apply to the surface via Lit's stylemap\n */\n get surfaceStyles() {\n return this.surfaceStylesInternal;\n }\n\n /**\n * Calculates the surface's new position required so that the surface's\n * `surfaceCorner` aligns to the anchor's `anchorCorner` while keeping the\n * surface inside the window viewport. This positioning also respects RTL by\n * checking `getComputedStyle()` on the surface element.\n */\n async position() {\n const {\n surfaceEl,\n anchorEl,\n anchorCorner: anchorCornerRaw,\n surfaceCorner: surfaceCornerRaw,\n positioning,\n xOffset,\n yOffset,\n disableBlockFlip,\n disableInlineFlip,\n repositionStrategy,\n } = this.getProperties();\n const anchorCorner = anchorCornerRaw.toLowerCase().trim();\n const surfaceCorner = surfaceCornerRaw.toLowerCase().trim();\n\n if (!surfaceEl || !anchorEl) {\n return;\n }\n\n // Store these before we potentially resize the window with the next set of\n // lines\n const windowInnerWidth = window.innerWidth;\n const windowInnerHeight = window.innerHeight;\n\n const div = document.createElement('div');\n div.style.opacity = '0';\n div.style.position = 'fixed';\n div.style.display = 'block';\n div.style.inset = '0';\n document.body.appendChild(div);\n const scrollbarTestRect = div.getBoundingClientRect();\n div.remove();\n\n // Calculate the widths of the scrollbars in the inline and block directions\n // to account for window-relative calculations.\n const blockScrollbarHeight = window.innerHeight - scrollbarTestRect.bottom;\n const inlineScrollbarWidth = window.innerWidth - scrollbarTestRect.right;\n\n // Paint the surface transparently so that we can get the position and the\n // rect info of the surface.\n this.surfaceStylesInternal = {\n 'display': 'block',\n 'opacity': '0',\n };\n\n // Wait for it to be visible.\n this.host.requestUpdate();\n await this.host.updateComplete;\n\n // Safari has a bug that makes popovers render incorrectly if the node is\n // made visible + Animation Frame before calling showPopover().\n // https://bugs.webkit.org/show_bug.cgi?id=264069\n // also the cast is required due to differing TS types in Google and OSS.\n if (\n (surfaceEl as unknown as {popover: string}).popover &&\n surfaceEl.isConnected\n ) {\n (surfaceEl as unknown as {showPopover: () => void}).showPopover();\n }\n\n const surfaceRect = surfaceEl.getSurfacePositionClientRect\n ? surfaceEl.getSurfacePositionClientRect()\n : surfaceEl.getBoundingClientRect();\n const anchorRect = anchorEl.getSurfacePositionClientRect\n ? anchorEl.getSurfacePositionClientRect()\n : anchorEl.getBoundingClientRect();\n const [surfaceBlock, surfaceInline] = surfaceCorner.split('-') as Array<\n 'start' | 'end'\n >;\n const [anchorBlock, anchorInline] = anchorCorner.split('-') as Array<\n 'start' | 'end'\n >;\n\n // LTR depends on the direction of the SURFACE not the anchor.\n const isLTR =\n getComputedStyle(surfaceEl as HTMLElement).direction === 'ltr';\n\n /*\n * For more on inline and block dimensions, see MDN article:\n * https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_logical_properties_and_values\n *\n * ┌───── inline/blockDocumentOffset inlineScrollbarWidth\n * │ │ │\n * │ ┌─▼─────┐ │Document\n * │ ┌┼───────┴──────────────────────────────┼────────┐\n * │ ││ │ │\n * └──► ││ ┌───── inline/blockWindowOffset │ │\n * ││ │ │ ▼ │\n * ││ │ ┌─▼───┐ Window┌┐ │\n * └┤ │ ┌┼─────┴───────────────────────┼│ │\n * │ │ ││ ││ │\n * │ └──► ││ ┌──inline/blockAnchorOffset││ │\n * │ ││ │ │ ││ │\n * │ └┤ │ ┌──▼───┐ ││ │\n * │ │ │ ┌┼──────┤ ││ │\n * │ │ └─►│Anchor│ ││ │\n * │ │ └┴──────┘ ││ │\n * │ │ ││ │\n * │ │ ┌───────────────────────┼┼────┐ │\n * │ │ │ Surface ││ │ │\n * │ │ │ ││ │ │\n * │ │ │ ││ │ │\n * │ │ │ ││ │ │\n * │ │ │ ││ │ │\n * │ ┌┼─────┼───────────────────────┼│ │ │\n * │ ┌─►┴──────┼────────────────────────┘ ├┐ │\n * │ │ │ inline/blockOOBCorrection ││ │\n * │ │ │ │ ││ │\n * │ │ │ ├──►├│ │\n * │ │ │ │ ││ │\n * │ │ └────────────────────────┐▼───┼┘ │\n * │ blockScrollbarHeight └────┘ │\n * │ │\n * └───────────────────────────────────────────────┘\n */\n\n // Calculate the block positioning properties\n let {blockInset, blockOutOfBoundsCorrection, surfaceBlockProperty} =\n this.calculateBlock({\n surfaceRect,\n anchorRect,\n anchorBlock,\n surfaceBlock,\n yOffset,\n positioning,\n windowInnerHeight,\n blockScrollbarHeight,\n });\n\n // If the surface should be out of bounds in the block direction, flip the\n // surface and anchor corner block values and recalculate\n if (blockOutOfBoundsCorrection && !disableBlockFlip) {\n const flippedSurfaceBlock = surfaceBlock === 'start' ? 'end' : 'start';\n const flippedAnchorBlock = anchorBlock === 'start' ? 'end' : 'start';\n\n const flippedBlock = this.calculateBlock({\n surfaceRect,\n anchorRect,\n anchorBlock: flippedAnchorBlock,\n surfaceBlock: flippedSurfaceBlock,\n yOffset,\n positioning,\n windowInnerHeight,\n blockScrollbarHeight,\n });\n\n // In the case that the flipped verion would require less out of bounds\n // correcting, use the flipped corner block values\n if (\n blockOutOfBoundsCorrection > flippedBlock.blockOutOfBoundsCorrection\n ) {\n blockInset = flippedBlock.blockInset;\n blockOutOfBoundsCorrection = flippedBlock.blockOutOfBoundsCorrection;\n surfaceBlockProperty = flippedBlock.surfaceBlockProperty;\n }\n }\n\n // Calculate the inline positioning properties\n let {inlineInset, inlineOutOfBoundsCorrection, surfaceInlineProperty} =\n this.calculateInline({\n surfaceRect,\n anchorRect,\n anchorInline,\n surfaceInline,\n xOffset,\n positioning,\n isLTR,\n windowInnerWidth,\n inlineScrollbarWidth,\n });\n\n // If the surface should be out of bounds in the inline direction, flip the\n // surface and anchor corner inline values and recalculate\n if (inlineOutOfBoundsCorrection && !disableInlineFlip) {\n const flippedSurfaceInline = surfaceInline === 'start' ? 'end' : 'start';\n const flippedAnchorInline = anchorInline === 'start' ? 'end' : 'start';\n\n const flippedInline = this.calculateInline({\n surfaceRect,\n anchorRect,\n anchorInline: flippedAnchorInline,\n surfaceInline: flippedSurfaceInline,\n xOffset,\n positioning,\n isLTR,\n windowInnerWidth,\n inlineScrollbarWidth,\n });\n\n // In the case that the flipped verion would require less out of bounds\n // correcting, use the flipped corner inline values\n if (\n Math.abs(inlineOutOfBoundsCorrection) >\n Math.abs(flippedInline.inlineOutOfBoundsCorrection)\n ) {\n inlineInset = flippedInline.inlineInset;\n inlineOutOfBoundsCorrection = flippedInline.inlineOutOfBoundsCorrection;\n surfaceInlineProperty = flippedInline.surfaceInlineProperty;\n }\n }\n\n // If we are simply repositioning the surface back inside the viewport,\n // subtract the out of bounds correction values from the positioning.\n if (repositionStrategy === 'move') {\n blockInset = blockInset - blockOutOfBoundsCorrection;\n inlineInset = inlineInset - inlineOutOfBoundsCorrection;\n }\n\n this.surfaceStylesInternal = {\n 'display': 'block',\n 'opacity': '1',\n [surfaceBlockProperty]: `${blockInset}px`,\n [surfaceInlineProperty]: `${inlineInset}px`,\n };\n\n // In the case that we are resizing the surface to stay inside the viewport\n // we need to set height and width on the surface.\n if (repositionStrategy === 'resize') {\n // Add a height property to the styles if there is block height correction\n if (blockOutOfBoundsCorrection) {\n this.surfaceStylesInternal['height'] = `${\n surfaceRect.height - blockOutOfBoundsCorrection\n }px`;\n }\n\n // Add a width property to the styles if there is block height correction\n if (inlineOutOfBoundsCorrection) {\n this.surfaceStylesInternal['width'] = `${\n surfaceRect.width - inlineOutOfBoundsCorrection\n }px`;\n }\n }\n\n this.host.requestUpdate();\n }\n\n /**\n * Calculates the css property, the inset, and the out of bounds correction\n * for the surface in the block direction.\n */\n private calculateBlock(config: {\n surfaceRect: DOMRect;\n anchorRect: DOMRect;\n anchorBlock: 'start' | 'end';\n surfaceBlock: 'start' | 'end';\n yOffset: number;\n positioning: 'absolute' | 'fixed' | 'document';\n windowInnerHeight: number;\n blockScrollbarHeight: number;\n }) {\n const {\n surfaceRect,\n anchorRect,\n anchorBlock,\n surfaceBlock,\n yOffset,\n positioning,\n windowInnerHeight,\n blockScrollbarHeight,\n } = config;\n // We use number booleans to multiply values rather than `if` / ternary\n // statements because it _heavily_ cuts down on nesting and readability\n const relativeToWindow =\n positioning === 'fixed' || positioning === 'document' ? 1 : 0;\n const relativeToDocument = positioning === 'document' ? 1 : 0;\n const isSurfaceBlockStart = surfaceBlock === 'start' ? 1 : 0;\n const isSurfaceBlockEnd = surfaceBlock === 'end' ? 1 : 0;\n const isOneBlockEnd = anchorBlock !== surfaceBlock ? 1 : 0;\n\n // Whether or not to apply the height of the anchor\n const blockAnchorOffset = isOneBlockEnd * anchorRect.height + yOffset;\n // The absolute block position of the anchor relative to window\n const blockTopLayerOffset =\n isSurfaceBlockStart * anchorRect.top +\n isSurfaceBlockEnd *\n (windowInnerHeight - anchorRect.bottom - blockScrollbarHeight);\n const blockDocumentOffset =\n isSurfaceBlockStart * window.scrollY - isSurfaceBlockEnd * window.scrollY;\n\n // If the surface's block would be out of bounds of the window, move it back\n // in\n const blockOutOfBoundsCorrection = Math.abs(\n Math.min(\n 0,\n windowInnerHeight -\n blockTopLayerOffset -\n blockAnchorOffset -\n surfaceRect.height,\n ),\n );\n\n // The block logical value of the surface\n const blockInset =\n relativeToWindow * blockTopLayerOffset +\n relativeToDocument * blockDocumentOffset +\n blockAnchorOffset;\n\n const surfaceBlockProperty =\n surfaceBlock === 'start' ? 'inset-block-start' : 'inset-block-end';\n\n return {blockInset, blockOutOfBoundsCorrection, surfaceBlockProperty};\n }\n\n /**\n * Calculates the css property, the inset, and the out of bounds correction\n * for the surface in the inline direction.\n */\n private calculateInline(config: {\n isLTR: boolean;\n surfaceInline: 'start' | 'end';\n anchorInline: 'start' | 'end';\n anchorRect: DOMRect;\n surfaceRect: DOMRect;\n xOffset: number;\n positioning: 'absolute' | 'fixed' | 'document';\n windowInnerWidth: number;\n inlineScrollbarWidth: number;\n }) {\n const {\n isLTR: isLTRBool,\n surfaceInline,\n anchorInline,\n anchorRect,\n surfaceRect,\n xOffset,\n positioning,\n windowInnerWidth,\n inlineScrollbarWidth,\n } = config;\n // We use number booleans to multiply values rather than `if` / ternary\n // statements because it _heavily_ cuts down on nesting and readability\n const relativeToWindow =\n positioning === 'fixed' || positioning === 'document' ? 1 : 0;\n const relativeToDocument = positioning === 'document' ? 1 : 0;\n const isLTR = isLTRBool ? 1 : 0;\n const isRTL = isLTRBool ? 0 : 1;\n const isSurfaceInlineStart = surfaceInline === 'start' ? 1 : 0;\n const isSurfaceInlineEnd = surfaceInline === 'end' ? 1 : 0;\n const isOneInlineEnd = anchorInline !== surfaceInline ? 1 : 0;\n\n // Whether or not to apply the width of the anchor\n const inlineAnchorOffset = isOneInlineEnd * anchorRect.width + xOffset;\n // The inline position of the anchor relative to window in LTR\n const inlineTopLayerOffsetLTR =\n isSurfaceInlineStart * anchorRect.left +\n isSurfaceInlineEnd *\n (windowInnerWidth - anchorRect.right - inlineScrollbarWidth);\n // The inline position of the anchor relative to window in RTL\n const inlineTopLayerOffsetRTL =\n isSurfaceInlineStart *\n (windowInnerWidth - anchorRect.right - inlineScrollbarWidth) +\n isSurfaceInlineEnd * anchorRect.left;\n // The inline position of the anchor relative to window\n const inlineTopLayerOffset =\n isLTR * inlineTopLayerOffsetLTR + isRTL * inlineTopLayerOffsetRTL;\n\n // The inline position of the anchor relative to window in LTR\n const inlineDocumentOffsetLTR =\n isSurfaceInlineStart * window.scrollX -\n isSurfaceInlineEnd * window.scrollX;\n // The inline position of the anchor relative to window in RTL\n const inlineDocumentOffsetRTL =\n isSurfaceInlineEnd * window.scrollX -\n isSurfaceInlineStart * window.scrollX;\n // The inline position of the anchor relative to window\n const inlineDocumentOffset =\n isLTR * inlineDocumentOffsetLTR + isRTL * inlineDocumentOffsetRTL;\n\n // If the surface's inline would be out of bounds of the window, move it\n // back in\n const inlineOutOfBoundsCorrection = Math.abs(\n Math.min(\n 0,\n windowInnerWidth -\n inlineTopLayerOffset -\n inlineAnchorOffset -\n surfaceRect.width,\n ),\n );\n\n // The inline logical value of the surface\n const inlineInset =\n relativeToWindow * inlineTopLayerOffset +\n inlineAnchorOffset +\n relativeToDocument * inlineDocumentOffset;\n\n let surfaceInlineProperty =\n surfaceInline === 'start' ? 'inset-inline-start' : 'inset-inline-end';\n\n // There are cases where the element is RTL but the root of the page is not.\n // In these cases we want to not use logical properties.\n if (positioning === 'document' || positioning === 'fixed') {\n if (\n (surfaceInline === 'start' && isLTRBool) ||\n (surfaceInline === 'end' && !isLTRBool)\n ) {\n surfaceInlineProperty = 'left';\n } else {\n surfaceInlineProperty = 'right';\n }\n }\n\n return {\n inlineInset,\n inlineOutOfBoundsCorrection,\n surfaceInlineProperty,\n };\n }\n\n hostUpdate() {\n this.onUpdate();\n }\n\n hostUpdated() {\n this.onUpdate();\n }\n\n /**\n * Checks whether the properties passed into the controller have changed since\n * the last positioning. If so, it will reposition if the surface is open or\n * close it if the surface should close.\n */\n private async onUpdate() {\n const props = this.getProperties();\n let hasChanged = false;\n for (const [key, value] of Object.entries(props)) {\n // tslint:disable-next-line\n hasChanged = hasChanged || value !== (this.lastValues as any)[key];\n if (hasChanged) break;\n }\n\n const openChanged = this.lastValues.isOpen !== props.isOpen;\n const hasAnchor = !!props.anchorEl;\n const hasSurface = !!props.surfaceEl;\n\n if (hasChanged && hasAnchor && hasSurface) {\n // Only update isOpen, because if it's closed, we do not want to waste\n // time on a useless reposition calculation. So save the other \"dirty\"\n // values until next time it opens.\n this.lastValues.isOpen = props.isOpen;\n\n if (props.isOpen) {\n // We are going to do a reposition, so save the prop values for future\n // dirty checking.\n this.lastValues = props;\n\n await this.position();\n props.onOpen();\n } else if (openChanged) {\n await props.beforeClose();\n this.close();\n props.onClose();\n }\n }\n }\n\n /**\n * Hides the surface.\n */\n private close() {\n this.surfaceStylesInternal = {\n 'display': 'none',\n };\n this.host.requestUpdate();\n const surfaceEl = this.getProperties().surfaceEl;\n\n // The following type casts are required due to differing TS types in Google\n // and open source.\n if (\n (surfaceEl as unknown as {popover?: string})?.popover &&\n surfaceEl?.isConnected\n ) {\n (surfaceEl as unknown as {hidePopover: () => void}).hidePopover();\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"surfacePositionController.js","sourceRoot":"","sources":["surfacePositionController.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAoBH;;GAEG;AACH,2EAA2E;AAC3E,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,SAAS,EAAE,WAAW;IACtB,OAAO,EAAE,SAAS;IAClB,WAAW,EAAE,aAAa;IAC1B,SAAS,EAAE,WAAW;CACd,CAAC;AAkGX;;;;;GAKG;AACH,MAAM,OAAO,yBAAyB;IAWpC;;;;OAIG;IACH,YACmB,IAA4B,EAC5B,aAAwD;QADxD,SAAI,GAAJ,IAAI,CAAwB;QAC5B,kBAAa,GAAb,aAAa,CAA2C;QAjB3E,8CAA8C;QACtC,0BAAqB,GAAc;YACzC,SAAS,EAAE,MAAM;SAClB,CAAC;QACF,wEAAwE;QACxE,+CAA+C;QACvC,eAAU,GAAwC;YACxD,MAAM,EAAE,KAAK;SACyB,CAAC;QAWvC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,qBAAqB,CAAC;IACpC,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,QAAQ;QACZ,MAAM,EACJ,SAAS,EACT,QAAQ,E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AAE,CAAC;YAC1C,sEAAsE;YACtE,sEAAsE;YACtE,mCAAmC;YACnC,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;YAEtC,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;gBACjB,sEAAsE;gBACtE,kBAAkB;gBAClB,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;gBAExB,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACtB,KAAK,CAAC,MAAM,EAAE,CAAC;YACjB,CAAC;iBAAM,IAAI,WAAW,EAAE,CAAC;gBACvB,MAAM,KAAK,CAAC,WAAW,EAAE,CAAC;gBAC1B,IAAI,CAAC,KAAK,EAAE,CAAC;gBACb,KAAK,CAAC,OAAO,EAAE,CAAC;YAClB,CAAC;QACH,CAAC;IACH,CAAC;IAED;;OAEG;IACK,KAAK;QACX,IAAI,CAAC,qBAAqB,GAAG;YAC3B,SAAS,EAAE,MAAM;SAClB,CAAC;QACF,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;QAC1B,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC,SAAS,CAAC;QAEjD,4EAA4E;QAC5E,mBAAmB;QACnB,IACG,SAA2C,EAAE,OAAO;YACrD,SAAS,EAAE,WAAW,EACtB,CAAC;YACA,SAAkD,CAAC,WAAW,EAAE,CAAC;QACpE,CAAC;IACH,CAAC;CACF","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {ReactiveController, ReactiveControllerHost} from 'lit';\nimport {StyleInfo} from 'lit/directives/style-map.js';\n\n/**\n * Declare popoverAPI functions and properties. See\n * https://developer.mozilla.org/en-US/docs/Web/API/Popover_API\n * Without this, closure will rename these functions. Can remove once these\n * functions make it into the typescript lib.\n */\ndeclare global {\n interface HTMLElement {\n showPopover(): void;\n hidePopover(): void;\n togglePopover(force: boolean): void;\n popover: string | null;\n }\n}\n\n/**\n * An enum of supported Menu corners\n */\n// tslint:disable-next-line:enforce-name-casing We are mimicking enum style\nexport const Corner = {\n END_START: 'end-start',\n END_END: 'end-end',\n START_START: 'start-start',\n START_END: 'start-end',\n} as const;\n\n/**\n * A corner of a box in the standard logical property style of <block>_<inline>\n */\nexport type Corner = (typeof Corner)[keyof typeof Corner];\n\n/**\n * An interface that provides a method to customize the rect from which to\n * calculate the anchor positioning. Useful for when you want a surface to\n * anchor to an element in your shadow DOM rather than the host element.\n */\nexport interface SurfacePositionTarget extends HTMLElement {\n getSurfacePositionClientRect?: () => DOMRect;\n}\n\n/**\n * The configurable options for the surface position controller.\n */\nexport interface SurfacePositionControllerProperties {\n /**\n * Disable the `flip` behavior on the block axis of the surface's corner\n */\n disableBlockFlip: boolean;\n /**\n * Disable the `flip` behavior on the inline axis of the surface's corner\n */\n disableInlineFlip: boolean;\n /**\n * The corner of the anchor to align the surface's position.\n */\n anchorCorner: Corner;\n /**\n * The corner of the surface to align to the given anchor corner.\n */\n surfaceCorner: Corner;\n /**\n * The HTMLElement reference of the surface to be positioned.\n */\n surfaceEl: SurfacePositionTarget | null;\n /**\n * The HTMLElement reference of the anchor to align to.\n */\n anchorEl: SurfacePositionTarget | null;\n /**\n * Whether the positioning algorithim should calculate relative to the parent\n * of the anchor element (absolute) or relative to the window (fixed).\n *\n * Examples for `position = 'fixed'`:\n *\n * - If there is no `position:relative` in the given parent tree and the\n * surface is `position:absolute`\n * - If the surface is `position:fixed`\n * - If the surface is in the \"top layer\"\n * - The anchor and the surface do not share a common `position:relative`\n * ancestor\n */\n positioning: 'absolute' | 'fixed' | 'document';\n /**\n * Whether or not the surface should be \"open\" and visible\n */\n isOpen: boolean;\n /**\n * The number of pixels in which to offset from the inline axis relative to\n * logical property.\n *\n * Positive is right in LTR and left in RTL.\n */\n xOffset: number;\n /**\n * The number of pixes in which to offset the block axis.\n *\n * Positive is down and negative is up.\n */\n yOffset: number;\n /**\n * The strategy to follow when repositioning the menu to stay inside the\n * viewport. \"move\" will simply move the surface to stay in the viewport.\n * \"resize\" will attempt to resize the surface.\n *\n * Both strategies will still attempt to flip the anchor and surface corners.\n */\n repositionStrategy: 'move' | 'resize';\n /**\n * A function to call after the surface has been positioned.\n */\n onOpen: () => void;\n /**\n * A function to call before the surface should be closed. (A good time to\n * perform animations while the surface is still visible)\n */\n beforeClose: () => Promise<void>;\n /**\n * A function to call after the surface has been closed.\n */\n onClose: () => void;\n}\n\n/**\n * Given a surface, an anchor, corners, and some options, this surface will\n * calculate the position of a surface to align the two given corners and keep\n * the surface inside the window viewport. It also provides a StyleInfo map that\n * can be applied to the surface to handle visiblility and position.\n */\nexport class SurfacePositionController implements ReactiveController {\n // The current styles to apply to the surface.\n private surfaceStylesInternal: StyleInfo = {\n 'display': 'none',\n };\n // Previous values stored for change detection. Open change detection is\n // calculated separately so initialize it here.\n private lastValues: SurfacePositionControllerProperties = {\n isOpen: false,\n } as SurfacePositionControllerProperties;\n\n /**\n * @param host The host to connect the controller to.\n * @param getProperties A function that returns the properties for the\n * controller.\n */\n constructor(\n private readonly host: ReactiveControllerHost,\n private readonly getProperties: () => SurfacePositionControllerProperties,\n ) {\n this.host.addController(this);\n }\n\n /**\n * The StyleInfo map to apply to the surface via Lit's stylemap\n */\n get surfaceStyles() {\n return this.surfaceStylesInternal;\n }\n\n /**\n * Calculates the surface's new position required so that the surface's\n * `surfaceCorner` aligns to the anchor's `anchorCorner` while keeping the\n * surface inside the window viewport. This positioning also respects RTL by\n * checking `getComputedStyle()` on the surface element.\n */\n async position() {\n const {\n surfaceEl,\n anchorEl,\n anchorCorner: anchorCornerRaw,\n surfaceCorner: surfaceCornerRaw,\n positioning,\n xOffset,\n yOffset,\n disableBlockFlip,\n disableInlineFlip,\n repositionStrategy,\n } = this.getProperties();\n const anchorCorner = anchorCornerRaw.toLowerCase().trim();\n const surfaceCorner = surfaceCornerRaw.toLowerCase().trim();\n\n if (!surfaceEl || !anchorEl) {\n return;\n }\n\n // Store these before we potentially resize the window with the next set of\n // lines\n const windowInnerWidth = window.innerWidth;\n const windowInnerHeight = window.innerHeight;\n\n const div = document.createElement('div');\n div.style.opacity = '0';\n div.style.position = 'fixed';\n div.style.display = 'block';\n div.style.inset = '0';\n document.body.appendChild(div);\n const scrollbarTestRect = div.getBoundingClientRect();\n div.remove();\n\n // Calculate the widths of the scrollbars in the inline and block directions\n // to account for window-relative calculations.\n const blockScrollbarHeight = window.innerHeight - scrollbarTestRect.bottom;\n const inlineScrollbarWidth = window.innerWidth - scrollbarTestRect.right;\n\n // Paint the surface transparently so that we can get the position and the\n // rect info of the surface.\n this.surfaceStylesInternal = {\n 'display': 'block',\n 'opacity': '0',\n };\n\n // Wait for it to be visible.\n this.host.requestUpdate();\n await this.host.updateComplete;\n\n // Safari has a bug that makes popovers render incorrectly if the node is\n // made visible + Animation Frame before calling showPopover().\n // https://bugs.webkit.org/show_bug.cgi?id=264069\n // also the cast is required due to differing TS types in Google and OSS.\n if (\n (surfaceEl as unknown as {popover: string}).popover &&\n surfaceEl.isConnected\n ) {\n (surfaceEl as unknown as {showPopover: () => void}).showPopover();\n }\n\n const surfaceRect = surfaceEl.getSurfacePositionClientRect\n ? surfaceEl.getSurfacePositionClientRect()\n : surfaceEl.getBoundingClientRect();\n const anchorRect = anchorEl.getSurfacePositionClientRect\n ? anchorEl.getSurfacePositionClientRect()\n : anchorEl.getBoundingClientRect();\n const [surfaceBlock, surfaceInline] = surfaceCorner.split('-') as Array<\n 'start' | 'end'\n >;\n const [anchorBlock, anchorInline] = anchorCorner.split('-') as Array<\n 'start' | 'end'\n >;\n\n // LTR depends on the direction of the SURFACE not the anchor.\n const isLTR =\n getComputedStyle(surfaceEl as HTMLElement).direction === 'ltr';\n\n /*\n * For more on inline and block dimensions, see MDN article:\n * https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_logical_properties_and_values\n *\n * ┌───── inline/blockDocumentOffset inlineScrollbarWidth\n * │ │ │\n * │ ┌─▼─────┐ │Document\n * │ ┌┼───────┴──────────────────────────────┼────────┐\n * │ ││ │ │\n * └──► ││ ┌───── inline/blockWindowOffset │ │\n * ││ │ │ ▼ │\n * ││ │ ┌─▼───┐ Window┌┐ │\n * └┤ │ ┌┼─────┴───────────────────────┼│ │\n * │ │ ││ ││ │\n * │ └──► ││ ┌──inline/blockAnchorOffset││ │\n * │ ││ │ │ ││ │\n * │ └┤ │ ┌──▼───┐ ││ │\n * │ │ │ ┌┼──────┤ ││ │\n * │ │ └─►│Anchor│ ││ │\n * │ │ └┴──────┘ ││ │\n * │ │ ││ │\n * │ │ ┌───────────────────────┼┼────┐ │\n * │ │ │ Surface ││ │ │\n * │ │ │ ││ │ │\n * │ │ │ ││ │ │\n * │ │ │ ││ │ │\n * │ │ │ ││ │ │\n * │ ┌┼─────┼───────────────────────┼│ │ │\n * │ ┌─►┴──────┼────────────────────────┘ ├┐ │\n * │ │ │ inline/blockOOBCorrection ││ │\n * │ │ │ │ ││ │\n * │ │ │ ├──►├│ │\n * │ │ │ │ ││ │\n * │ │ └────────────────────────┐▼───┼┘ │\n * │ blockScrollbarHeight └────┘ │\n * │ │\n * └───────────────────────────────────────────────┘\n */\n\n // Calculate the block positioning properties\n let {blockInset, blockOutOfBoundsCorrection, surfaceBlockProperty} =\n this.calculateBlock({\n surfaceRect,\n anchorRect,\n anchorBlock,\n surfaceBlock,\n yOffset,\n positioning,\n windowInnerHeight,\n blockScrollbarHeight,\n });\n\n // If the surface should be out of bounds in the block direction, flip the\n // surface and anchor corner block values and recalculate\n if (blockOutOfBoundsCorrection && !disableBlockFlip) {\n const flippedSurfaceBlock = surfaceBlock === 'start' ? 'end' : 'start';\n const flippedAnchorBlock = anchorBlock === 'start' ? 'end' : 'start';\n\n const flippedBlock = this.calculateBlock({\n surfaceRect,\n anchorRect,\n anchorBlock: flippedAnchorBlock,\n surfaceBlock: flippedSurfaceBlock,\n yOffset,\n positioning,\n windowInnerHeight,\n blockScrollbarHeight,\n });\n\n // In the case that the flipped verion would require less out of bounds\n // correcting, use the flipped corner block values\n if (\n blockOutOfBoundsCorrection > flippedBlock.blockOutOfBoundsCorrection\n ) {\n blockInset = flippedBlock.blockInset;\n blockOutOfBoundsCorrection = flippedBlock.blockOutOfBoundsCorrection;\n surfaceBlockProperty = flippedBlock.surfaceBlockProperty;\n }\n }\n\n // Calculate the inline positioning properties\n let {inlineInset, inlineOutOfBoundsCorrection, surfaceInlineProperty} =\n this.calculateInline({\n surfaceRect,\n anchorRect,\n anchorInline,\n surfaceInline,\n xOffset,\n positioning,\n isLTR,\n windowInnerWidth,\n inlineScrollbarWidth,\n });\n\n // If the surface should be out of bounds in the inline direction, flip the\n // surface and anchor corner inline values and recalculate\n if (inlineOutOfBoundsCorrection && !disableInlineFlip) {\n const flippedSurfaceInline = surfaceInline === 'start' ? 'end' : 'start';\n const flippedAnchorInline = anchorInline === 'start' ? 'end' : 'start';\n\n const flippedInline = this.calculateInline({\n surfaceRect,\n anchorRect,\n anchorInline: flippedAnchorInline,\n surfaceInline: flippedSurfaceInline,\n xOffset,\n positioning,\n isLTR,\n windowInnerWidth,\n inlineScrollbarWidth,\n });\n\n // In the case that the flipped verion would require less out of bounds\n // correcting, use the flipped corner inline values\n if (\n Math.abs(inlineOutOfBoundsCorrection) >\n Math.abs(flippedInline.inlineOutOfBoundsCorrection)\n ) {\n inlineInset = flippedInline.inlineInset;\n inlineOutOfBoundsCorrection = flippedInline.inlineOutOfBoundsCorrection;\n surfaceInlineProperty = flippedInline.surfaceInlineProperty;\n }\n }\n\n // If we are simply repositioning the surface back inside the viewport,\n // subtract the out of bounds correction values from the positioning.\n if (repositionStrategy === 'move') {\n blockInset = blockInset - blockOutOfBoundsCorrection;\n inlineInset = inlineInset - inlineOutOfBoundsCorrection;\n }\n\n this.surfaceStylesInternal = {\n 'display': 'block',\n 'opacity': '1',\n [surfaceBlockProperty]: `${blockInset}px`,\n [surfaceInlineProperty]: `${inlineInset}px`,\n };\n\n // In the case that we are resizing the surface to stay inside the viewport\n // we need to set height and width on the surface.\n if (repositionStrategy === 'resize') {\n // Add a height property to the styles if there is block height correction\n if (blockOutOfBoundsCorrection) {\n this.surfaceStylesInternal['height'] = `${\n surfaceRect.height - blockOutOfBoundsCorrection\n }px`;\n }\n\n // Add a width property to the styles if there is block height correction\n if (inlineOutOfBoundsCorrection) {\n this.surfaceStylesInternal['width'] = `${\n surfaceRect.width - inlineOutOfBoundsCorrection\n }px`;\n }\n }\n\n this.host.requestUpdate();\n }\n\n /**\n * Calculates the css property, the inset, and the out of bounds correction\n * for the surface in the block direction.\n */\n private calculateBlock(config: {\n surfaceRect: DOMRect;\n anchorRect: DOMRect;\n anchorBlock: 'start' | 'end';\n surfaceBlock: 'start' | 'end';\n yOffset: number;\n positioning: 'absolute' | 'fixed' | 'document';\n windowInnerHeight: number;\n blockScrollbarHeight: number;\n }) {\n const {\n surfaceRect,\n anchorRect,\n anchorBlock,\n surfaceBlock,\n yOffset,\n positioning,\n windowInnerHeight,\n blockScrollbarHeight,\n } = config;\n // We use number booleans to multiply values rather than `if` / ternary\n // statements because it _heavily_ cuts down on nesting and readability\n const relativeToWindow =\n positioning === 'fixed' || positioning === 'document' ? 1 : 0;\n const relativeToDocument = positioning === 'document' ? 1 : 0;\n const isSurfaceBlockStart = surfaceBlock === 'start' ? 1 : 0;\n const isSurfaceBlockEnd = surfaceBlock === 'end' ? 1 : 0;\n const isOneBlockEnd = anchorBlock !== surfaceBlock ? 1 : 0;\n\n // Whether or not to apply the height of the anchor\n const blockAnchorOffset = isOneBlockEnd * anchorRect.height + yOffset;\n // The absolute block position of the anchor relative to window\n const blockTopLayerOffset =\n isSurfaceBlockStart * anchorRect.top +\n isSurfaceBlockEnd *\n (windowInnerHeight - anchorRect.bottom - blockScrollbarHeight);\n const blockDocumentOffset =\n isSurfaceBlockStart * window.scrollY - isSurfaceBlockEnd * window.scrollY;\n\n // If the surface's block would be out of bounds of the window, move it back\n // in\n const blockOutOfBoundsCorrection = Math.abs(\n Math.min(\n 0,\n windowInnerHeight -\n blockTopLayerOffset -\n blockAnchorOffset -\n surfaceRect.height,\n ),\n );\n\n // The block logical value of the surface\n const blockInset =\n relativeToWindow * blockTopLayerOffset +\n relativeToDocument * blockDocumentOffset +\n blockAnchorOffset;\n\n const surfaceBlockProperty =\n surfaceBlock === 'start' ? 'inset-block-start' : 'inset-block-end';\n\n return {blockInset, blockOutOfBoundsCorrection, surfaceBlockProperty};\n }\n\n /**\n * Calculates the css property, the inset, and the out of bounds correction\n * for the surface in the inline direction.\n */\n private calculateInline(config: {\n isLTR: boolean;\n surfaceInline: 'start' | 'end';\n anchorInline: 'start' | 'end';\n anchorRect: DOMRect;\n surfaceRect: DOMRect;\n xOffset: number;\n positioning: 'absolute' | 'fixed' | 'document';\n windowInnerWidth: number;\n inlineScrollbarWidth: number;\n }) {\n const {\n isLTR: isLTRBool,\n surfaceInline,\n anchorInline,\n anchorRect,\n surfaceRect,\n xOffset,\n positioning,\n windowInnerWidth,\n inlineScrollbarWidth,\n } = config;\n // We use number booleans to multiply values rather than `if` / ternary\n // statements because it _heavily_ cuts down on nesting and readability\n const relativeToWindow =\n positioning === 'fixed' || positioning === 'document' ? 1 : 0;\n const relativeToDocument = positioning === 'document' ? 1 : 0;\n const isLTR = isLTRBool ? 1 : 0;\n const isRTL = isLTRBool ? 0 : 1;\n const isSurfaceInlineStart = surfaceInline === 'start' ? 1 : 0;\n const isSurfaceInlineEnd = surfaceInline === 'end' ? 1 : 0;\n const isOneInlineEnd = anchorInline !== surfaceInline ? 1 : 0;\n\n // Whether or not to apply the width of the anchor\n const inlineAnchorOffset = isOneInlineEnd * anchorRect.width + xOffset;\n // The inline position of the anchor relative to window in LTR\n const inlineTopLayerOffsetLTR =\n isSurfaceInlineStart * anchorRect.left +\n isSurfaceInlineEnd *\n (windowInnerWidth - anchorRect.right - inlineScrollbarWidth);\n // The inline position of the anchor relative to window in RTL\n const inlineTopLayerOffsetRTL =\n isSurfaceInlineStart *\n (windowInnerWidth - anchorRect.right - inlineScrollbarWidth) +\n isSurfaceInlineEnd * anchorRect.left;\n // The inline position of the anchor relative to window\n const inlineTopLayerOffset =\n isLTR * inlineTopLayerOffsetLTR + isRTL * inlineTopLayerOffsetRTL;\n\n // The inline position of the anchor relative to window in LTR\n const inlineDocumentOffsetLTR =\n isSurfaceInlineStart * window.scrollX -\n isSurfaceInlineEnd * window.scrollX;\n // The inline position of the anchor relative to window in RTL\n const inlineDocumentOffsetRTL =\n isSurfaceInlineEnd * window.scrollX -\n isSurfaceInlineStart * window.scrollX;\n // The inline position of the anchor relative to window\n const inlineDocumentOffset =\n isLTR * inlineDocumentOffsetLTR + isRTL * inlineDocumentOffsetRTL;\n\n // If the surface's inline would be out of bounds of the window, move it\n // back in\n const inlineOutOfBoundsCorrection = Math.abs(\n Math.min(\n 0,\n windowInnerWidth -\n inlineTopLayerOffset -\n inlineAnchorOffset -\n surfaceRect.width,\n ),\n );\n\n // The inline logical value of the surface\n const inlineInset =\n relativeToWindow * inlineTopLayerOffset +\n inlineAnchorOffset +\n relativeToDocument * inlineDocumentOffset;\n\n let surfaceInlineProperty =\n surfaceInline === 'start' ? 'inset-inline-start' : 'inset-inline-end';\n\n // There are cases where the element is RTL but the root of the page is not.\n // In these cases we want to not use logical properties.\n if (positioning === 'document' || positioning === 'fixed') {\n if (\n (surfaceInline === 'start' && isLTRBool) ||\n (surfaceInline === 'end' && !isLTRBool)\n ) {\n surfaceInlineProperty = 'left';\n } else {\n surfaceInlineProperty = 'right';\n }\n }\n\n return {\n inlineInset,\n inlineOutOfBoundsCorrection,\n surfaceInlineProperty,\n };\n }\n\n hostUpdate() {\n this.onUpdate();\n }\n\n hostUpdated() {\n this.onUpdate();\n }\n\n /**\n * Checks whether the properties passed into the controller have changed since\n * the last positioning. If so, it will reposition if the surface is open or\n * close it if the surface should close.\n */\n private async onUpdate() {\n const props = this.getProperties();\n let hasChanged = false;\n for (const [key, value] of Object.entries(props)) {\n // tslint:disable-next-line\n hasChanged = hasChanged || value !== (this.lastValues as any)[key];\n if (hasChanged) break;\n }\n\n const openChanged = this.lastValues.isOpen !== props.isOpen;\n const hasAnchor = !!props.anchorEl;\n const hasSurface = !!props.surfaceEl;\n\n if (hasChanged && hasAnchor && hasSurface) {\n // Only update isOpen, because if it's closed, we do not want to waste\n // time on a useless reposition calculation. So save the other \"dirty\"\n // values until next time it opens.\n this.lastValues.isOpen = props.isOpen;\n\n if (props.isOpen) {\n // We are going to do a reposition, so save the prop values for future\n // dirty checking.\n this.lastValues = props;\n\n await this.position();\n props.onOpen();\n } else if (openChanged) {\n await props.beforeClose();\n this.close();\n props.onClose();\n }\n }\n }\n\n /**\n * Hides the surface.\n */\n private close() {\n this.surfaceStylesInternal = {\n 'display': 'none',\n };\n this.host.requestUpdate();\n const surfaceEl = this.getProperties().surfaceEl;\n\n // The following type casts are required due to differing TS types in Google\n // and open source.\n if (\n (surfaceEl as unknown as {popover?: string})?.popover &&\n surfaceEl?.isConnected\n ) {\n (surfaceEl as unknown as {hidePopover: () => void}).hidePopover();\n }\n }\n}\n"]}
|