Skip to content

Commit

Permalink
feat(cdk/tree): squash cdk-tree-revamp changes into a single commit
Browse files Browse the repository at this point in the history
TODO: cleanup this commit message.

Squashes changes in cdk-tree-revamp into a single commit. Here are the
aggregated commit messages from preview commits.

* docs: improved contributing and coding standard docs (angular#27280)

* feat(cdk/tree): Add levelAccessor and childrenAccessor to CDK tree API

* This is currently unimplemented and will allow a more reactive API for
the tree.

* feat(cdk/tree): wording changes

* feat(cdk/tree): wording changes

* feat(cdk/tree): make getLevel getAccessor private

* feat(cdk/tree): make nullable properties optional

* feat(cdk/tree): fix lint issues

* feat(cdk/tree): add TreeControl methods into the CdkTree itself

* feat(cdk/tree): add missing tree errors

* feat(cdk/tree): make nullable properties optional

* feat(cdk/tree): fix build errors.

* feat(cdk/tree): update tree API goldens

* feat(cdk/tree): fix lint errors

* feat(cdk/tree): fix tests

* feat(cdk/tree): fix final lint and golden errors

* feat(cdk/tree): fix comments and improve readability

* feat(cdk/tree): remove ! assertion

* feat(cdk/tree): implement the various expansion-related methods

* fix(cdk/tree): fix merge conflict errors

* fix(cdk/tree): remove TODOs and fix `isExpanded`

* fix(cdk/tree): fix nested nodes not rendering children

* fix(cdk/tree): remove childrenAccessor?. usage

* fix(cdk/tree): address comments from review

* feat(cdk/tree): add tests for the new cdk/tree APIs (angular#24500)

* feat(cdk/tree): complete migrated tests

* feat(cdk/tree): fix tests

* fix(cdk/tree): add docs to _getAllDescendants

* fix(cdk/tree): add explanatory comment for tree-redesign.spec.ts

feat(cdk/tree): improve aria attributes (angular#24658)

* feat(cdk/tree): add demos to the dev-app

* feat(cdk/tree): add flat-node with levelAccessor example to the demo
page

* feat(cdk/tree): move new demos to cdk-tree-redesign dir

* fix(cdk/tree): fix unused error

* feat(cdk/tree): move demos back to their own dirs

* fix(cdk/tree): address review comments

* feat(cdk/tree): use _getDirectChildren method in nested node

* feat(cdk/tree): add cache of nodes to the tree

* fix(cdk/tree): fix cherry-pick errors

* feat(cdk/tree): add translation layer for nested nodes using levelAccessor

* feat(cdk/tree): add example with nested nodes & level accessor

* feat(cdk/tree): fix examples

* feat(cdk/tree): add example with flat nodes & childrenAccessor

* feat(cdk/tree): flatten data that uses childrenAccessor

* fix(cdk/tree): fix padding not showing for `childrenAccessor` trees

* fix(cdk/tree): fix flat tree demo

* fix(cdk/tree): convert generator function to return a regular array in demo

* fix(cdk/tree): fix build error

* feat(cdk/tree): update API goldens

* fix(cdk/tree): fix some failing tests, one remaining

* fix(cdk/tree): fix test errors and children conversion; also make `renderNodeChanges` private

* fix(cdk/tree): update api goldens

* fix(cdk/tree): fix lint errors

* feat(cdk/tree): deprecate the TreeControl APIs

* fix(cdk/tree): make the toggle button not focusable by keyboard

* fix(cdk/tree): add aria attributes for the flat nodes

* feat(cdk/tree): maintain a cache of parents and node groups

* feat(cdk/tree): implement aria-posinset and aria-setsize

* feat(cdk/tree): update goldens, add descriptions to methods

* feat(cdk/tree): fix lint errors

* fix(cdk/tree): fix build errors

* fix(cdk/tree): change explicit breaking-change version to PLACEHOLDER

* fix(cdk/tree): also update flat level accessor example

* fix(cdk/tree): update API goldens

* fix(cdk/tree): update API goldens

* feat(cdk/tree): add a translation function to the tree to get children

* fix(cdk/tree): lint

* feat(cdk/a11y): add a TreeKeyManager, with next/prev implemented (angular#24659)

* feat(cdk/a11y): add API for TreeKeyManager

* feat(cdk/a11y): add activeItem into the TreeKeyManager

* feat(cdk/a11y): store the options into the key manager

* feat(cdk/a11y): add _getItems translation layer

* feat(cdk/a11y): add skeleton for keydown actions

* feat(cdk/a11y): implement activate item

* feat(cdk/a11y): implement various focus methods

* feat(cdk/a11y): implement onClick, remove lint disables

* feat(cdk/a11y): partial spec migration, fixed some bugs in impl

* fix(cdk/tree): fix lint errors

* fix(cdk/a11y): fix lint errors pt2

* feat(cdk/tree): implement expansion methods for TreeKeyManager (angular#26586)

* feat(cdk/a11y): implement expansion methods

* feat(cdk/a11y): add tests and fixes for expand/collapse interactions

* feat(cdk/a11y): actually fix build

* feat(cdk/a11y): use skipPredicate instead of disabled

* feat(cdk/tree): implement typeahead for TreeKeyManager (angular#27202)

* feat(cdk/a11y): implement typeahead (needs test)

* feat(cdk/a11y): handle typeahead in keydown handler

* feat(cdk/a11y): fix typeahead build errors

* feat(cdk/a11y): add tests for typeahead

* feat(cdk/a11y): add TreeKeyManager to public a11y API

* fix(cdk/a11y): tree key manager build errors/weird merge

* feat(cdk/a11y): fix api goldens

* fix(cdk/a11y): fix tests

* feat(cdk/tree): integrate TreeKeyManager with cdk/tree (angular#27285)

* feat(cdk/tree): add cache of nodes to the tree

* feat(cdk/tree): bug fixes for tree and key manager

* feat(cdk/tree): flatten data that uses childrenAccessor

* feat(cdk/tree): add examples, fix bugs

* fix(cdk/tree): fix build errors

* fix(cdk/tree): restoring incorrectly removed code

* fix(cdk/tree): fix minor typo

* fix(cdk/tree): fix lint

* feat(cdk/tree): add additional tests, fix bug with aria-posinset

* fix(cdk/tree): update goldens, remove fdescribe

* fix(cdk/tree): dev app compilation

* fix(cdk/tree): fix tests

* fix(material/tree): update tests & API

* fix(material/tree): api goldens

* feat(cdk/tree): add `isExpandable` parameter to NestedTreeControl, fix some tests

* fix(cdk/tree): update api goldens

* fix(material/tree): lint

* fix(cdk/tree): update API goldens
  • Loading branch information
alkavats1 authored and zarend committed Aug 7, 2023
1 parent 6cc6cf2 commit c850aff
Show file tree
Hide file tree
Showing 36 changed files with 4,939 additions and 301 deletions.
951 changes: 951 additions & 0 deletions src/cdk/a11y/key-manager/tree-key-manager.spec.ts

Large diffs are not rendered by default.

485 changes: 485 additions & 0 deletions src/cdk/a11y/key-manager/tree-key-manager.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/cdk/a11y/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export * from './aria-describer/aria-reference';
export * from './key-manager/activedescendant-key-manager';
export * from './key-manager/focus-key-manager';
export * from './key-manager/list-key-manager';
export * from './key-manager/tree-key-manager';
export * from './focus-trap/configurable-focus-trap';
export * from './focus-trap/configurable-focus-trap-config';
export * from './focus-trap/configurable-focus-trap-factory';
Expand Down
7 changes: 6 additions & 1 deletion src/cdk/tree/control/base-tree-control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import {SelectionModel} from '@angular/cdk/collections';
import {Observable} from 'rxjs';
import {TreeControl} from './tree-control';

/** Base tree control. It has basic toggle/expand/collapse operations on a single data node. */
/**
* Base tree control. It has basic toggle/expand/collapse operations on a single data node.
*
* @deprecated Use one of levelAccessor or childrenAccessor
* @breaking-change 0.0.0-PLACEHOLDER
*/
export abstract class BaseTreeControl<T, K = T> implements TreeControl<T, K> {
/** Gets a list of descendent data nodes of a subtree rooted at given data node recursively. */
abstract getDescendants(dataNode: T): T[];
Expand Down
7 changes: 6 additions & 1 deletion src/cdk/tree/control/flat-tree-control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ export interface FlatTreeControlOptions<T, K> {
trackBy?: (dataNode: T) => K;
}

/** Flat tree control. Able to expand/collapse a subtree recursively for flattened tree. */
/**
* Flat tree control. Able to expand/collapse a subtree recursively for flattened tree.
*
* @deprecated Use one of levelAccessor or childrenAccessor
* @breaking-change 14.0.0
*/
export class FlatTreeControl<T, K = T> extends BaseTreeControl<T, K> {
/** Construct with flat tree data node functions getLevel and isExpandable. */
constructor(
Expand Down
13 changes: 12 additions & 1 deletion src/cdk/tree/control/nested-tree-control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@ import {BaseTreeControl} from './base-tree-control';

/** Optional set of configuration that can be provided to the NestedTreeControl. */
export interface NestedTreeControlOptions<T, K> {
/** Function to determine if the provided node is expandable. */
isExpandable?: (dataNode: T) => boolean;
trackBy?: (dataNode: T) => K;
}

/** Nested tree control. Able to expand/collapse a subtree recursively for NestedNode type. */
/**
* Nested tree control. Able to expand/collapse a subtree recursively for NestedNode type.
*
* @deprecated Use one of levelAccessor or childrenAccessor
* @breaking-change 14.0.0
*/
export class NestedTreeControl<T, K = T> extends BaseTreeControl<T, K> {
/** Construct with nested tree function getChildren. */
constructor(
Expand All @@ -26,6 +33,10 @@ export class NestedTreeControl<T, K = T> extends BaseTreeControl<T, K> {
if (this.options) {
this.trackBy = this.options.trackBy;
}

if (this.options?.isExpandable) {
this.isExpandable = this.options.isExpandable;
}
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/cdk/tree/control/tree-control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import {Observable} from 'rxjs';
* Tree control interface. User can implement TreeControl to expand/collapse dataNodes in the tree.
* The CDKTree will use this TreeControl to expand/collapse a node.
* User can also use it outside the `<cdk-tree>` to control the expansion status of the tree.
*
* @deprecated Use one of levelAccessor or childrenAccessor
* @breaking-change 14.0.0
*/
export interface TreeControl<T, K = T> {
/** The saved tree nodes data for `expandAll` action. */
Expand Down
23 changes: 8 additions & 15 deletions src/cdk/tree/nested-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
import {
AfterContentInit,
ChangeDetectorRef,
ContentChildren,
Directive,
ElementRef,
Expand All @@ -16,12 +17,10 @@ import {
OnInit,
QueryList,
} from '@angular/core';
import {isObservable} from 'rxjs';
import {takeUntil} from 'rxjs/operators';

import {CDK_TREE_NODE_OUTLET_NODE, CdkTreeNodeOutlet} from './outlet';
import {CdkTree, CdkTreeNode} from './tree';
import {getTreeControlFunctionsMissingError} from './tree-errors';

/**
* Nested node is a child of `<cdk-tree>`. It works with nested tree.
Expand Down Expand Up @@ -62,24 +61,18 @@ export class CdkNestedTreeNode<T, K = T>
constructor(
elementRef: ElementRef<HTMLElement>,
tree: CdkTree<T, K>,
changeDetectorRef: ChangeDetectorRef,
protected _differs: IterableDiffers,
) {
super(elementRef, tree);
super(elementRef, tree, changeDetectorRef);
}

ngAfterContentInit() {
this._dataDiffer = this._differs.find([]).create(this._tree.trackBy);
if (!this._tree.treeControl.getChildren && (typeof ngDevMode === 'undefined' || ngDevMode)) {
throw getTreeControlFunctionsMissingError();
}
const childrenNodes = this._tree.treeControl.getChildren(this.data);
if (Array.isArray(childrenNodes)) {
this.updateChildrenNodes(childrenNodes as T[]);
} else if (isObservable(childrenNodes)) {
childrenNodes
.pipe(takeUntil(this._destroyed))
.subscribe(result => this.updateChildrenNodes(result));
}
this._tree
._getDirectChildren(this.data)
.pipe(takeUntil(this._destroyed))
.subscribe(result => this.updateChildrenNodes(result));
this.nodeOutlet.changes
.pipe(takeUntil(this._destroyed))
.subscribe(() => this.updateChildrenNodes());
Expand All @@ -104,7 +97,7 @@ export class CdkNestedTreeNode<T, K = T>
}
if (outlet && this._children) {
const viewContainer = outlet.viewContainer;
this._tree.renderNodeChanges(this._children, this._dataDiffer, viewContainer, this._data);
this._tree._renderNodeChanges(this._children, this._dataDiffer, viewContainer, this._data);
} else {
// Reset the data differ if there's no children nodes displayed
this._dataDiffer.diff([]);
Expand Down
5 changes: 1 addition & 4 deletions src/cdk/tree/padding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ export class CdkTreeNodePadding<T, K = T> implements OnDestroy {

/** The padding indent value for the tree node. Returns a string with px numbers if not null. */
_paddingIndent(): string | null {
const nodeLevel =
this._treeNode.data && this._tree.treeControl.getLevel
? this._tree.treeControl.getLevel(this._treeNode.data)
: null;
const nodeLevel = (this._treeNode.data && this._tree._getLevel(this._treeNode.data)) ?? null;
const level = this._level == null ? nodeLevel : this._level;
return typeof level === 'number' ? `${level * this._indent}${this.indentUnits}` : null;
}
Expand Down
5 changes: 3 additions & 2 deletions src/cdk/tree/toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {CdkTree, CdkTreeNode} from './tree';
selector: '[cdkTreeNodeToggle]',
host: {
'(click)': '_toggle($event)',
'tabindex': '-1',
},
})
export class CdkTreeNodeToggle<T, K = T> {
Expand All @@ -35,8 +36,8 @@ export class CdkTreeNodeToggle<T, K = T> {

_toggle(event: Event): void {
this.recursive
? this._tree.treeControl.toggleDescendants(this._treeNode.data)
: this._tree.treeControl.toggle(this._treeNode.data);
? this._tree.toggleDescendants(this._treeNode.data)
: this._tree.toggle(this._treeNode.data);

event.stopPropagation();
}
Expand Down
19 changes: 14 additions & 5 deletions src/cdk/tree/tree-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,26 @@ export function getTreeMissingMatchingNodeDefError() {
}

/**
* Returns an error to be thrown when there are tree control.
* Returns an error to be thrown when there is no tree control.
* @docs-private
*/
export function getTreeControlMissingError() {
return Error(`Could not find a tree control for the tree.`);
return Error(`Could not find a tree control, levelAccessor, or childrenAccessor for the tree.`);
}

/**
* Returns an error to be thrown when tree control did not implement functions for flat/nested node.
* Returns an error to be thrown when there are multiple ways of specifying children or level
* provided to the tree.
* @docs-private
*/
export function getTreeControlFunctionsMissingError() {
return Error(`Could not find functions for nested/flat tree in tree control.`);
export function getMultipleTreeControlsError() {
return Error(`More than one of tree control, levelAccessor, or childrenAccessor were provided.`);
}

/**
* Returns an error to be thrown when the node type is not specified.
* @docs-private
*/
export function getTreeControlNodeTypeUnspecifiedError() {
return Error(`The nodeType was not specified for the tree.`);
}
Loading

0 comments on commit c850aff

Please sign in to comment.