|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright Google LLC All Rights Reserved. |
| 4 | + * |
| 5 | + * Use of this source code is governed by an MIT-style license that can be |
| 6 | + * found in the LICENSE file at https://angular.io/license |
| 7 | + */ |
| 8 | + |
| 9 | +import {Subject} from 'rxjs'; |
| 10 | +import { |
| 11 | + TREE_KEY_MANAGER, |
| 12 | + TreeKeyManagerFactory, |
| 13 | + TreeKeyManagerItem, |
| 14 | + TreeKeyManagerStrategy, |
| 15 | +} from './tree-key-manager'; |
| 16 | + |
| 17 | +/** |
| 18 | + * @docs-private |
| 19 | + * |
| 20 | + * @deprecated LegacyTreeKeyManager deprecated. Use TreeKeyManager or inject a |
| 21 | + * TreeKeyManagerStrategy instead. To be removed in a future version. |
| 22 | + * |
| 23 | + * @breaking-change 19.0.0 |
| 24 | + */ |
| 25 | +// LegacyTreeKeyManager is a "noop" implementation of TreeKeyMangerStrategy. Methods are noops. Does |
| 26 | +// not emit to streams. |
| 27 | +// |
| 28 | +// Used for applications built before TreeKeyManager to opt-out of TreeKeyManager and revert to |
| 29 | +// legacy behavior. |
| 30 | +export class LegacyTreeKeyManager<T extends TreeKeyManagerItem> |
| 31 | + implements TreeKeyManagerStrategy<T> |
| 32 | +{ |
| 33 | + get _isLegacyTreeKeyManager() { |
| 34 | + return true; |
| 35 | + } |
| 36 | + |
| 37 | + // Provide change as required by TreeKeyManagerStrategy. LegacyTreeKeyManager is a "noop" |
| 38 | + // implementation that does not emit to streams. |
| 39 | + readonly change = new Subject<T | null>(); |
| 40 | + |
| 41 | + onKeydown() { |
| 42 | + // noop |
| 43 | + } |
| 44 | + |
| 45 | + getActiveItemIndex() { |
| 46 | + // Always return null. LegacyTreeKeyManager is a "noop" implementation that does not maintain |
| 47 | + // the active item. |
| 48 | + return null; |
| 49 | + } |
| 50 | + |
| 51 | + getActiveItem() { |
| 52 | + // Always return null. LegacyTreeKeyManager is a "noop" implementation that does not maintain |
| 53 | + // the active item. |
| 54 | + return null; |
| 55 | + } |
| 56 | + |
| 57 | + onInitialFocus() { |
| 58 | + // noop |
| 59 | + } |
| 60 | + |
| 61 | + focusItem() { |
| 62 | + // noop |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +/** |
| 67 | + * @docs-private |
| 68 | + * |
| 69 | + * @deprecated LegacyTreeKeyManager deprecated. Use TreeKeyManager or inject a |
| 70 | + * TreeKeyManagerStrategy instead. To be removed in a future version. |
| 71 | + * |
| 72 | + * @breaking-change 19.0.0 |
| 73 | + */ |
| 74 | +export function LEGACY_TREE_KEY_MANAGER_FACTORY< |
| 75 | + T extends TreeKeyManagerItem, |
| 76 | +>(): TreeKeyManagerFactory<T> { |
| 77 | + return () => new LegacyTreeKeyManager<T>(); |
| 78 | +} |
| 79 | + |
| 80 | +/** |
| 81 | + * @docs-private |
| 82 | + * |
| 83 | + * @deprecated LegacyTreeKeyManager deprecated. Use TreeKeyManager or inject a |
| 84 | + * TreeKeyManagerStrategy instead. To be removed in a future version. |
| 85 | + * |
| 86 | + * @breaking-change 19.0.0 |
| 87 | + */ |
| 88 | +export const LEGACY_TREE_KEY_MANAGER_FACTORY_PROVIDER = { |
| 89 | + provide: TREE_KEY_MANAGER, |
| 90 | + useFactory: LEGACY_TREE_KEY_MANAGER_FACTORY, |
| 91 | +}; |
0 commit comments