| 148 | |
| 149 | /** Controls the state and interactions of a tree view. */ |
| 150 | export class TreePattern<V> implements TreeInputs<V> { |
| 151 | /** The tree behavior for the tree. */ |
| 152 | readonly treeBehavior: Tree<TreeItemPattern<V>, V>; |
| 153 | |
| 154 | /** Whether the tree has been interacted with. */ |
| 155 | readonly hasBeenInteracted = signal(false); |
| 156 | |
| 157 | /** The root level is 0. */ |
| 158 | readonly level = () => 0; |
| 159 | |
| 160 | /** The root is always expanded. */ |
| 161 | readonly expanded = () => true; |
| 162 | |
| 163 | /** The root is always visible. */ |
| 164 | readonly visible = () => true; |
| 165 | |
| 166 | /** The tab index of the tree. */ |
| 167 | readonly tabIndex: SignalLike<-1 | 0> = computed(() => this.treeBehavior.tabIndex()); |
| 168 | |
| 169 | /** The id of the current active item. */ |
| 170 | readonly activeDescendant = computed(() => this.treeBehavior.activeDescendant()); |
| 171 | |
| 172 | /** The direct children of the root (top-level tree items). */ |
| 173 | readonly children = computed(() => |
| 174 | this.inputs.items().filter(item => item.level() === this.level() + 1), |
| 175 | ); |
| 176 | |
| 177 | /** Whether the tree selection follows focus. */ |
| 178 | readonly followFocus = computed(() => this.inputs.selectionMode() === 'follow'); |
| 179 | |
| 180 | /** Whether the tree direction is RTL. */ |
| 181 | readonly isRtl = computed(() => this.textDirection() === 'rtl'); |
| 182 | |
| 183 | /** The key for navigating to the previous item. */ |
| 184 | readonly prevKey = computed(() => { |
| 185 | if (this.inputs.orientation() === 'vertical') { |
| 186 | return 'ArrowUp'; |
| 187 | } |
| 188 | return this.isRtl() ? 'ArrowRight' : 'ArrowLeft'; |
| 189 | }); |
| 190 | |
| 191 | /** The key for navigating to the next item. */ |
| 192 | readonly nextKey = computed(() => { |
| 193 | if (this.inputs.orientation() === 'vertical') { |
| 194 | return 'ArrowDown'; |
| 195 | } |
| 196 | return this.isRtl() ? 'ArrowLeft' : 'ArrowRight'; |
| 197 | }); |
| 198 | |
| 199 | /** The key for collapsing an item or moving to its parent. */ |
| 200 | readonly collapseKey = computed(() => { |
| 201 | if (this.inputs.orientation() === 'horizontal') { |
| 202 | return 'ArrowUp'; |
| 203 | } |
| 204 | return this.isRtl() ? 'ArrowRight' : 'ArrowLeft'; |
| 205 | }); |
| 206 | |
| 207 | /** The key for expanding an item or moving to its first child. */ |
nothing calls this directly
no test coverage detected
searching dependent graphs…