| 38 | |
| 39 | /** The UI pattern for a grid, handling keyboard navigation, focus, and selection. */ |
| 40 | export class GridPattern { |
| 41 | /** The underlying grid behavior that this pattern is built on. */ |
| 42 | readonly gridBehavior: Grid<GridCellPattern>; |
| 43 | |
| 44 | /** The cells in the grid. */ |
| 45 | readonly cells = computed(() => this.gridBehavior.data.cells()); |
| 46 | |
| 47 | /** The tab index for the grid. */ |
| 48 | readonly tabIndex = computed(() => this.gridBehavior.gridTabIndex()); |
| 49 | |
| 50 | /** Whether the grid is disabled. */ |
| 51 | readonly disabled = computed(() => this.gridBehavior.gridDisabled()); |
| 52 | |
| 53 | /** Whether the grid is multi-selectable. */ |
| 54 | readonly multiSelectable = computed(() => |
| 55 | this.inputs.enableSelection() ? this.inputs.multi() : undefined, |
| 56 | ); |
| 57 | |
| 58 | /** The ID of the currently active descendant cell. */ |
| 59 | readonly activeDescendant = computed(() => this.gridBehavior.activeDescendant()); |
| 60 | |
| 61 | /** The currently active cell. */ |
| 62 | readonly activeCell = computed(() => this.gridBehavior.focusBehavior.activeCell()); |
| 63 | |
| 64 | /** The current selection anchor cell. */ |
| 65 | readonly anchorCell: SignalLike<GridCellPattern | undefined> = computed(() => |
| 66 | this.multiSelectable() ? this.gridBehavior.selectionAnchorCell() : undefined, |
| 67 | ); |
| 68 | |
| 69 | /** Whether to pause grid navigation and give the keyboard control to cell or widget. */ |
| 70 | readonly pauseNavigation: SignalLike<boolean> = computed(() => |
| 71 | this.gridBehavior.data |
| 72 | .cells() |
| 73 | .flat() |
| 74 | .reduce((res, c) => res || c.isActivated(), false), |
| 75 | ); |
| 76 | |
| 77 | /** Whether the focus is in the grid. */ |
| 78 | readonly isFocused = signal(false); |
| 79 | |
| 80 | /** Whether the grid has received focus once. */ |
| 81 | readonly hasBeenInteracted = signal(false); |
| 82 | |
| 83 | /** Whether the user is currently dragging to select a range of cells. */ |
| 84 | readonly dragging = signal(false); |
| 85 | |
| 86 | /** The key for navigating to the previous column. */ |
| 87 | readonly prevColKey = computed(() => |
| 88 | this.inputs.textDirection() === 'rtl' ? 'ArrowRight' : 'ArrowLeft', |
| 89 | ); |
| 90 | |
| 91 | /** The key for navigating to the next column. */ |
| 92 | readonly nextColKey = computed(() => |
| 93 | this.inputs.textDirection() === 'rtl' ? 'ArrowLeft' : 'ArrowRight', |
| 94 | ); |
| 95 | |
| 96 | /** The keydown event manager for the grid. */ |
| 97 | readonly keydown = computed(() => { |
nothing calls this directly
no test coverage detected
searching dependent graphs…