| 34 | * Represents an item in a Tree. |
| 35 | */ |
| 36 | export class TreeItemPattern<V> implements TreeItem<V, TreeItemPattern<V>> { |
| 37 | /** A unique identifier for this item. */ |
| 38 | readonly id: SignalLike<string> = () => this.inputs.id(); |
| 39 | |
| 40 | /** The value of this item. */ |
| 41 | readonly value: SignalLike<V> = () => this.inputs.value(); |
| 42 | |
| 43 | /** A reference to the item element. */ |
| 44 | readonly element: SignalLike<HTMLElement> = () => this.inputs.element()!; |
| 45 | |
| 46 | /** Whether the item is disabled. */ |
| 47 | readonly disabled: SignalLike<boolean> = () => this.inputs.disabled(); |
| 48 | |
| 49 | /** The text used by the typeahead search. */ |
| 50 | readonly searchTerm: SignalLike<string> = () => this.inputs.searchTerm(); |
| 51 | |
| 52 | /** The tree pattern this item belongs to. */ |
| 53 | readonly tree: SignalLike<TreePattern<V>> = () => this.inputs.tree(); |
| 54 | |
| 55 | /** The parent item. */ |
| 56 | readonly parent: SignalLike<TreeItemPattern<V> | undefined> = computed(() => { |
| 57 | const parent = this.inputs.parent(); |
| 58 | return parent instanceof TreeItemPattern ? parent : undefined; |
| 59 | }); |
| 60 | |
| 61 | /** The children items. */ |
| 62 | readonly children: SignalLike<TreeItemPattern<V>[]> = () => this.inputs.children() ?? []; |
| 63 | |
| 64 | /** The position of this item among its siblings. */ |
| 65 | readonly index = computed(() => this.tree().inputs.items().indexOf(this)); |
| 66 | |
| 67 | /** Whether the item is expandable. It's expandable if children item exist. */ |
| 68 | readonly expandable: SignalLike<boolean> = () => this.inputs.hasChildren(); |
| 69 | |
| 70 | /** Whether the item is selectable. */ |
| 71 | readonly selectable: SignalLike<boolean> = () => this.inputs.selectable(); |
| 72 | |
| 73 | /** Whether the item is expanded. */ |
| 74 | readonly expanded: WritableSignalLike<boolean>; |
| 75 | |
| 76 | /** The level of the current item in a tree. */ |
| 77 | readonly level: SignalLike<number> = computed(() => this.inputs.parent().level() + 1); |
| 78 | |
| 79 | /** Whether this item is visible. */ |
| 80 | readonly visible: SignalLike<boolean> = computed( |
| 81 | () => this.inputs.parent().expanded() && this.inputs.parent().visible(), |
| 82 | ); |
| 83 | |
| 84 | /** The number of items under the same parent at the same level. */ |
| 85 | readonly setsize = computed(() => this.inputs.parent().children().length); |
| 86 | |
| 87 | /** The position of this item among its siblings (1-based). */ |
| 88 | readonly posinset = computed(() => this.inputs.parent().children().indexOf(this) + 1); |
| 89 | |
| 90 | /** Whether the item is active. */ |
| 91 | readonly active = computed(() => this.tree().activeItem() === this); |
| 92 | |
| 93 | /** The tab index of the item. */ |
nothing calls this directly
no test coverage detected
searching dependent graphs…