@angular/cdk 21.0.0-next.8 → 21.0.0-rc.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/_adev_assets/cdk_drag_drop.json +13 -12
- package/_adev_assets/cdk_testing.json +15 -25
- package/_adev_assets/cdk_testing_protractor.json +1 -1
- package/_adev_assets/cdk_testing_selenium_webdriver.json +1 -1
- package/_adev_assets/cdk_testing_testbed.json +1 -1
- package/fesm2022/_a11y-module-chunk.mjs +755 -869
- package/fesm2022/_a11y-module-chunk.mjs.map +1 -1
- package/fesm2022/_activedescendant-key-manager-chunk.mjs +8 -8
- package/fesm2022/_activedescendant-key-manager-chunk.mjs.map +1 -1
- package/fesm2022/_array-chunk.mjs +1 -1
- package/fesm2022/_array-chunk.mjs.map +1 -1
- package/fesm2022/_breakpoints-observer-chunk.mjs +149 -152
- package/fesm2022/_breakpoints-observer-chunk.mjs.map +1 -1
- package/fesm2022/_css-pixel-value-chunk.mjs +4 -5
- package/fesm2022/_css-pixel-value-chunk.mjs.map +1 -1
- package/fesm2022/_data-source-chunk.mjs +2 -8
- package/fesm2022/_data-source-chunk.mjs.map +1 -1
- package/fesm2022/_directionality-chunk.mjs +54 -54
- package/fesm2022/_directionality-chunk.mjs.map +1 -1
- package/fesm2022/_dispose-view-repeater-strategy-chunk.mjs +25 -36
- package/fesm2022/_dispose-view-repeater-strategy-chunk.mjs.map +1 -1
- package/fesm2022/_element-chunk.mjs +6 -17
- package/fesm2022/_element-chunk.mjs.map +1 -1
- package/fesm2022/_fake-event-detection-chunk.mjs +3 -17
- package/fesm2022/_fake-event-detection-chunk.mjs.map +1 -1
- package/fesm2022/_focus-key-manager-chunk.mjs +10 -14
- package/fesm2022/_focus-key-manager-chunk.mjs.map +1 -1
- package/fesm2022/_focus-monitor-chunk.mjs +376 -566
- package/fesm2022/_focus-monitor-chunk.mjs.map +1 -1
- package/fesm2022/_id-generator-chunk.mjs +36 -27
- package/fesm2022/_id-generator-chunk.mjs.map +1 -1
- package/fesm2022/_keycodes-chunk.mjs +9 -9
- package/fesm2022/_keycodes-chunk.mjs.map +1 -1
- package/fesm2022/_list-key-manager-chunk.mjs +248 -336
- package/fesm2022/_list-key-manager-chunk.mjs.map +1 -1
- package/fesm2022/_overlay-module-chunk.mjs +2534 -2948
- package/fesm2022/_overlay-module-chunk.mjs.map +1 -1
- package/fesm2022/_passive-listeners-chunk.mjs +10 -22
- package/fesm2022/_passive-listeners-chunk.mjs.map +1 -1
- package/fesm2022/_platform-chunk.mjs +42 -65
- package/fesm2022/_platform-chunk.mjs.map +1 -1
- package/fesm2022/_recycle-view-repeater-strategy-chunk.mjs +78 -134
- package/fesm2022/_recycle-view-repeater-strategy-chunk.mjs.map +1 -1
- package/fesm2022/_scrolling-chunk.mjs +44 -85
- package/fesm2022/_scrolling-chunk.mjs.map +1 -1
- package/fesm2022/_selection-model-chunk.mjs +138 -209
- package/fesm2022/_selection-model-chunk.mjs.map +1 -1
- package/fesm2022/_shadow-dom-chunk.mjs +21 -35
- package/fesm2022/_shadow-dom-chunk.mjs.map +1 -1
- package/fesm2022/_style-loader-chunk.mjs +50 -37
- package/fesm2022/_style-loader-chunk.mjs.map +1 -1
- package/fesm2022/_test-environment-chunk.mjs +2 -14
- package/fesm2022/_test-environment-chunk.mjs.map +1 -1
- package/fesm2022/_tree-key-manager-chunk.mjs +229 -308
- package/fesm2022/_tree-key-manager-chunk.mjs.map +1 -1
- package/fesm2022/_typeahead-chunk.mjs +52 -74
- package/fesm2022/_typeahead-chunk.mjs.map +1 -1
- package/fesm2022/_unique-selection-dispatcher-chunk.mjs +43 -40
- package/fesm2022/_unique-selection-dispatcher-chunk.mjs.map +1 -1
- package/fesm2022/a11y.mjs +351 -449
- package/fesm2022/a11y.mjs.map +1 -1
- package/fesm2022/accordion.mjs +254 -192
- package/fesm2022/accordion.mjs.map +1 -1
- package/fesm2022/bidi.mjs +121 -64
- package/fesm2022/bidi.mjs.map +1 -1
- package/fesm2022/cdk.mjs +1 -2
- package/fesm2022/cdk.mjs.map +1 -1
- package/fesm2022/clipboard.mjs +208 -186
- package/fesm2022/clipboard.mjs.map +1 -1
- package/fesm2022/coercion-private.mjs +4 -8
- package/fesm2022/coercion-private.mjs.map +1 -1
- package/fesm2022/coercion.mjs +11 -29
- package/fesm2022/coercion.mjs.map +1 -1
- package/fesm2022/dialog.mjs +660 -808
- package/fesm2022/dialog.mjs.map +1 -1
- package/fesm2022/drag-drop.mjs +3347 -4286
- package/fesm2022/drag-drop.mjs.map +1 -1
- package/fesm2022/keycodes.mjs +4 -8
- package/fesm2022/keycodes.mjs.map +1 -1
- package/fesm2022/layout.mjs +44 -26
- package/fesm2022/layout.mjs.map +1 -1
- package/fesm2022/listbox.mjs +841 -895
- package/fesm2022/listbox.mjs.map +1 -1
- package/fesm2022/menu.mjs +1942 -1858
- package/fesm2022/menu.mjs.map +1 -1
- package/fesm2022/observers-private.mjs +88 -106
- package/fesm2022/observers-private.mjs.map +1 -1
- package/fesm2022/observers.mjs +262 -184
- package/fesm2022/observers.mjs.map +1 -1
- package/fesm2022/overlay.mjs +72 -68
- package/fesm2022/overlay.mjs.map +1 -1
- package/fesm2022/platform.mjs +43 -54
- package/fesm2022/platform.mjs.map +1 -1
- package/fesm2022/portal.mjs +402 -560
- package/fesm2022/portal.mjs.map +1 -1
- package/fesm2022/private.mjs +38 -10
- package/fesm2022/private.mjs.map +1 -1
- package/fesm2022/scrolling.mjs +1323 -1400
- package/fesm2022/scrolling.mjs.map +1 -1
- package/fesm2022/stepper.mjs +758 -590
- package/fesm2022/stepper.mjs.map +1 -1
- package/fesm2022/table.mjs +2327 -2319
- package/fesm2022/table.mjs.map +1 -1
- package/fesm2022/testing-selenium-webdriver.mjs +252 -325
- package/fesm2022/testing-selenium-webdriver.mjs.map +1 -1
- package/fesm2022/testing-testbed.mjs +592 -709
- package/fesm2022/testing-testbed.mjs.map +1 -1
- package/fesm2022/testing.mjs +368 -889
- package/fesm2022/testing.mjs.map +1 -1
- package/fesm2022/text-field.mjs +459 -388
- package/fesm2022/text-field.mjs.map +1 -1
- package/fesm2022/tree.mjs +1483 -1731
- package/fesm2022/tree.mjs.map +1 -1
- package/overlay/_index.scss +28 -0
- package/overlay-prebuilt.css +1 -1
- package/package.json +1 -1
- package/schematics/ng-add/index.js +1 -1
- package/types/_harness-environment-chunk.d.ts +1 -2
- package/types/_overlay-module-chunk.d.ts +59 -7
- package/types/_portal-directives-chunk.d.ts +2 -18
- package/types/accordion.d.ts +3 -1
- package/types/dialog.d.ts +1 -1
- package/types/overlay.d.ts +6 -2
- package/types/portal.d.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_tree-key-manager-chunk.mjs","sources":["../../../../../darwin_arm64-fastbuild-ST-199a4f3c4e20/bin/src/cdk/a11y/key-manager/tree-key-manager.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {InjectionToken, QueryList} from '@angular/core';\nimport {coerceObservable} from '../../coercion/private';\nimport {Observable, Subject, Subscription, isObservable, of as observableOf} from 'rxjs';\nimport {take} from 'rxjs/operators';\nimport {\n TreeKeyManagerFactory,\n TreeKeyManagerItem,\n TreeKeyManagerOptions,\n TreeKeyManagerStrategy,\n} from './tree-key-manager-strategy';\nimport {Typeahead} from './typeahead';\n\n/**\n * This class manages keyboard events for trees. If you pass it a QueryList or other list of tree\n * items, it will set the active item, focus, handle expansion and typeahead correctly when\n * keyboard events occur.\n */\nexport class TreeKeyManager<T extends TreeKeyManagerItem> implements TreeKeyManagerStrategy<T> {\n /** The index of the currently active (focused) item. */\n private _activeItemIndex = -1;\n /** The currently active (focused) item. */\n private _activeItem: T | null = null;\n /** Whether or not we activate the item when it's focused. */\n private _shouldActivationFollowFocus = false;\n /**\n * The orientation that the tree is laid out in. In `rtl` mode, the behavior of Left and\n * Right arrow are switched.\n */\n private _horizontalOrientation: 'ltr' | 'rtl' = 'ltr';\n\n /**\n * Predicate function that can be used to check whether an item should be skipped\n * by the key manager.\n *\n * The default value for this doesn't skip any elements in order to keep tree items focusable\n * when disabled. This aligns with ARIA guidelines:\n * https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/#focusabilityofdisabledcontrols.\n */\n private _skipPredicateFn = (_item: T) => false;\n\n /** Function to determine equivalent items. */\n private _trackByFn: (item: T) => unknown = (item: T) => item;\n\n /** Synchronous cache of the items to manage. */\n private _items: T[] = [];\n\n private _typeahead?: Typeahead<T>;\n private _typeaheadSubscription = Subscription.EMPTY;\n\n private _hasInitialFocused = false;\n\n private _initializeFocus(): void {\n if (this._hasInitialFocused || this._items.length === 0) {\n return;\n }\n\n let activeIndex = 0;\n for (let i = 0; i < this._items.length; i++) {\n if (!this._skipPredicateFn(this._items[i]) && !this._isItemDisabled(this._items[i])) {\n activeIndex = i;\n break;\n }\n }\n\n const activeItem = this._items[activeIndex];\n\n // Use `makeFocusable` here, because we want the item to just be focusable, not actually\n // capture the focus since the user isn't interacting with it. See #29628.\n if (activeItem.makeFocusable) {\n this._activeItem?.unfocus();\n this._activeItemIndex = activeIndex;\n this._activeItem = activeItem;\n this._typeahead?.setCurrentSelectedItemIndex(activeIndex);\n activeItem.makeFocusable();\n } else {\n // Backwards compatibility for items that don't implement `makeFocusable`.\n this.focusItem(activeIndex);\n }\n\n this._hasInitialFocused = true;\n }\n\n /**\n *\n * @param items List of TreeKeyManager options. Can be synchronous or asynchronous.\n * @param config Optional configuration options. By default, use 'ltr' horizontal orientation. By\n * default, do not skip any nodes. By default, key manager only calls `focus` method when items\n * are focused and does not call `activate`. If `typeaheadDefaultInterval` is `true`, use a\n * default interval of 200ms.\n */\n constructor(items: Observable<T[]> | QueryList<T> | T[], config: TreeKeyManagerOptions<T>) {\n // We allow for the items to be an array or Observable because, in some cases, the consumer may\n // not have access to a QueryList of the items they want to manage (e.g. when the\n // items aren't being collected via `ViewChildren` or `ContentChildren`).\n if (items instanceof QueryList) {\n this._items = items.toArray();\n items.changes.subscribe((newItems: QueryList<T>) => {\n this._items = newItems.toArray();\n this._typeahead?.setItems(this._items);\n this._updateActiveItemIndex(this._items);\n this._initializeFocus();\n });\n } else if (isObservable(items)) {\n items.subscribe(newItems => {\n this._items = newItems;\n this._typeahead?.setItems(newItems);\n this._updateActiveItemIndex(newItems);\n this._initializeFocus();\n });\n } else {\n this._items = items;\n this._initializeFocus();\n }\n\n if (typeof config.shouldActivationFollowFocus === 'boolean') {\n this._shouldActivationFollowFocus = config.shouldActivationFollowFocus;\n }\n if (config.horizontalOrientation) {\n this._horizontalOrientation = config.horizontalOrientation;\n }\n if (config.skipPredicate) {\n this._skipPredicateFn = config.skipPredicate;\n }\n if (config.trackBy) {\n this._trackByFn = config.trackBy;\n }\n if (typeof config.typeAheadDebounceInterval !== 'undefined') {\n this._setTypeAhead(config.typeAheadDebounceInterval);\n }\n }\n\n /** Stream that emits any time the focused item changes. */\n readonly change = new Subject<T | null>();\n\n /** Cleans up the key manager. */\n destroy() {\n this._typeaheadSubscription.unsubscribe();\n this._typeahead?.destroy();\n this.change.complete();\n }\n\n /**\n * Handles a keyboard event on the tree.\n * @param event Keyboard event that represents the user interaction with the tree.\n */\n onKeydown(event: KeyboardEvent) {\n const key = event.key;\n\n switch (key) {\n case 'Tab':\n // Return early here, in order to allow Tab to actually tab out of the tree\n return;\n\n case 'ArrowDown':\n this._focusNextItem();\n break;\n\n case 'ArrowUp':\n this._focusPreviousItem();\n break;\n\n case 'ArrowRight':\n this._horizontalOrientation === 'rtl'\n ? this._collapseCurrentItem()\n : this._expandCurrentItem();\n break;\n\n case 'ArrowLeft':\n this._horizontalOrientation === 'rtl'\n ? this._expandCurrentItem()\n : this._collapseCurrentItem();\n break;\n\n case 'Home':\n this._focusFirstItem();\n break;\n\n case 'End':\n this._focusLastItem();\n break;\n\n case 'Enter':\n case ' ':\n this._activateCurrentItem();\n break;\n\n default:\n if (event.key === '*') {\n this._expandAllItemsAtCurrentItemLevel();\n break;\n }\n\n this._typeahead?.handleKey(event);\n // Return here, in order to avoid preventing the default action of non-navigational\n // keys or resetting the buffer of pressed letters.\n return;\n }\n\n // Reset the typeahead since the user has used a navigational key.\n this._typeahead?.reset();\n event.preventDefault();\n }\n\n /** Index of the currently active item. */\n getActiveItemIndex(): number | null {\n return this._activeItemIndex;\n }\n\n /** The currently active item. */\n getActiveItem(): T | null {\n return this._activeItem;\n }\n\n /** Focus the first available item. */\n private _focusFirstItem(): void {\n this.focusItem(this._findNextAvailableItemIndex(-1));\n }\n\n /** Focus the last available item. */\n private _focusLastItem(): void {\n this.focusItem(this._findPreviousAvailableItemIndex(this._items.length));\n }\n\n /** Focus the next available item. */\n private _focusNextItem(): void {\n this.focusItem(this._findNextAvailableItemIndex(this._activeItemIndex));\n }\n\n /** Focus the previous available item. */\n private _focusPreviousItem(): void {\n this.focusItem(this._findPreviousAvailableItemIndex(this._activeItemIndex));\n }\n\n /**\n * Focus the provided item by index.\n * @param index The index of the item to focus.\n * @param options Additional focusing options.\n */\n focusItem(index: number, options?: {emitChangeEvent?: boolean}): void;\n focusItem(item: T, options?: {emitChangeEvent?: boolean}): void;\n focusItem(itemOrIndex: number | T, options?: {emitChangeEvent?: boolean}): void;\n focusItem(itemOrIndex: number | T, options: {emitChangeEvent?: boolean} = {}) {\n // Set default options\n options.emitChangeEvent ??= true;\n\n let index =\n typeof itemOrIndex === 'number'\n ? itemOrIndex\n : this._items.findIndex(item => this._trackByFn(item) === this._trackByFn(itemOrIndex));\n if (index < 0 || index >= this._items.length) {\n return;\n }\n const activeItem = this._items[index];\n\n // If we're just setting the same item, don't re-call activate or focus\n if (\n this._activeItem !== null &&\n this._trackByFn(activeItem) === this._trackByFn(this._activeItem)\n ) {\n return;\n }\n\n const previousActiveItem = this._activeItem;\n this._activeItem = activeItem ?? null;\n this._activeItemIndex = index;\n this._typeahead?.setCurrentSelectedItemIndex(index);\n\n this._activeItem?.focus();\n previousActiveItem?.unfocus();\n\n if (options.emitChangeEvent) {\n this.change.next(this._activeItem);\n }\n\n if (this._shouldActivationFollowFocus) {\n this._activateCurrentItem();\n }\n }\n\n private _updateActiveItemIndex(newItems: T[]) {\n const activeItem = this._activeItem;\n if (!activeItem) {\n return;\n }\n\n const newIndex = newItems.findIndex(\n item => this._trackByFn(item) === this._trackByFn(activeItem),\n );\n\n if (newIndex > -1 && newIndex !== this._activeItemIndex) {\n this._activeItemIndex = newIndex;\n this._typeahead?.setCurrentSelectedItemIndex(newIndex);\n }\n }\n\n private _setTypeAhead(debounceInterval: number | boolean) {\n this._typeahead = new Typeahead(this._items, {\n debounceInterval: typeof debounceInterval === 'number' ? debounceInterval : undefined,\n skipPredicate: item => this._skipPredicateFn(item),\n });\n\n this._typeaheadSubscription = this._typeahead.selectedItem.subscribe(item => {\n this.focusItem(item);\n });\n }\n\n private _findNextAvailableItemIndex(startingIndex: number) {\n for (let i = startingIndex + 1; i < this._items.length; i++) {\n if (!this._skipPredicateFn(this._items[i])) {\n return i;\n }\n }\n return startingIndex;\n }\n\n private _findPreviousAvailableItemIndex(startingIndex: number) {\n for (let i = startingIndex - 1; i >= 0; i--) {\n if (!this._skipPredicateFn(this._items[i])) {\n return i;\n }\n }\n return startingIndex;\n }\n\n /**\n * If the item is already expanded, we collapse the item. Otherwise, we will focus the parent.\n */\n private _collapseCurrentItem() {\n if (!this._activeItem) {\n return;\n }\n\n if (this._isCurrentItemExpanded()) {\n this._activeItem.collapse();\n } else {\n const parent = this._activeItem.getParent();\n if (!parent || this._skipPredicateFn(parent as T)) {\n return;\n }\n this.focusItem(parent as T);\n }\n }\n\n /**\n * If the item is already collapsed, we expand the item. Otherwise, we will focus the first child.\n */\n private _expandCurrentItem() {\n if (!this._activeItem) {\n return;\n }\n\n if (!this._isCurrentItemExpanded()) {\n this._activeItem.expand();\n } else {\n coerceObservable(this._activeItem.getChildren())\n .pipe(take(1))\n .subscribe(children => {\n const firstChild = children.find(child => !this._skipPredicateFn(child as T));\n if (!firstChild) {\n return;\n }\n this.focusItem(firstChild as T);\n });\n }\n }\n\n private _isCurrentItemExpanded() {\n if (!this._activeItem) {\n return false;\n }\n return typeof this._activeItem.isExpanded === 'boolean'\n ? this._activeItem.isExpanded\n : this._activeItem.isExpanded();\n }\n\n private _isItemDisabled(item: TreeKeyManagerItem) {\n return typeof item.isDisabled === 'boolean' ? item.isDisabled : item.isDisabled?.();\n }\n\n /** For all items that are the same level as the current item, we expand those items. */\n private _expandAllItemsAtCurrentItemLevel() {\n if (!this._activeItem) {\n return;\n }\n\n const parent = this._activeItem.getParent();\n let itemsToExpand;\n if (!parent) {\n itemsToExpand = observableOf(this._items.filter(item => item.getParent() === null));\n } else {\n itemsToExpand = coerceObservable(parent.getChildren());\n }\n\n itemsToExpand.pipe(take(1)).subscribe(items => {\n for (const item of items) {\n item.expand();\n }\n });\n }\n\n private _activateCurrentItem() {\n this._activeItem?.activate();\n }\n}\n\n/** Injection token that determines the key manager to use. */\nexport const TREE_KEY_MANAGER = new InjectionToken<TreeKeyManagerFactory<any>>('tree-key-manager', {\n providedIn: 'root',\n factory: () => (items, options) => new TreeKeyManager(items, options),\n});\n"],"names":["observableOf"],"mappings":";;;;;;AAoBA;;;;AAIG;MACU,cAAc,CAAA;;IAEjB,gBAAgB,GAAG,CAAC,CAAC;;IAErB,WAAW,GAAa,IAAI;;IAE5B,4BAA4B,GAAG,KAAK;AAC5C;;;AAGG;IACK,sBAAsB,GAAkB,KAAK;AAErD;;;;;;;AAOG;AACK,IAAA,gBAAgB,GAAG,CAAC,KAAQ,KAAK,KAAK;;AAGtC,IAAA,UAAU,GAAyB,CAAC,IAAO,KAAK,IAAI;;IAGpD,MAAM,GAAQ,EAAE;AAEhB,IAAA,UAAU;AACV,IAAA,sBAAsB,GAAG,YAAY,CAAC,KAAK;IAE3C,kBAAkB,GAAG,KAAK;IAE1B,gBAAgB,GAAA;AACtB,QAAA,IAAI,IAAI,CAAC,kBAAkB,IAAI,IAAI,CAAC,MAAM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xB,IAAI,CAAC,MAAM,EAAE;;AAEjB,SAAC,CAAC;;IAGI,oBAAoB,GAAA;AAC1B,QAAA,IAAI,CAAC,WAAW,EAAE,QAAQ,EAAE;;AAE/B;AAED;MACa,gBAAgB,GAAG,IAAI,cAAc,CAA6B,kBAAkB,EAAE;AACjG,IAAA,UAAU,EAAE,MAAM;AAClB,IAAA,OAAO,EAAE,MAAM,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,cAAc,CAAC,KAAK,EAAE,OAAO,CAAC;AACtE,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"_tree-key-manager-chunk.mjs","sources":["../../../../../darwin_arm64-fastbuild-ST-199a4f3c4e20/bin/src/cdk/a11y/key-manager/tree-key-manager.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {InjectionToken, QueryList} from '@angular/core';\nimport {coerceObservable} from '../../coercion/private';\nimport {Observable, Subject, Subscription, isObservable, of as observableOf} from 'rxjs';\nimport {take} from 'rxjs/operators';\nimport {\n TreeKeyManagerFactory,\n TreeKeyManagerItem,\n TreeKeyManagerOptions,\n TreeKeyManagerStrategy,\n} from './tree-key-manager-strategy';\nimport {Typeahead} from './typeahead';\n\n/**\n * This class manages keyboard events for trees. If you pass it a QueryList or other list of tree\n * items, it will set the active item, focus, handle expansion and typeahead correctly when\n * keyboard events occur.\n */\nexport class TreeKeyManager<T extends TreeKeyManagerItem> implements TreeKeyManagerStrategy<T> {\n /** The index of the currently active (focused) item. */\n private _activeItemIndex = -1;\n /** The currently active (focused) item. */\n private _activeItem: T | null = null;\n /** Whether or not we activate the item when it's focused. */\n private _shouldActivationFollowFocus = false;\n /**\n * The orientation that the tree is laid out in. In `rtl` mode, the behavior of Left and\n * Right arrow are switched.\n */\n private _horizontalOrientation: 'ltr' | 'rtl' = 'ltr';\n\n /**\n * Predicate function that can be used to check whether an item should be skipped\n * by the key manager.\n *\n * The default value for this doesn't skip any elements in order to keep tree items focusable\n * when disabled. This aligns with ARIA guidelines:\n * https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/#focusabilityofdisabledcontrols.\n */\n private _skipPredicateFn = (_item: T) => false;\n\n /** Function to determine equivalent items. */\n private _trackByFn: (item: T) => unknown = (item: T) => item;\n\n /** Synchronous cache of the items to manage. */\n private _items: T[] = [];\n\n private _typeahead?: Typeahead<T>;\n private _typeaheadSubscription = Subscription.EMPTY;\n\n private _hasInitialFocused = false;\n\n private _initializeFocus(): void {\n if (this._hasInitialFocused || this._items.length === 0) {\n return;\n }\n\n let activeIndex = 0;\n for (let i = 0; i < this._items.length; i++) {\n if (!this._skipPredicateFn(this._items[i]) && !this._isItemDisabled(this._items[i])) {\n activeIndex = i;\n break;\n }\n }\n\n const activeItem = this._items[activeIndex];\n\n // Use `makeFocusable` here, because we want the item to just be focusable, not actually\n // capture the focus since the user isn't interacting with it. See #29628.\n if (activeItem.makeFocusable) {\n this._activeItem?.unfocus();\n this._activeItemIndex = activeIndex;\n this._activeItem = activeItem;\n this._typeahead?.setCurrentSelectedItemIndex(activeIndex);\n activeItem.makeFocusable();\n } else {\n // Backwards compatibility for items that don't implement `makeFocusable`.\n this.focusItem(activeIndex);\n }\n\n this._hasInitialFocused = true;\n }\n\n /**\n *\n * @param items List of TreeKeyManager options. Can be synchronous or asynchronous.\n * @param config Optional configuration options. By default, use 'ltr' horizontal orientation. By\n * default, do not skip any nodes. By default, key manager only calls `focus` method when items\n * are focused and does not call `activate`. If `typeaheadDefaultInterval` is `true`, use a\n * default interval of 200ms.\n */\n constructor(items: Observable<T[]> | QueryList<T> | T[], config: TreeKeyManagerOptions<T>) {\n // We allow for the items to be an array or Observable because, in some cases, the consumer may\n // not have access to a QueryList of the items they want to manage (e.g. when the\n // items aren't being collected via `ViewChildren` or `ContentChildren`).\n if (items instanceof QueryList) {\n this._items = items.toArray();\n items.changes.subscribe((newItems: QueryList<T>) => {\n this._items = newItems.toArray();\n this._typeahead?.setItems(this._items);\n this._updateActiveItemIndex(this._items);\n this._initializeFocus();\n });\n } else if (isObservable(items)) {\n items.subscribe(newItems => {\n this._items = newItems;\n this._typeahead?.setItems(newItems);\n this._updateActiveItemIndex(newItems);\n this._initializeFocus();\n });\n } else {\n this._items = items;\n this._initializeFocus();\n }\n\n if (typeof config.shouldActivationFollowFocus === 'boolean') {\n this._shouldActivationFollowFocus = config.shouldActivationFollowFocus;\n }\n if (config.horizontalOrientation) {\n this._horizontalOrientation = config.horizontalOrientation;\n }\n if (config.skipPredicate) {\n this._skipPredicateFn = config.skipPredicate;\n }\n if (config.trackBy) {\n this._trackByFn = config.trackBy;\n }\n if (typeof config.typeAheadDebounceInterval !== 'undefined') {\n this._setTypeAhead(config.typeAheadDebounceInterval);\n }\n }\n\n /** Stream that emits any time the focused item changes. */\n readonly change = new Subject<T | null>();\n\n /** Cleans up the key manager. */\n destroy() {\n this._typeaheadSubscription.unsubscribe();\n this._typeahead?.destroy();\n this.change.complete();\n }\n\n /**\n * Handles a keyboard event on the tree.\n * @param event Keyboard event that represents the user interaction with the tree.\n */\n onKeydown(event: KeyboardEvent) {\n const key = event.key;\n\n switch (key) {\n case 'Tab':\n // Return early here, in order to allow Tab to actually tab out of the tree\n return;\n\n case 'ArrowDown':\n this._focusNextItem();\n break;\n\n case 'ArrowUp':\n this._focusPreviousItem();\n break;\n\n case 'ArrowRight':\n this._horizontalOrientation === 'rtl'\n ? this._collapseCurrentItem()\n : this._expandCurrentItem();\n break;\n\n case 'ArrowLeft':\n this._horizontalOrientation === 'rtl'\n ? this._expandCurrentItem()\n : this._collapseCurrentItem();\n break;\n\n case 'Home':\n this._focusFirstItem();\n break;\n\n case 'End':\n this._focusLastItem();\n break;\n\n case 'Enter':\n case ' ':\n this._activateCurrentItem();\n break;\n\n default:\n if (event.key === '*') {\n this._expandAllItemsAtCurrentItemLevel();\n break;\n }\n\n this._typeahead?.handleKey(event);\n // Return here, in order to avoid preventing the default action of non-navigational\n // keys or resetting the buffer of pressed letters.\n return;\n }\n\n // Reset the typeahead since the user has used a navigational key.\n this._typeahead?.reset();\n event.preventDefault();\n }\n\n /** Index of the currently active item. */\n getActiveItemIndex(): number | null {\n return this._activeItemIndex;\n }\n\n /** The currently active item. */\n getActiveItem(): T | null {\n return this._activeItem;\n }\n\n /** Focus the first available item. */\n private _focusFirstItem(): void {\n this.focusItem(this._findNextAvailableItemIndex(-1));\n }\n\n /** Focus the last available item. */\n private _focusLastItem(): void {\n this.focusItem(this._findPreviousAvailableItemIndex(this._items.length));\n }\n\n /** Focus the next available item. */\n private _focusNextItem(): void {\n this.focusItem(this._findNextAvailableItemIndex(this._activeItemIndex));\n }\n\n /** Focus the previous available item. */\n private _focusPreviousItem(): void {\n this.focusItem(this._findPreviousAvailableItemIndex(this._activeItemIndex));\n }\n\n /**\n * Focus the provided item by index.\n * @param index The index of the item to focus.\n * @param options Additional focusing options.\n */\n focusItem(index: number, options?: {emitChangeEvent?: boolean}): void;\n focusItem(item: T, options?: {emitChangeEvent?: boolean}): void;\n focusItem(itemOrIndex: number | T, options?: {emitChangeEvent?: boolean}): void;\n focusItem(itemOrIndex: number | T, options: {emitChangeEvent?: boolean} = {}) {\n // Set default options\n options.emitChangeEvent ??= true;\n\n let index =\n typeof itemOrIndex === 'number'\n ? itemOrIndex\n : this._items.findIndex(item => this._trackByFn(item) === this._trackByFn(itemOrIndex));\n if (index < 0 || index >= this._items.length) {\n return;\n }\n const activeItem = this._items[index];\n\n // If we're just setting the same item, don't re-call activate or focus\n if (\n this._activeItem !== null &&\n this._trackByFn(activeItem) === this._trackByFn(this._activeItem)\n ) {\n return;\n }\n\n const previousActiveItem = this._activeItem;\n this._activeItem = activeItem ?? null;\n this._activeItemIndex = index;\n this._typeahead?.setCurrentSelectedItemIndex(index);\n\n this._activeItem?.focus();\n previousActiveItem?.unfocus();\n\n if (options.emitChangeEvent) {\n this.change.next(this._activeItem);\n }\n\n if (this._shouldActivationFollowFocus) {\n this._activateCurrentItem();\n }\n }\n\n private _updateActiveItemIndex(newItems: T[]) {\n const activeItem = this._activeItem;\n if (!activeItem) {\n return;\n }\n\n const newIndex = newItems.findIndex(\n item => this._trackByFn(item) === this._trackByFn(activeItem),\n );\n\n if (newIndex > -1 && newIndex !== this._activeItemIndex) {\n this._activeItemIndex = newIndex;\n this._typeahead?.setCurrentSelectedItemIndex(newIndex);\n }\n }\n\n private _setTypeAhead(debounceInterval: number | boolean) {\n this._typeahead = new Typeahead(this._items, {\n debounceInterval: typeof debounceInterval === 'number' ? debounceInterval : undefined,\n skipPredicate: item => this._skipPredicateFn(item),\n });\n\n this._typeaheadSubscription = this._typeahead.selectedItem.subscribe(item => {\n this.focusItem(item);\n });\n }\n\n private _findNextAvailableItemIndex(startingIndex: number) {\n for (let i = startingIndex + 1; i < this._items.length; i++) {\n if (!this._skipPredicateFn(this._items[i])) {\n return i;\n }\n }\n return startingIndex;\n }\n\n private _findPreviousAvailableItemIndex(startingIndex: number) {\n for (let i = startingIndex - 1; i >= 0; i--) {\n if (!this._skipPredicateFn(this._items[i])) {\n return i;\n }\n }\n return startingIndex;\n }\n\n /**\n * If the item is already expanded, we collapse the item. Otherwise, we will focus the parent.\n */\n private _collapseCurrentItem() {\n if (!this._activeItem) {\n return;\n }\n\n if (this._isCurrentItemExpanded()) {\n this._activeItem.collapse();\n } else {\n const parent = this._activeItem.getParent();\n if (!parent || this._skipPredicateFn(parent as T)) {\n return;\n }\n this.focusItem(parent as T);\n }\n }\n\n /**\n * If the item is already collapsed, we expand the item. Otherwise, we will focus the first child.\n */\n private _expandCurrentItem() {\n if (!this._activeItem) {\n return;\n }\n\n if (!this._isCurrentItemExpanded()) {\n this._activeItem.expand();\n } else {\n coerceObservable(this._activeItem.getChildren())\n .pipe(take(1))\n .subscribe(children => {\n const firstChild = children.find(child => !this._skipPredicateFn(child as T));\n if (!firstChild) {\n return;\n }\n this.focusItem(firstChild as T);\n });\n }\n }\n\n private _isCurrentItemExpanded() {\n if (!this._activeItem) {\n return false;\n }\n return typeof this._activeItem.isExpanded === 'boolean'\n ? this._activeItem.isExpanded\n : this._activeItem.isExpanded();\n }\n\n private _isItemDisabled(item: TreeKeyManagerItem) {\n return typeof item.isDisabled === 'boolean' ? item.isDisabled : item.isDisabled?.();\n }\n\n /** For all items that are the same level as the current item, we expand those items. */\n private _expandAllItemsAtCurrentItemLevel() {\n if (!this._activeItem) {\n return;\n }\n\n const parent = this._activeItem.getParent();\n let itemsToExpand;\n if (!parent) {\n itemsToExpand = observableOf(this._items.filter(item => item.getParent() === null));\n } else {\n itemsToExpand = coerceObservable(parent.getChildren());\n }\n\n itemsToExpand.pipe(take(1)).subscribe(items => {\n for (const item of items) {\n item.expand();\n }\n });\n }\n\n private _activateCurrentItem() {\n this._activeItem?.activate();\n }\n}\n\n/** Injection token that determines the key manager to use. */\nexport const TREE_KEY_MANAGER = new InjectionToken<TreeKeyManagerFactory<any>>('tree-key-manager', {\n providedIn: 'root',\n factory: () => (items, options) => new TreeKeyManager(items, options),\n});\n"],"names":["TreeKeyManager","_activeItemIndex","_horizontalOrientation","_hasInitialFocused","_items","length","activeIndex","i","_skipPredicateFn","_isItemDisabled","activeItem","_typeahead","setCurrentSelectedItemIndex","focusItem","newItems","toArray","setItems","_initializeFocus","isObservable","items","subscribe","_updateActiveItemIndex","config","shouldActivationFollowFocus","_shouldActivationFollowFocus","horizontalOrientation","skipPredicate","_trackByFn","trackBy","typeAheadDebounceInterval","_setTypeAhead","Subject","_typeaheadSubscription","unsubscribe","onKeydown","event","key","_focusNextItem","_expandCurrentItem","_collapseCurrentItem","_focusFirstItem","_focusLastItem","_activateCurrentItem","_expandAllItemsAtCurrentItemLevel","handleKey","reset","getActiveItem","_findNextAvailableItemIndex","_focusPreviousItem","itemOrIndex","options","findIndex","item","index","_activeItem","previousActiveItem","unfocus","emitChangeEvent","newIndex","Typeahead","debounceInterval","undefined","selectedItem","startingIndex","_findPreviousAvailableItemIndex","parent","getParent"],"mapp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,+BAAAA,CAAAD,aAAA,EAAA;aAEMxD,CAAA,GAAAwD,aAAA,iBAA0B,EAAA;AAChC,MAAA,IAAA,CAAA,IAAA,CAAAvD;;;;;AAKA;;AAMA,IAAA,IAAA,MAAA8C,WAAA,EAAA;AACF,MAAA;;;;;AASA,MAAA,MAAUW,MAAA,GAAA,IAAQ,CAAAX,WAAA,CAAAY,SAAA,EAAA;AAClB,MAAA,IAAA,CAAAD,MAAS,IAAA,IAAA,CAAAzD,gBAAA,CAAAyD,MAAA,CAAA,EAAA;AACT,QAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -3,85 +3,63 @@ import { tap, debounceTime, filter, map } from 'rxjs/operators';
|
|
|
3
3
|
import { A, Z, ZERO, NINE } from './_keycodes-chunk.mjs';
|
|
4
4
|
|
|
5
5
|
const DEFAULT_TYPEAHEAD_DEBOUNCE_INTERVAL_MS = 200;
|
|
6
|
-
/**
|
|
7
|
-
* Selects items based on keyboard inputs. Implements the typeahead functionality of
|
|
8
|
-
* `role="listbox"` or `role="tree"` and other related roles.
|
|
9
|
-
*/
|
|
10
6
|
class Typeahead {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
: DEFAULT_TYPEAHEAD_DEBOUNCE_INTERVAL_MS;
|
|
23
|
-
if (config?.skipPredicate) {
|
|
24
|
-
this._skipPredicateFn = config.skipPredicate;
|
|
25
|
-
}
|
|
26
|
-
if ((typeof ngDevMode === 'undefined' || ngDevMode) &&
|
|
27
|
-
initialItems.length &&
|
|
28
|
-
initialItems.some(item => typeof item.getLabel !== 'function')) {
|
|
29
|
-
throw new Error('KeyManager items in typeahead mode must implement the `getLabel` method.');
|
|
30
|
-
}
|
|
31
|
-
this.setItems(initialItems);
|
|
32
|
-
this._setupKeyHandler(typeAheadInterval);
|
|
7
|
+
_letterKeyStream = new Subject();
|
|
8
|
+
_items = [];
|
|
9
|
+
_selectedItemIndex = -1;
|
|
10
|
+
_pressedLetters = [];
|
|
11
|
+
_skipPredicateFn;
|
|
12
|
+
_selectedItem = new Subject();
|
|
13
|
+
selectedItem = this._selectedItem;
|
|
14
|
+
constructor(initialItems, config) {
|
|
15
|
+
const typeAheadInterval = typeof config?.debounceInterval === 'number' ? config.debounceInterval : DEFAULT_TYPEAHEAD_DEBOUNCE_INTERVAL_MS;
|
|
16
|
+
if (config?.skipPredicate) {
|
|
17
|
+
this._skipPredicateFn = config.skipPredicate;
|
|
33
18
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
this._letterKeyStream.complete();
|
|
37
|
-
this._selectedItem.complete();
|
|
19
|
+
if ((typeof ngDevMode === 'undefined' || ngDevMode) && initialItems.length && initialItems.some(item => typeof item.getLabel !== 'function')) {
|
|
20
|
+
throw new Error('KeyManager items in typeahead mode must implement the `getLabel` method.');
|
|
38
21
|
}
|
|
39
|
-
|
|
40
|
-
|
|
22
|
+
this.setItems(initialItems);
|
|
23
|
+
this._setupKeyHandler(typeAheadInterval);
|
|
24
|
+
}
|
|
25
|
+
destroy() {
|
|
26
|
+
this._pressedLetters = [];
|
|
27
|
+
this._letterKeyStream.complete();
|
|
28
|
+
this._selectedItem.complete();
|
|
29
|
+
}
|
|
30
|
+
setCurrentSelectedItemIndex(index) {
|
|
31
|
+
this._selectedItemIndex = index;
|
|
32
|
+
}
|
|
33
|
+
setItems(items) {
|
|
34
|
+
this._items = items;
|
|
35
|
+
}
|
|
36
|
+
handleKey(event) {
|
|
37
|
+
const keyCode = event.keyCode;
|
|
38
|
+
if (event.key && event.key.length === 1) {
|
|
39
|
+
this._letterKeyStream.next(event.key.toLocaleUpperCase());
|
|
40
|
+
} else if (keyCode >= A && keyCode <= Z || keyCode >= ZERO && keyCode <= NINE) {
|
|
41
|
+
this._letterKeyStream.next(String.fromCharCode(keyCode));
|
|
41
42
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
43
|
+
}
|
|
44
|
+
isTyping() {
|
|
45
|
+
return this._pressedLetters.length > 0;
|
|
46
|
+
}
|
|
47
|
+
reset() {
|
|
48
|
+
this._pressedLetters = [];
|
|
49
|
+
}
|
|
50
|
+
_setupKeyHandler(typeAheadInterval) {
|
|
51
|
+
this._letterKeyStream.pipe(tap(letter => this._pressedLetters.push(letter)), debounceTime(typeAheadInterval), filter(() => this._pressedLetters.length > 0), map(() => this._pressedLetters.join('').toLocaleUpperCase())).subscribe(inputString => {
|
|
52
|
+
for (let i = 1; i < this._items.length + 1; i++) {
|
|
53
|
+
const index = (this._selectedItemIndex + i) % this._items.length;
|
|
54
|
+
const item = this._items[index];
|
|
55
|
+
if (!this._skipPredicateFn?.(item) && item.getLabel?.().toLocaleUpperCase().trim().indexOf(inputString) === 0) {
|
|
56
|
+
this._selectedItem.next(item);
|
|
57
|
+
break;
|
|
54
58
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
/** Resets the currently stored sequence of typed letters. */
|
|
61
|
-
reset() {
|
|
62
|
-
this._pressedLetters = [];
|
|
63
|
-
}
|
|
64
|
-
_setupKeyHandler(typeAheadInterval) {
|
|
65
|
-
// Debounce the presses of non-navigational keys, collect the ones that correspond to letters
|
|
66
|
-
// and convert those letters back into a string. Afterwards find the first item that starts
|
|
67
|
-
// with that string and select it.
|
|
68
|
-
this._letterKeyStream
|
|
69
|
-
.pipe(tap(letter => this._pressedLetters.push(letter)), debounceTime(typeAheadInterval), filter(() => this._pressedLetters.length > 0), map(() => this._pressedLetters.join('').toLocaleUpperCase()))
|
|
70
|
-
.subscribe(inputString => {
|
|
71
|
-
// Start at 1 because we want to start searching at the item immediately
|
|
72
|
-
// following the current active item.
|
|
73
|
-
for (let i = 1; i < this._items.length + 1; i++) {
|
|
74
|
-
const index = (this._selectedItemIndex + i) % this._items.length;
|
|
75
|
-
const item = this._items[index];
|
|
76
|
-
if (!this._skipPredicateFn?.(item) &&
|
|
77
|
-
item.getLabel?.().toLocaleUpperCase().trim().indexOf(inputString) === 0) {
|
|
78
|
-
this._selectedItem.next(item);
|
|
79
|
-
break;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
this._pressedLetters = [];
|
|
83
|
-
});
|
|
84
|
-
}
|
|
59
|
+
}
|
|
60
|
+
this._pressedLetters = [];
|
|
61
|
+
});
|
|
62
|
+
}
|
|
85
63
|
}
|
|
86
64
|
|
|
87
65
|
export { Typeahead };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_typeahead-chunk.mjs","sources":["../../../../../darwin_arm64-fastbuild-ST-199a4f3c4e20/bin/src/cdk/a11y/key-manager/typeahead.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {A, NINE, Z, ZERO} from '../../keycodes';\nimport {Subject, Observable} from 'rxjs';\nimport {debounceTime, filter, map, tap} from 'rxjs/operators';\n\nconst DEFAULT_TYPEAHEAD_DEBOUNCE_INTERVAL_MS = 200;\n\ninterface TypeaheadItem {\n getLabel?(): string;\n}\n\ninterface TypeaheadConfig<T> {\n debounceInterval?: number;\n skipPredicate?: (item: T) => boolean | undefined;\n}\n\n/**\n * Selects items based on keyboard inputs. Implements the typeahead functionality of\n * `role=\"listbox\"` or `role=\"tree\"` and other related roles.\n */\nexport class Typeahead<T extends TypeaheadItem> {\n private readonly _letterKeyStream = new Subject<string>();\n private _items: readonly T[] = [];\n private _selectedItemIndex = -1;\n\n /** Buffer for the letters that the user has pressed */\n private _pressedLetters: string[] = [];\n\n private _skipPredicateFn?: (item: T) => boolean | undefined;\n\n private readonly _selectedItem = new Subject<T>();\n readonly selectedItem: Observable<T> = this._selectedItem;\n\n constructor(initialItems: readonly T[], config?: TypeaheadConfig<T>) {\n const typeAheadInterval =\n typeof config?.debounceInterval === 'number'\n ? config.debounceInterval\n : DEFAULT_TYPEAHEAD_DEBOUNCE_INTERVAL_MS;\n\n if (config?.skipPredicate) {\n this._skipPredicateFn = config.skipPredicate;\n }\n\n if (\n (typeof ngDevMode === 'undefined' || ngDevMode) &&\n initialItems.length &&\n initialItems.some(item => typeof item.getLabel !== 'function')\n ) {\n throw new Error('KeyManager items in typeahead mode must implement the `getLabel` method.');\n }\n\n this.setItems(initialItems);\n this._setupKeyHandler(typeAheadInterval);\n }\n\n destroy() {\n this._pressedLetters = [];\n this._letterKeyStream.complete();\n this._selectedItem.complete();\n }\n\n setCurrentSelectedItemIndex(index: number) {\n this._selectedItemIndex = index;\n }\n\n setItems(items: readonly T[]) {\n this._items = items;\n }\n\n handleKey(event: KeyboardEvent): void {\n const keyCode = event.keyCode;\n\n // Attempt to use the `event.key` which also maps it to the user's keyboard language,\n // otherwise fall back to resolving alphanumeric characters via the keyCode.\n if (event.key && event.key.length === 1) {\n this._letterKeyStream.next(event.key.toLocaleUpperCase());\n } else if ((keyCode >= A && keyCode <= Z) || (keyCode >= ZERO && keyCode <= NINE)) {\n this._letterKeyStream.next(String.fromCharCode(keyCode));\n }\n }\n\n /** Gets whether the user is currently typing into the manager using the typeahead feature. */\n isTyping(): boolean {\n return this._pressedLetters.length > 0;\n }\n\n /** Resets the currently stored sequence of typed letters. */\n reset(): void {\n this._pressedLetters = [];\n }\n\n private _setupKeyHandler(typeAheadInterval: number) {\n // Debounce the presses of non-navigational keys, collect the ones that correspond to letters\n // and convert those letters back into a string. Afterwards find the first item that starts\n // with that string and select it.\n this._letterKeyStream\n .pipe(\n tap(letter => this._pressedLetters.push(letter)),\n debounceTime(typeAheadInterval),\n filter(() => this._pressedLetters.length > 0),\n map(() => this._pressedLetters.join('').toLocaleUpperCase()),\n )\n .subscribe(inputString => {\n // Start at 1 because we want to start searching at the item immediately\n // following the current active item.\n for (let i = 1; i < this._items.length + 1; i++) {\n const index = (this._selectedItemIndex + i) % this._items.length;\n const item = this._items[index];\n\n if (\n !this._skipPredicateFn?.(item) &&\n item.getLabel?.().toLocaleUpperCase().trim().indexOf(inputString) === 0\n ) {\n this._selectedItem.next(item);\n break;\n }\n }\n\n this._pressedLetters = [];\n });\n }\n}\n"],"names":[
|
|
1
|
+
{"version":3,"file":"_typeahead-chunk.mjs","sources":["../../../../../darwin_arm64-fastbuild-ST-199a4f3c4e20/bin/src/cdk/a11y/key-manager/typeahead.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {A, NINE, Z, ZERO} from '../../keycodes';\nimport {Subject, Observable} from 'rxjs';\nimport {debounceTime, filter, map, tap} from 'rxjs/operators';\n\nconst DEFAULT_TYPEAHEAD_DEBOUNCE_INTERVAL_MS = 200;\n\ninterface TypeaheadItem {\n getLabel?(): string;\n}\n\ninterface TypeaheadConfig<T> {\n debounceInterval?: number;\n skipPredicate?: (item: T) => boolean | undefined;\n}\n\n/**\n * Selects items based on keyboard inputs. Implements the typeahead functionality of\n * `role=\"listbox\"` or `role=\"tree\"` and other related roles.\n */\nexport class Typeahead<T extends TypeaheadItem> {\n private readonly _letterKeyStream = new Subject<string>();\n private _items: readonly T[] = [];\n private _selectedItemIndex = -1;\n\n /** Buffer for the letters that the user has pressed */\n private _pressedLetters: string[] = [];\n\n private _skipPredicateFn?: (item: T) => boolean | undefined;\n\n private readonly _selectedItem = new Subject<T>();\n readonly selectedItem: Observable<T> = this._selectedItem;\n\n constructor(initialItems: readonly T[], config?: TypeaheadConfig<T>) {\n const typeAheadInterval =\n typeof config?.debounceInterval === 'number'\n ? config.debounceInterval\n : DEFAULT_TYPEAHEAD_DEBOUNCE_INTERVAL_MS;\n\n if (config?.skipPredicate) {\n this._skipPredicateFn = config.skipPredicate;\n }\n\n if (\n (typeof ngDevMode === 'undefined' || ngDevMode) &&\n initialItems.length &&\n initialItems.some(item => typeof item.getLabel !== 'function')\n ) {\n throw new Error('KeyManager items in typeahead mode must implement the `getLabel` method.');\n }\n\n this.setItems(initialItems);\n this._setupKeyHandler(typeAheadInterval);\n }\n\n destroy() {\n this._pressedLetters = [];\n this._letterKeyStream.complete();\n this._selectedItem.complete();\n }\n\n setCurrentSelectedItemIndex(index: number) {\n this._selectedItemIndex = index;\n }\n\n setItems(items: readonly T[]) {\n this._items = items;\n }\n\n handleKey(event: KeyboardEvent): void {\n const keyCode = event.keyCode;\n\n // Attempt to use the `event.key` which also maps it to the user's keyboard language,\n // otherwise fall back to resolving alphanumeric characters via the keyCode.\n if (event.key && event.key.length === 1) {\n this._letterKeyStream.next(event.key.toLocaleUpperCase());\n } else if ((keyCode >= A && keyCode <= Z) || (keyCode >= ZERO && keyCode <= NINE)) {\n this._letterKeyStream.next(String.fromCharCode(keyCode));\n }\n }\n\n /** Gets whether the user is currently typing into the manager using the typeahead feature. */\n isTyping(): boolean {\n return this._pressedLetters.length > 0;\n }\n\n /** Resets the currently stored sequence of typed letters. */\n reset(): void {\n this._pressedLetters = [];\n }\n\n private _setupKeyHandler(typeAheadInterval: number) {\n // Debounce the presses of non-navigational keys, collect the ones that correspond to letters\n // and convert those letters back into a string. Afterwards find the first item that starts\n // with that string and select it.\n this._letterKeyStream\n .pipe(\n tap(letter => this._pressedLetters.push(letter)),\n debounceTime(typeAheadInterval),\n filter(() => this._pressedLetters.length > 0),\n map(() => this._pressedLetters.join('').toLocaleUpperCase()),\n )\n .subscribe(inputString => {\n // Start at 1 because we want to start searching at the item immediately\n // following the current active item.\n for (let i = 1; i < this._items.length + 1; i++) {\n const index = (this._selectedItemIndex + i) % this._items.length;\n const item = this._items[index];\n\n if (\n !this._skipPredicateFn?.(item) &&\n item.getLabel?.().toLocaleUpperCase().trim().indexOf(inputString) === 0\n ) {\n this._selectedItem.next(item);\n break;\n }\n }\n\n this._pressedLetters = [];\n });\n }\n}\n"],"names":["Typeahead","Subject","_skipPredicateFn","_selectedItem","selectedItem","constructor","initialItems","config","typeAheadInterval","debounceInterval","DEFAULT_TYPEAHEAD_DEBOUNCE_INTERVAL_MS","skipPredicate","ngDevMode","length","some","item","getLabel","Error","setItems","_setupKeyHandler","_pressedLetters","_letterKeyStream","complete","setCurrentSelectedItemIndex","index","_selectedItemIndex","items","_items","handleKey","event","key","next","toLocaleUpperCase","keyCode","A","Z","ZERO","NINE","String","fromCharCode","isTyping"],"mappings":";;;;;AA4BmB,MAAAA,SAA8B,CAAA;kBACjC,GAAmB,IAAAC,OAAA,EAAA;QAGsB,GAAA,EAAA;;;EAqBnDC,gBAAA;AAEAC,EAAAA,aAAA,OAAUF,OAAA,EAAA;EACZG,YAAA,GAAA,IAAA,CAAAD,aAAA;EAEAE,WAA2BA,CAAAC,YAAA,EAAAC,MAAA,EAAA;IAC3B,MAAAC,iBAAsB,GAAAD,OAAAA,MAAA,EAAAE,gBAAA,0CAItBC,sCAAyB;IAEzB,IAAAH,MAAA,EAAkBI,aAAW,EAAA;AAG/B,MAAA,IAAA,CAA4BT,gBAAa,GAAAK,MAAA,CAAAI,aAAA;AACvC;AAGF,IAAA,IAAA,CAAA,OAA4BC,SAAA,KAAA,WAAA,IAAAA,SAAA,KAC1BN,YAAA,CAAAO,MAAmB,IAGrBP,YAA8B,CAAAQ,IAAA,CAAAC,IAAA,IAAA,OAAAA,IAAA,CAAAC,QAAA,KAAA,UAAA,CAAA,EAAA;MAC5B,MAAA,IAAAC,KAAA,CAA6B,0EAAA,CAAA;;QAI7B,CAAAC,QAAA,CAAAZ,YAAsB,CAAA;IACpB,IAAA,CAAAa,gBAAA,CAAAX,iBAAA,CAAA;;;AAIJ,IAAA,IAAA,CAAAY,eAAA,GAAA,EAAA;QAGQ,CAAAC,gBAAA,CAAAC,QAAA,EAAA;IACN,IAAA,CAAAnB,aAAA,CAAAmB,QAAA,EAAA;;AAIGC,EAAAA,2BAAAA,CAAAC,KAAA,EAAA;IACH,IAAAC,CAAAA,kBAAA,GAAAD,KAAA;AAGM;AACNN,EAAAA,QAAAA,CAA6FQ,KAAA,EAAA;QAC7F,CAA2FC,MAAA,GAAAD,KAAA;;AAE3FE,EAAAA,SAAAA,CAAAC,KAAA,EAAA;iCAO2B;IAIrB,IAAAA,KAAA,CAAcC,GAAA,IAAAD,KAAA,CAAAC,GAAA,CAAAjB,MAAA,KAAA,CAAA,EAAA;2BACR,CAAAkB,IAAA,CAAAF,KAAA,CAAAC,GAAA,CAAAE,iBAAA,EAAA,CAAA;AAEN,KAAA,MAIE,IAAAC,OAAkB,IAAAC,CAAA,IAAAD,OAAA,IAAAE,CAAA,IAAAF,OAAA,IAAAG,IAAA,IAAAH,OAAA,IAAAI,IAAA,EAAA;2BACZ,CAAAN,IAAA,CAAAO,MAAA,CAAAC,YAAA,CAAAN,OAAA,CAAA,CAAA;;;UAMhBO,GAAA;IACD,OAAA,IAAA,CAAApB,eAAA,CAAAP,MAAA,GAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,49 +1,52 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { Injectable } from '@angular/core';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* Class to coordinate unique selection based on name.
|
|
6
|
-
* Intended to be consumed as an Angular service.
|
|
7
|
-
* This service is needed because native radio change events are only fired on the item currently
|
|
8
|
-
* being selected, and we still need to uncheck the previous selection.
|
|
9
|
-
*
|
|
10
|
-
* This service does not *store* any IDs and names because they may change at any time, so it is
|
|
11
|
-
* less error-prone if they are simply passed through when the events occur.
|
|
12
|
-
*/
|
|
13
4
|
class UniqueSelectionDispatcher {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
* @param name Name of the item.
|
|
19
|
-
*/
|
|
20
|
-
notify(id, name) {
|
|
21
|
-
for (let listener of this._listeners) {
|
|
22
|
-
listener(id, name);
|
|
23
|
-
}
|
|
5
|
+
_listeners = [];
|
|
6
|
+
notify(id, name) {
|
|
7
|
+
for (let listener of this._listeners) {
|
|
8
|
+
listener(id, name);
|
|
24
9
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
10
|
+
}
|
|
11
|
+
listen(listener) {
|
|
12
|
+
this._listeners.push(listener);
|
|
13
|
+
return () => {
|
|
14
|
+
this._listeners = this._listeners.filter(registered => {
|
|
15
|
+
return listener !== registered;
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
ngOnDestroy() {
|
|
20
|
+
this._listeners = [];
|
|
21
|
+
}
|
|
22
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
23
|
+
minVersion: "12.0.0",
|
|
24
|
+
version: "20.2.0-next.2",
|
|
25
|
+
ngImport: i0,
|
|
26
|
+
type: UniqueSelectionDispatcher,
|
|
27
|
+
deps: [],
|
|
28
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
29
|
+
});
|
|
30
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
31
|
+
minVersion: "12.0.0",
|
|
32
|
+
version: "20.2.0-next.2",
|
|
33
|
+
ngImport: i0,
|
|
34
|
+
type: UniqueSelectionDispatcher,
|
|
35
|
+
providedIn: 'root'
|
|
36
|
+
});
|
|
42
37
|
}
|
|
43
|
-
i0.ɵɵngDeclareClassMetadata({
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
39
|
+
minVersion: "12.0.0",
|
|
40
|
+
version: "20.2.0-next.2",
|
|
41
|
+
ngImport: i0,
|
|
42
|
+
type: UniqueSelectionDispatcher,
|
|
43
|
+
decorators: [{
|
|
44
|
+
type: Injectable,
|
|
45
|
+
args: [{
|
|
46
|
+
providedIn: 'root'
|
|
47
|
+
}]
|
|
48
|
+
}]
|
|
49
|
+
});
|
|
47
50
|
|
|
48
51
|
export { UniqueSelectionDispatcher };
|
|
49
52
|
//# sourceMappingURL=_unique-selection-dispatcher-chunk.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_unique-selection-dispatcher-chunk.mjs","sources":["../../../../../darwin_arm64-fastbuild-ST-199a4f3c4e20/bin/src/cdk/collections/unique-selection-dispatcher.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {Injectable, OnDestroy} from '@angular/core';\n\n// Users of the Dispatcher never need to see this type, but TypeScript requires it to be exported.\nexport type UniqueSelectionDispatcherListener = (id: string, name: string) => void;\n\n/**\n * Class to coordinate unique selection based on name.\n * Intended to be consumed as an Angular service.\n * This service is needed because native radio change events are only fired on the item currently\n * being selected, and we still need to uncheck the previous selection.\n *\n * This service does not *store* any IDs and names because they may change at any time, so it is\n * less error-prone if they are simply passed through when the events occur.\n */\n@Injectable({providedIn: 'root'})\nexport class UniqueSelectionDispatcher implements OnDestroy {\n private _listeners: UniqueSelectionDispatcherListener[] = [];\n\n /**\n * Notify other items that selection for the given name has been set.\n * @param id ID of the item.\n * @param name Name of the item.\n */\n notify(id: string, name: string) {\n for (let listener of this._listeners) {\n listener(id, name);\n }\n }\n\n /**\n * Listen for future changes to item selection.\n * @return Function used to deregister listener\n */\n listen(listener: UniqueSelectionDispatcherListener): () => void {\n this._listeners.push(listener);\n return () => {\n this._listeners = this._listeners.filter((registered: UniqueSelectionDispatcherListener) => {\n return listener !== registered;\n });\n };\n }\n\n ngOnDestroy() {\n this._listeners = [];\n }\n}\n"],"names":[
|
|
1
|
+
{"version":3,"file":"_unique-selection-dispatcher-chunk.mjs","sources":["../../../../../darwin_arm64-fastbuild-ST-199a4f3c4e20/bin/src/cdk/collections/unique-selection-dispatcher.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {Injectable, OnDestroy} from '@angular/core';\n\n// Users of the Dispatcher never need to see this type, but TypeScript requires it to be exported.\nexport type UniqueSelectionDispatcherListener = (id: string, name: string) => void;\n\n/**\n * Class to coordinate unique selection based on name.\n * Intended to be consumed as an Angular service.\n * This service is needed because native radio change events are only fired on the item currently\n * being selected, and we still need to uncheck the previous selection.\n *\n * This service does not *store* any IDs and names because they may change at any time, so it is\n * less error-prone if they are simply passed through when the events occur.\n */\n@Injectable({providedIn: 'root'})\nexport class UniqueSelectionDispatcher implements OnDestroy {\n private _listeners: UniqueSelectionDispatcherListener[] = [];\n\n /**\n * Notify other items that selection for the given name has been set.\n * @param id ID of the item.\n * @param name Name of the item.\n */\n notify(id: string, name: string) {\n for (let listener of this._listeners) {\n listener(id, name);\n }\n }\n\n /**\n * Listen for future changes to item selection.\n * @return Function used to deregister listener\n */\n listen(listener: UniqueSelectionDispatcherListener): () => void {\n this._listeners.push(listener);\n return () => {\n this._listeners = this._listeners.filter((registered: UniqueSelectionDispatcherListener) => {\n return listener !== registered;\n });\n };\n }\n\n ngOnDestroy() {\n this._listeners = [];\n }\n}\n"],"names":["notify","id","name","listener","_listeners","push"],"mappings":";;;;;EAqCEA,MAAAA,CAAAC,EAAA,EAAAC,IAAA,EAAA;;MAGGC,QAAA,CAAAF,EAAA,EAAAC,IAAA,CAAA;;;iBAOD,EAAC;AACH,IAAA,IAAA,CAAAE,UAAA,CAAAC,IAAA,CAAAF,QAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|