mirror of
https://github.com/angular/angular.git
synced 2026-11-22 22:55:25 -05:00
refactor(devtools): replace deprecated tree APIs in the component tree
`FlatTreeControl` from `@angular/cdk/tree` and `MatTreeFlattener` from `@angular/material/tree` are deprecated in favor of the tree's `levelAccessor`/`childrenAccessor` APIs. The component tree (directive forest) isn't rendered with a CDK tree but as a flat list in a virtual scroll viewport. It only used `FlatTreeControl` to track which nodes are expanded, and `MatTreeFlattener` to flatten the forest and compute the visible nodes. Replace them with: - An `ExpansionModel` that tracks expanded nodes with a `SelectionModel`, like `FlatTreeControl` did internally, and exposes the `expand`, `collapse`, `toggle`, `isExpanded` and `changed` members used by devtools. - Local helpers in `ComponentDataSource` that flatten the forest in depth-first order and return the nodes whose ancestors are all expanded, matching the previous behavior. Also add a spec covering which nodes are visible as nodes are expanded and collapsed.
This commit is contained in:
committed by
Kirill Cherkashin
parent
a1bffc29dd
commit
d60ee5e27b
+11
-1
@@ -18,6 +18,7 @@ ng_project(
|
||||
],
|
||||
deps = [
|
||||
":directive_forest_utils",
|
||||
":expansion_model",
|
||||
"//:node_modules/@angular/cdk",
|
||||
"//:node_modules/@angular/core",
|
||||
"//:node_modules/@angular/material",
|
||||
@@ -34,11 +35,20 @@ ng_project(
|
||||
],
|
||||
)
|
||||
|
||||
ts_project(
|
||||
name = "expansion_model",
|
||||
srcs = ["expansion-model.ts"],
|
||||
deps = [
|
||||
"//:node_modules/@angular/cdk",
|
||||
"//:node_modules/rxjs",
|
||||
],
|
||||
)
|
||||
|
||||
ts_project(
|
||||
name = "directive_forest_utils",
|
||||
srcs = ["directive-forest-utils.ts"],
|
||||
deps = [
|
||||
"//:node_modules/@angular/cdk",
|
||||
":expansion_model",
|
||||
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/component-data-source",
|
||||
],
|
||||
)
|
||||
|
||||
+3
-2
@@ -8,10 +8,10 @@ ts_project(
|
||||
deps = [
|
||||
"//:node_modules/@angular/cdk",
|
||||
"//:node_modules/@angular/core",
|
||||
"//:node_modules/@angular/material",
|
||||
"//:node_modules/@types",
|
||||
"//:node_modules/rxjs",
|
||||
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/diffing",
|
||||
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest:expansion_model",
|
||||
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/index-forest",
|
||||
"//devtools/projects/protocol",
|
||||
],
|
||||
@@ -22,7 +22,8 @@ ts_test_library(
|
||||
srcs = glob(["**/*.spec.ts"]),
|
||||
deps = [
|
||||
":component-data-source",
|
||||
"//:node_modules/@angular/cdk",
|
||||
"//:node_modules/rxjs",
|
||||
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest:expansion_model",
|
||||
"//devtools/projects/protocol",
|
||||
],
|
||||
)
|
||||
|
||||
+28
-6
@@ -6,10 +6,12 @@
|
||||
* found in the LICENSE file at https://angular.dev/license
|
||||
*/
|
||||
|
||||
import {FlatTreeControl} from '@angular/cdk/tree';
|
||||
import {of} from 'rxjs';
|
||||
|
||||
import {DevToolsNode} from '../../../../../../../protocol';
|
||||
|
||||
import {ComponentDataSource, FlatNode} from '.';
|
||||
import {ExpansionModel} from '../expansion-model';
|
||||
|
||||
const tree1: DevToolsNode = {
|
||||
tagName: 'app',
|
||||
@@ -213,12 +215,9 @@ const tree4: DevToolsNode = {
|
||||
|
||||
describe('ComponentDataSource', () => {
|
||||
let dataSource: ComponentDataSource;
|
||||
const treeControl = new FlatTreeControl<FlatNode>(
|
||||
(node) => node.level,
|
||||
(node) => node.expandable,
|
||||
);
|
||||
const expansionModel = new ExpansionModel<FlatNode>();
|
||||
|
||||
beforeEach(() => (dataSource = new ComponentDataSource(treeControl)));
|
||||
beforeEach(() => (dataSource = new ComponentDataSource(expansionModel)));
|
||||
|
||||
it('should return new and old items', () => {
|
||||
const result = dataSource.update([tree1], true);
|
||||
@@ -250,4 +249,27 @@ describe('ComponentDataSource', () => {
|
||||
|
||||
expect(result.newItems[1].position).toEqual([0, 0, 0, 0, 0, 0]);
|
||||
});
|
||||
|
||||
it('should only show the children of expanded nodes', () => {
|
||||
const expansionModel = new ExpansionModel<FlatNode>();
|
||||
const source = new ComponentDataSource(expansionModel);
|
||||
source.update([tree1], true);
|
||||
const [app, bar] = source.data;
|
||||
expect([app.level, bar.level]).toEqual([0, 1]);
|
||||
|
||||
let visibleNodes: string[] = [];
|
||||
const subscription = source
|
||||
.connect({viewChange: of({start: 0, end: Number.MAX_VALUE})})
|
||||
.subscribe((nodes) => (visibleNodes = nodes.map((node) => node.name)));
|
||||
|
||||
expect(visibleNodes).toEqual(['app']);
|
||||
|
||||
expansionModel.expand(app);
|
||||
expect(visibleNodes).toEqual(['app', 'bar']);
|
||||
|
||||
expansionModel.collapse(app);
|
||||
expect(visibleNodes).toEqual(['app']);
|
||||
|
||||
subscription.unsubscribe();
|
||||
});
|
||||
});
|
||||
|
||||
+68
-43
@@ -7,9 +7,7 @@
|
||||
*/
|
||||
|
||||
import {CollectionViewer, DataSource} from '@angular/cdk/collections';
|
||||
import {FlatTreeControl} from '@angular/cdk/tree';
|
||||
import {DefaultIterableDiffer, TrackByFunction} from '@angular/core';
|
||||
import {MatTreeFlattener} from '@angular/material/tree';
|
||||
import {
|
||||
DevToolsNode,
|
||||
ControlFlowBlock,
|
||||
@@ -19,6 +17,7 @@ import {
|
||||
import {BehaviorSubject, merge, Observable, map} from 'rxjs';
|
||||
|
||||
import {diff} from '../../diffing';
|
||||
import {ExpansionModel} from '../expansion-model';
|
||||
import {IndexedNode, indexForest} from '../index-forest';
|
||||
|
||||
/** Flat node with expandable and level information */
|
||||
@@ -87,47 +86,77 @@ const filterCommentNodes = (nodes: IndexedNode[]) => {
|
||||
return nodes;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the nodes of a flattened tree that are visible, i.e. whose ancestors are all expanded.
|
||||
*
|
||||
* @param nodes flat nodes in depth-first order.
|
||||
* @param isExpanded whether the given node is expanded.
|
||||
*/
|
||||
const getVisibleNodes = (nodes: FlatNode[], isExpanded: (node: FlatNode) => boolean) => {
|
||||
const visibleNodes: FlatNode[] = [];
|
||||
// Whether all ancestors are expanded, indexed by level.
|
||||
const expandedAtLevel: boolean[] = [true];
|
||||
for (const node of nodes) {
|
||||
let visible = true;
|
||||
for (let i = 0; i <= node.level; i++) {
|
||||
visible = visible && !!expandedAtLevel[i];
|
||||
}
|
||||
if (visible) {
|
||||
visibleNodes.push(node);
|
||||
}
|
||||
if (node.expandable) {
|
||||
expandedAtLevel[node.level + 1] = isExpanded(node);
|
||||
}
|
||||
}
|
||||
return visibleNodes;
|
||||
};
|
||||
|
||||
export class ComponentDataSource extends DataSource<FlatNode> {
|
||||
private _differ = new DefaultIterableDiffer<FlatNode>(trackBy);
|
||||
private _expandedData = new BehaviorSubject<FlatNode[]>([]);
|
||||
private _flattenedData = new BehaviorSubject<FlatNode[]>([]);
|
||||
private _nodeToFlat = new WeakMap<IndexedNode, FlatNode>();
|
||||
|
||||
private _treeFlattener = new MatTreeFlattener(
|
||||
(node: IndexedNode, level: number) => {
|
||||
if (this._nodeToFlat.has(node)) {
|
||||
return this._nodeToFlat.get(node);
|
||||
}
|
||||
const flatNode: FlatNode = {
|
||||
expandable: expandable(node),
|
||||
id: getId(node),
|
||||
// We can compare the nodes in the navigation functions above
|
||||
// based on this identifier directly, since it's a reference type
|
||||
// and the reference is preserved after transformation.
|
||||
position: node.position,
|
||||
name: node.component ? node.component.name : (node.tagName ?? ''),
|
||||
directives: node.directives?.map((d) => d.name) ?? [],
|
||||
original: node,
|
||||
level,
|
||||
hydration: node.hydration,
|
||||
controlFlowBlock: node.controlFlowBlock,
|
||||
static: node.static,
|
||||
changeDetection: node.changeDetection,
|
||||
hasNativeElement: node.hasNativeElement,
|
||||
collapsedByDefault: node.children.every((n) => n.static),
|
||||
};
|
||||
this._nodeToFlat.set(node, flatNode);
|
||||
return flatNode;
|
||||
},
|
||||
(node) => (node ? node.level : -1),
|
||||
(node) => (node ? node.expandable : false),
|
||||
(node) => (node ? node.children : []),
|
||||
);
|
||||
|
||||
constructor(private _treeControl: FlatTreeControl<FlatNode>) {
|
||||
constructor(private _expansionModel: ExpansionModel<FlatNode>) {
|
||||
super();
|
||||
}
|
||||
|
||||
/** Flattens the forest into a list of nodes in depth-first order. */
|
||||
private _flattenNodes(nodes: IndexedNode[], level = 0, result: FlatNode[] = []): FlatNode[] {
|
||||
for (const node of nodes) {
|
||||
const flatNode = this._toFlatNode(node, level);
|
||||
result.push(flatNode);
|
||||
if (flatNode.expandable) {
|
||||
this._flattenNodes(node.children, level + 1, result);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private _toFlatNode(node: IndexedNode, level: number): FlatNode {
|
||||
const existingNode = this._nodeToFlat.get(node);
|
||||
if (existingNode) {
|
||||
return existingNode;
|
||||
}
|
||||
const flatNode: FlatNode = {
|
||||
expandable: expandable(node),
|
||||
id: getId(node),
|
||||
position: node.position,
|
||||
name: node.component ? node.component.name : (node.tagName ?? ''),
|
||||
directives: node.directives?.map((d) => d.name) ?? [],
|
||||
original: node,
|
||||
level,
|
||||
hydration: node.hydration,
|
||||
controlFlowBlock: node.controlFlowBlock,
|
||||
static: node.static,
|
||||
changeDetection: node.changeDetection,
|
||||
hasNativeElement: node.hasNativeElement,
|
||||
collapsedByDefault: node.children.every((n) => n.static),
|
||||
};
|
||||
this._nodeToFlat.set(node, flatNode);
|
||||
return flatNode;
|
||||
}
|
||||
|
||||
get data(): FlatNode[] {
|
||||
return this._flattenedData.value;
|
||||
}
|
||||
@@ -174,13 +203,13 @@ export class ComponentDataSource extends DataSource<FlatNode> {
|
||||
indexedForest = filterCommentNodes(indexedForest);
|
||||
}
|
||||
|
||||
const flattenedCollection = this._treeFlattener.flattenNodes(indexedForest) as FlatNode[];
|
||||
const flattenedCollection = this._flattenNodes(indexedForest);
|
||||
|
||||
this.data.forEach((i) => (i.newItem = false));
|
||||
|
||||
const expandedNodes: Record<string, boolean> = {};
|
||||
this.data.forEach((item) => {
|
||||
expandedNodes[item.id] = this._treeControl.isExpanded(item);
|
||||
expandedNodes[item.id] = this._expansionModel.isExpanded(item);
|
||||
});
|
||||
|
||||
const {newItems, movedItems, removedItems} = diff<FlatNode>(
|
||||
@@ -188,13 +217,12 @@ export class ComponentDataSource extends DataSource<FlatNode> {
|
||||
this.data,
|
||||
flattenedCollection,
|
||||
);
|
||||
this._treeControl.dataNodes = this.data;
|
||||
this._flattenedData.next(this.data);
|
||||
|
||||
movedItems.forEach((i) => {
|
||||
this._nodeToFlat.set(i.original, i);
|
||||
if (expandedNodes[i.id]) {
|
||||
this._treeControl.expand(i);
|
||||
this._expansionModel.expand(i);
|
||||
}
|
||||
});
|
||||
newItems.forEach((i) => (i.newItem = true));
|
||||
@@ -206,16 +234,13 @@ export class ComponentDataSource extends DataSource<FlatNode> {
|
||||
override connect(collectionViewer: CollectionViewer): Observable<FlatNode[]> {
|
||||
const changes = [
|
||||
collectionViewer.viewChange,
|
||||
this._treeControl.expansionModel.changed,
|
||||
this._expansionModel.changed,
|
||||
this._flattenedData,
|
||||
];
|
||||
return merge<unknown[]>(...changes).pipe(
|
||||
map(() => {
|
||||
this._expandedData.next(
|
||||
this._treeFlattener.expandFlattenedNodes(
|
||||
this.data,
|
||||
this._treeControl as FlatTreeControl<FlatNode | undefined>,
|
||||
) as FlatNode[],
|
||||
getVisibleNodes(this.data, (node) => this._expansionModel.isExpanded(node)),
|
||||
);
|
||||
return this._expandedData.value;
|
||||
}),
|
||||
|
||||
+3
-4
@@ -6,9 +6,8 @@
|
||||
* found in the LICENSE file at https://angular.dev/license
|
||||
*/
|
||||
|
||||
import {FlatTreeControl} from '@angular/cdk/tree';
|
||||
|
||||
import {FlatNode} from './component-data-source/index';
|
||||
import {ExpansionModel} from './expansion-model';
|
||||
|
||||
export const isChildOf = (childPosition: number[], parentPosition: number[]) => {
|
||||
if (childPosition.length <= parentPosition.length) {
|
||||
@@ -25,11 +24,11 @@ export const isChildOf = (childPosition: number[], parentPosition: number[]) =>
|
||||
export const parentCollapsed = (
|
||||
nodeIdx: number,
|
||||
all: FlatNode[],
|
||||
treeControl: FlatTreeControl<FlatNode>,
|
||||
expansionModel: ExpansionModel<FlatNode>,
|
||||
) => {
|
||||
const node = all[nodeIdx];
|
||||
for (let i = nodeIdx - 1; i >= 0; i--) {
|
||||
if (isChildOf(node.position, all[i].position) && !treeControl.isExpanded(all[i])) {
|
||||
if (isChildOf(node.position, all[i].position) && !expansionModel.isExpanded(all[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@
|
||||
[node]="node"
|
||||
[selectedNode]="selectedNode()"
|
||||
[highlightedId]="highlightIdInTreeFromElement()"
|
||||
[treeControl]="treeControl"
|
||||
[expansionModel]="expansionModel"
|
||||
[textMatches]="matchedNodes().get(idx) ?? []"
|
||||
[nodeCdData]="mappedCdData().get(node.original.original)"
|
||||
(selectNode)="selectAndEnsureVisible($event)"
|
||||
|
||||
+13
-18
@@ -11,7 +11,6 @@ import {
|
||||
CdkFixedSizeVirtualScroll,
|
||||
CdkVirtualForOf,
|
||||
} from '@angular/cdk/scrolling';
|
||||
import {FlatTreeControl} from '@angular/cdk/tree';
|
||||
import {
|
||||
afterRenderEffect,
|
||||
Component,
|
||||
@@ -34,11 +33,10 @@ import {
|
||||
Events,
|
||||
MessageBus,
|
||||
} from '../../../../../../protocol';
|
||||
|
||||
import {TabUpdate} from '../../tab-update/index';
|
||||
import {DEEP_LINK_INSTANCE_ID} from '../../../application-providers/deep_link';
|
||||
|
||||
import {ComponentDataSource, FlatNode} from './component-data-source';
|
||||
import {ExpansionModel} from './expansion-model';
|
||||
import {
|
||||
getFullNodeNameString,
|
||||
isChildOf,
|
||||
@@ -138,11 +136,8 @@ export class DirectiveForestComponent {
|
||||
return mapped;
|
||||
});
|
||||
|
||||
readonly treeControl = new FlatTreeControl<FlatNode>(
|
||||
(node) => node!.level,
|
||||
(node) => node.expandable,
|
||||
);
|
||||
readonly dataSource = new ComponentDataSource(this.treeControl);
|
||||
readonly expansionModel = new ExpansionModel<FlatNode>();
|
||||
readonly dataSource = new ComponentDataSource(this.expansionModel);
|
||||
readonly itemHeight = NODE_ITEM_HEIGHT;
|
||||
readonly filterGenerator = directiveForestFilterFnGenerator;
|
||||
|
||||
@@ -260,7 +255,7 @@ export class DirectiveForestComponent {
|
||||
if (prevNode.position.length <= currentNode.position.length) {
|
||||
return this.selectAndEnsureVisible(data[prevIdx]);
|
||||
}
|
||||
while (prevIdx >= 0 && parentCollapsed(prevIdx, data, this.treeControl)) {
|
||||
while (prevIdx >= 0 && parentCollapsed(prevIdx, data, this.expansionModel)) {
|
||||
prevIdx--;
|
||||
prevNode = data[prevIdx];
|
||||
}
|
||||
@@ -277,7 +272,7 @@ export class DirectiveForestComponent {
|
||||
const selectedNode = this.selectedNode();
|
||||
let idx = data.findIndex((e) => selectedNode && e.id === selectedNode.id);
|
||||
const currentNode = data[idx];
|
||||
if (!this.treeControl.isExpanded(currentNode) && currentNode.expandable) {
|
||||
if (!this.expansionModel.isExpanded(currentNode) && currentNode.expandable) {
|
||||
for (let i = idx + 1; i < data.length; i++) {
|
||||
const node = data[i];
|
||||
if (!isChildOf(node.position, currentNode.position)) {
|
||||
@@ -302,7 +297,7 @@ export class DirectiveForestComponent {
|
||||
if (!selectedNode) {
|
||||
return;
|
||||
}
|
||||
this.treeControl.collapse(selectedNode);
|
||||
this.expansionModel.collapse(selectedNode);
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
@@ -314,7 +309,7 @@ export class DirectiveForestComponent {
|
||||
if (!selectedNode) {
|
||||
return;
|
||||
}
|
||||
this.treeControl.expand(selectedNode);
|
||||
this.expansionModel.expand(selectedNode);
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
@@ -354,7 +349,7 @@ export class DirectiveForestComponent {
|
||||
const [nodeIdxToSelect] = indexesOfMatchedNodes[newMatchedIndex];
|
||||
const nodeToSelect = this.dataSource.data[nodeIdxToSelect];
|
||||
if (nodeIdxToSelect !== undefined) {
|
||||
this.treeControl.expand(nodeToSelect);
|
||||
this.expansionModel.expand(nodeToSelect);
|
||||
this.selectAndEnsureVisible(nodeToSelect);
|
||||
|
||||
// Set the `currentlyMatchedIndex` after `selectAndEnsureVisible` since it resets it.
|
||||
@@ -388,11 +383,11 @@ export class DirectiveForestComponent {
|
||||
this.forestRoot = this.dataSource.data[0];
|
||||
|
||||
if (!this.initialized && forest && forest.length) {
|
||||
for (const n of this.treeControl.dataNodes) {
|
||||
for (const n of this.dataSource.data) {
|
||||
if (!n.collapsedByDefault) {
|
||||
this.treeControl.expand(n);
|
||||
this.expansionModel.expand(n);
|
||||
} else {
|
||||
this.treeControl.collapse(n);
|
||||
this.expansionModel.collapse(n);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -403,7 +398,7 @@ export class DirectiveForestComponent {
|
||||
// they are `collapsedByDefault`.
|
||||
result.newItems.forEach((item) => {
|
||||
if (!item.collapsedByDefault) {
|
||||
this.treeControl.expand(item);
|
||||
this.expansionModel.expand(item);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
@@ -464,7 +459,7 @@ export class DirectiveForestComponent {
|
||||
}
|
||||
|
||||
private expandParents(): void {
|
||||
this.parents.forEach((parent) => this.treeControl.expand(parent));
|
||||
this.parents.forEach((parent) => this.expansionModel.expand(parent));
|
||||
}
|
||||
|
||||
private handleViewportResize() {
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google LLC All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.dev/license
|
||||
*/
|
||||
|
||||
import {SelectionChange, SelectionModel} from '@angular/cdk/collections';
|
||||
import {Observable} from 'rxjs';
|
||||
|
||||
/**
|
||||
* Tracks which nodes of a tree are expanded.
|
||||
*
|
||||
* The directive forest is rendered as a flat list inside a virtual scroll viewport rather than
|
||||
* with a CDK tree, so it only needs this expansion state, which used to be provided by the
|
||||
* deprecated `FlatTreeControl`.
|
||||
*/
|
||||
export class ExpansionModel<T> {
|
||||
private readonly _expanded = new SelectionModel<T>(true);
|
||||
|
||||
/** Emits whenever nodes are expanded or collapsed. */
|
||||
readonly changed: Observable<SelectionChange<T>> = this._expanded.changed;
|
||||
|
||||
expand(node: T): void {
|
||||
this._expanded.select(node);
|
||||
}
|
||||
|
||||
collapse(node: T): void {
|
||||
this._expanded.deselect(node);
|
||||
}
|
||||
|
||||
toggle(node: T): void {
|
||||
this._expanded.toggle(node);
|
||||
}
|
||||
|
||||
isExpanded(node: T): boolean {
|
||||
return this._expanded.isSelected(node);
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -26,6 +26,7 @@ ng_project(
|
||||
"//:node_modules/@angular/material",
|
||||
"//devtools/projects/ng-devtools/src/lib/application-providers:app_data",
|
||||
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest:directive_forest_utils",
|
||||
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest:expansion_model",
|
||||
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/component-data-source",
|
||||
"//devtools/projects/ng-devtools/src/lib/shared/utils",
|
||||
"//devtools/projects/protocol",
|
||||
@@ -37,11 +38,11 @@ ts_test_library(
|
||||
srcs = ["tree-node.component.spec.ts"],
|
||||
deps = [
|
||||
":tree-node",
|
||||
"//:node_modules/@angular/cdk",
|
||||
"//:node_modules/@angular/core",
|
||||
"//:node_modules/@angular/material",
|
||||
"//:node_modules/@angular/platform-browser",
|
||||
"//devtools/projects/ng-devtools/src/lib/application-providers:app_data",
|
||||
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest:expansion_model",
|
||||
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/component-data-source",
|
||||
"//devtools/projects/protocol",
|
||||
],
|
||||
|
||||
+3
-3
@@ -4,12 +4,12 @@
|
||||
@if (node().expandable) {
|
||||
<!-- We stop propagration on dblClick to prevent to show the element panel -->
|
||||
<button
|
||||
(click)="treeControl().toggle(node())"
|
||||
(click)="expansionModel().toggle(node())"
|
||||
(dblclick)="$event.stopPropagation()"
|
||||
[attr.aria-label]="'Toggle ' + node().name"
|
||||
>
|
||||
<mat-icon class="mat-icon-rtl-mirror">
|
||||
{{ treeControl().isExpanded(node()) ? 'expand_more' : 'chevron_right' }}
|
||||
{{ expansionModel().isExpanded(node()) ? 'expand_more' : 'chevron_right' }}
|
||||
</mat-icon>
|
||||
</button>
|
||||
}
|
||||
@@ -93,7 +93,7 @@
|
||||
</div>
|
||||
|
||||
@if (
|
||||
treeControl().isExpanded(node()) &&
|
||||
expansionModel().isExpanded(node()) &&
|
||||
hydration &&
|
||||
hydration.status === 'mismatched' &&
|
||||
(hydration.expectedNodeDetails || hydration.actualNodeDetails)
|
||||
|
||||
+2
-8
@@ -9,7 +9,6 @@
|
||||
import {signal} from '@angular/core';
|
||||
import {ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
import {By} from '@angular/platform-browser';
|
||||
import {FlatTreeControl} from '@angular/cdk/tree';
|
||||
|
||||
import {MatTooltip} from '@angular/material/tooltip';
|
||||
|
||||
@@ -17,6 +16,7 @@ import {NodeTextMatch, TreeNodeComponent} from './tree-node.component';
|
||||
import {FlatNode} from '../component-data-source';
|
||||
import {APP_DATA, AppData} from '../../../../application-providers/app_data';
|
||||
import {CdElementData, ChangeDetection} from '../../../../../../../protocol';
|
||||
import {ExpansionModel} from '../expansion-model';
|
||||
|
||||
type DeepPartial<T> = T extends object ? {[P in keyof T]?: DeepPartial<T[P]>} : T;
|
||||
|
||||
@@ -54,13 +54,7 @@ async function configureTestingModule(appData?: Partial<AppData>) {
|
||||
fixture.componentRef.setInput('node', srcNode);
|
||||
fixture.componentRef.setInput('selectedNode', null);
|
||||
fixture.componentRef.setInput('highlightedId', 0);
|
||||
fixture.componentRef.setInput(
|
||||
'treeControl',
|
||||
new FlatTreeControl<FlatNode>(
|
||||
(node) => node!.level,
|
||||
(node) => node.expandable,
|
||||
),
|
||||
);
|
||||
fixture.componentRef.setInput('expansionModel', new ExpansionModel<FlatNode>());
|
||||
|
||||
await fixture.whenStable();
|
||||
|
||||
|
||||
+2
-2
@@ -21,7 +21,6 @@ import {DecimalPipe, DOCUMENT} from '@angular/common';
|
||||
|
||||
import {MatIcon} from '@angular/material/icon';
|
||||
import {MatTooltip} from '@angular/material/tooltip';
|
||||
import {FlatTreeControl} from '@angular/cdk/tree';
|
||||
|
||||
import {FlatNode} from '../component-data-source';
|
||||
import {
|
||||
@@ -32,6 +31,7 @@ import {
|
||||
import {BlockType} from '../../../../shared/utils/control-flow';
|
||||
import {APP_DATA} from '../../../../application-providers/app_data';
|
||||
import {CdElementData} from '../../../../../../../protocol';
|
||||
import {ExpansionModel} from '../expansion-model';
|
||||
|
||||
const PADDING_LEFT_STEP = 15; // px
|
||||
|
||||
@@ -69,7 +69,7 @@ export class TreeNodeComponent {
|
||||
protected readonly node = input.required<FlatNode>();
|
||||
protected readonly selectedNode = input.required<FlatNode | null>();
|
||||
protected readonly highlightedId = input.required<number | null>();
|
||||
protected readonly treeControl = input.required<FlatTreeControl<FlatNode>>();
|
||||
protected readonly expansionModel = input.required<ExpansionModel<FlatNode>>();
|
||||
protected readonly textMatches = input<NodeTextMatch[]>([]);
|
||||
protected readonly nodeCdData = input<CdElementData>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user