ng-zorro-antd-tree-view.mjs 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125
  1. import * as i0 from '@angular/core';
  2. import { EventEmitter, booleanAttribute, Output, Input, ChangeDetectionStrategy, Component, inject, Directive, forwardRef, Renderer2, ChangeDetectorRef, numberAttribute, ViewChild, ViewEncapsulation, NgModule } from '@angular/core';
  3. import { takeUntil, auditTime, filter, take, map } from 'rxjs/operators';
  4. import * as i1 from 'ng-zorro-antd/core/services';
  5. import { NzDestroyService } from 'ng-zorro-antd/core/services';
  6. import { fromEventOutsideAngular } from 'ng-zorro-antd/core/util';
  7. import { Subject, animationFrameScheduler, asapScheduler, merge, BehaviorSubject } from 'rxjs';
  8. import { CdkTreeNode, CdkTree, CdkTreeNodeToggle, CdkTreeNodeDef, CDK_TREE_NODE_OUTLET_NODE, CdkTreeNodeOutlet, CdkTreeNodePadding, CdkTreeNodeOutletContext } from '@angular/cdk/tree';
  9. import { NzNoAnimationDirective } from 'ng-zorro-antd/core/no-animation';
  10. import * as i1$1 from '@angular/cdk/bidi';
  11. import { treeCollapseMotion } from 'ng-zorro-antd/core/animation';
  12. import { CdkVirtualForOf, CdkVirtualScrollViewport, CdkFixedSizeVirtualScroll } from '@angular/cdk/scrolling';
  13. import { DataSource } from '@angular/cdk/collections';
  14. /**
  15. * Use of this source code is governed by an MIT-style license that can be
  16. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  17. */
  18. class NzTreeNodeCheckboxComponent {
  19. ngZone;
  20. ref;
  21. host;
  22. destroy$;
  23. nzChecked;
  24. nzIndeterminate;
  25. nzDisabled;
  26. nzClick = new EventEmitter();
  27. constructor(ngZone, ref, host, destroy$) {
  28. this.ngZone = ngZone;
  29. this.ref = ref;
  30. this.host = host;
  31. this.destroy$ = destroy$;
  32. }
  33. ngOnInit() {
  34. fromEventOutsideAngular(this.host.nativeElement, 'click')
  35. .pipe(takeUntil(this.destroy$))
  36. .subscribe((event) => {
  37. if (!this.nzDisabled && this.nzClick.observers.length) {
  38. this.ngZone.run(() => {
  39. this.nzClick.emit(event);
  40. this.ref.markForCheck();
  41. });
  42. }
  43. });
  44. }
  45. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeNodeCheckboxComponent, deps: [{ token: i0.NgZone }, { token: i0.ChangeDetectorRef }, { token: i0.ElementRef }, { token: i1.NzDestroyService }], target: i0.ɵɵFactoryTarget.Component });
  46. static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "16.1.0", version: "19.2.2", type: NzTreeNodeCheckboxComponent, isStandalone: true, selector: "nz-tree-node-checkbox:not([builtin])", inputs: { nzChecked: ["nzChecked", "nzChecked", booleanAttribute], nzIndeterminate: ["nzIndeterminate", "nzIndeterminate", booleanAttribute], nzDisabled: ["nzDisabled", "nzDisabled", booleanAttribute] }, outputs: { nzClick: "nzClick" }, host: { properties: { "class.ant-tree-checkbox-checked": "nzChecked", "class.ant-tree-checkbox-indeterminate": "nzIndeterminate", "class.ant-tree-checkbox-disabled": "nzDisabled" }, classAttribute: "ant-tree-checkbox" }, providers: [NzDestroyService], ngImport: i0, template: ` <span class="ant-tree-checkbox-inner"></span> `, isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush });
  47. }
  48. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeNodeCheckboxComponent, decorators: [{
  49. type: Component,
  50. args: [{
  51. selector: 'nz-tree-node-checkbox:not([builtin])',
  52. template: ` <span class="ant-tree-checkbox-inner"></span> `,
  53. changeDetection: ChangeDetectionStrategy.OnPush,
  54. preserveWhitespaces: false,
  55. host: {
  56. class: 'ant-tree-checkbox',
  57. '[class.ant-tree-checkbox-checked]': `nzChecked`,
  58. '[class.ant-tree-checkbox-indeterminate]': `nzIndeterminate`,
  59. '[class.ant-tree-checkbox-disabled]': `nzDisabled`
  60. },
  61. providers: [NzDestroyService]
  62. }]
  63. }], ctorParameters: () => [{ type: i0.NgZone }, { type: i0.ChangeDetectorRef }, { type: i0.ElementRef }, { type: i1.NzDestroyService }], propDecorators: { nzChecked: [{
  64. type: Input,
  65. args: [{ transform: booleanAttribute }]
  66. }], nzIndeterminate: [{
  67. type: Input,
  68. args: [{ transform: booleanAttribute }]
  69. }], nzDisabled: [{
  70. type: Input,
  71. args: [{ transform: booleanAttribute }]
  72. }], nzClick: [{
  73. type: Output
  74. }] } });
  75. /**
  76. * Use of this source code is governed by an MIT-style license that can be
  77. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  78. */
  79. const getParent = (nodes, node, getLevel) => {
  80. let index = nodes.indexOf(node);
  81. if (index < 0) {
  82. return null;
  83. }
  84. const level = getLevel(node);
  85. for (index--; index >= 0; index--) {
  86. const preLevel = getLevel(nodes[index]);
  87. if (preLevel + 1 === level) {
  88. return nodes[index];
  89. }
  90. if (preLevel + 1 < level) {
  91. return null;
  92. }
  93. }
  94. return null;
  95. };
  96. const getNextSibling = (nodes, node, getLevel, _index) => {
  97. let index = typeof _index !== 'undefined' ? _index : nodes.indexOf(node);
  98. if (index < 0) {
  99. return null;
  100. }
  101. const level = getLevel(node);
  102. for (index++; index < nodes.length; index++) {
  103. const nextLevel = getLevel(nodes[index]);
  104. if (nextLevel < level) {
  105. return null;
  106. }
  107. if (nextLevel === level) {
  108. return nodes[index];
  109. }
  110. }
  111. return null;
  112. };
  113. /**
  114. * Use of this source code is governed by an MIT-style license that can be
  115. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  116. */
  117. class NzNodeBase extends CdkTreeNode {
  118. }
  119. // eslint-disable-next-line @angular-eslint/component-class-suffix
  120. class NzTreeView extends CdkTree {
  121. differs;
  122. changeDetectorRef;
  123. directionality;
  124. destroy$ = new Subject();
  125. dir = 'ltr';
  126. _dataSourceChanged = new Subject();
  127. // eslint-disable-next-line @angular-eslint/no-input-rename
  128. treeControl = undefined;
  129. get dataSource() {
  130. return super.dataSource;
  131. }
  132. set dataSource(dataSource) {
  133. super.dataSource = dataSource;
  134. }
  135. nzDirectoryTree = false;
  136. nzBlockNode = false;
  137. noAnimation = inject(NzNoAnimationDirective, { host: true, optional: true });
  138. constructor(differs, changeDetectorRef, directionality) {
  139. super(differs, changeDetectorRef, directionality);
  140. this.differs = differs;
  141. this.changeDetectorRef = changeDetectorRef;
  142. this.directionality = directionality;
  143. }
  144. ngOnInit() {
  145. super.ngOnInit();
  146. this.dir = this.directionality.value;
  147. this.directionality.change?.pipe(takeUntil(this.destroy$)).subscribe((direction) => {
  148. this.dir = direction;
  149. this.changeDetectorRef.detectChanges();
  150. });
  151. }
  152. ngOnDestroy() {
  153. super.ngOnDestroy();
  154. this.destroy$.next(true);
  155. this.destroy$.complete();
  156. }
  157. renderNodeChanges(data, dataDiffer, viewContainer, parentData) {
  158. super.renderNodeChanges(data, dataDiffer, viewContainer, parentData);
  159. this._dataSourceChanged.next();
  160. }
  161. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeView, deps: [{ token: i0.IterableDiffers }, { token: i0.ChangeDetectorRef }, { token: i1$1.Directionality }], target: i0.ɵɵFactoryTarget.Component });
  162. static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "16.1.0", version: "19.2.2", type: NzTreeView, isStandalone: true, selector: "ng-component", inputs: { treeControl: ["nzTreeControl", "treeControl"], dataSource: ["nzDataSource", "dataSource"], nzDirectoryTree: ["nzDirectoryTree", "nzDirectoryTree", booleanAttribute], nzBlockNode: ["nzBlockNode", "nzBlockNode", booleanAttribute] }, usesInheritance: true, ngImport: i0, template: '', isInline: true });
  163. }
  164. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeView, decorators: [{
  165. type: Component,
  166. args: [{
  167. template: ''
  168. }]
  169. }], ctorParameters: () => [{ type: i0.IterableDiffers }, { type: i0.ChangeDetectorRef }, { type: i1$1.Directionality }], propDecorators: { treeControl: [{
  170. type: Input,
  171. args: ['nzTreeControl']
  172. }], dataSource: [{
  173. type: Input,
  174. args: ['nzDataSource']
  175. }], nzDirectoryTree: [{
  176. type: Input,
  177. args: [{ transform: booleanAttribute }]
  178. }], nzBlockNode: [{
  179. type: Input,
  180. args: [{ transform: booleanAttribute }]
  181. }] } });
  182. /**
  183. * Use of this source code is governed by an MIT-style license that can be
  184. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  185. */
  186. /**
  187. * [true, false, false, true] => 1001
  188. */
  189. function booleanArrayToString(arr) {
  190. return arr.map(i => (i ? 1 : 0)).join('');
  191. }
  192. const BUILD_INDENTS_SCHEDULER = typeof requestAnimationFrame !== 'undefined' ? animationFrameScheduler : asapScheduler;
  193. class NzTreeNodeIndentsComponent {
  194. indents = [];
  195. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeNodeIndentsComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
  196. static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.2", type: NzTreeNodeIndentsComponent, isStandalone: true, selector: "nz-tree-node-indents", inputs: { indents: "indents" }, host: { classAttribute: "ant-tree-indent" }, ngImport: i0, template: `
  197. @for (isEnd of indents; track isEnd) {
  198. <span class="ant-tree-indent-unit" [class.ant-tree-indent-unit-end]="!isEnd"></span>
  199. }
  200. `, isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush });
  201. }
  202. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeNodeIndentsComponent, decorators: [{
  203. type: Component,
  204. args: [{
  205. selector: 'nz-tree-node-indents',
  206. template: `
  207. @for (isEnd of indents; track isEnd) {
  208. <span class="ant-tree-indent-unit" [class.ant-tree-indent-unit-end]="!isEnd"></span>
  209. }
  210. `,
  211. changeDetection: ChangeDetectionStrategy.OnPush,
  212. host: {
  213. class: 'ant-tree-indent'
  214. }
  215. }]
  216. }], propDecorators: { indents: [{
  217. type: Input
  218. }] } });
  219. class NzTreeNodeIndentLineDirective {
  220. treeNode;
  221. tree;
  222. cdr;
  223. isLast = 'unset';
  224. isLeaf = false;
  225. preNodeRef = null;
  226. nextNodeRef = null;
  227. currentIndents = '';
  228. changeSubscription;
  229. constructor(treeNode, tree, cdr) {
  230. this.treeNode = treeNode;
  231. this.tree = tree;
  232. this.cdr = cdr;
  233. this.buildIndents();
  234. this.checkLast();
  235. /**
  236. * The dependent data (TreeControl.dataNodes) can be set after node instantiation,
  237. * and setting the indents can cause frame rate loss if it is set too often.
  238. */
  239. this.changeSubscription = merge(this.treeNode._dataChanges, tree._dataSourceChanged)
  240. .pipe(auditTime(0, BUILD_INDENTS_SCHEDULER))
  241. .subscribe(() => {
  242. this.buildIndents();
  243. this.checkAdjacent();
  244. this.cdr.markForCheck();
  245. });
  246. }
  247. getIndents() {
  248. const indents = [];
  249. if (!this.tree.treeControl) {
  250. return indents;
  251. }
  252. const nodes = this.tree.treeControl.dataNodes;
  253. const getLevel = this.tree.treeControl.getLevel;
  254. let parent = getParent(nodes, this.treeNode.data, getLevel);
  255. while (parent) {
  256. const parentNextSibling = getNextSibling(nodes, parent, getLevel);
  257. if (parentNextSibling) {
  258. indents.unshift(true);
  259. }
  260. else {
  261. indents.unshift(false);
  262. }
  263. parent = getParent(nodes, parent, getLevel);
  264. }
  265. return indents;
  266. }
  267. buildIndents() {
  268. if (this.treeNode.data) {
  269. const indents = this.getIndents();
  270. const diffString = booleanArrayToString(indents);
  271. if (diffString !== this.currentIndents) {
  272. this.treeNode.setIndents(this.getIndents());
  273. this.currentIndents = diffString;
  274. }
  275. }
  276. }
  277. /**
  278. * We need to add an class name for the last child node,
  279. * this result can also be affected when the adjacent nodes are changed.
  280. */
  281. checkAdjacent() {
  282. const nodes = this.tree.treeControl?.dataNodes || [];
  283. const index = nodes.indexOf(this.treeNode.data);
  284. const preNode = nodes[index - 1] || null;
  285. const nextNode = nodes[index + 1] || null;
  286. if (this.nextNodeRef !== nextNode || this.preNodeRef !== preNode) {
  287. this.checkLast(index);
  288. }
  289. this.preNodeRef = preNode;
  290. this.nextNodeRef = nextNode;
  291. }
  292. checkLast(index) {
  293. const nodes = this.tree.treeControl?.dataNodes || [];
  294. this.isLeaf = this.treeNode.isLeaf;
  295. this.isLast =
  296. !!this.tree.treeControl && !getNextSibling(nodes, this.treeNode.data, this.tree.treeControl.getLevel, index);
  297. }
  298. ngOnDestroy() {
  299. this.preNodeRef = null;
  300. this.nextNodeRef = null;
  301. this.changeSubscription.unsubscribe();
  302. }
  303. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeNodeIndentLineDirective, deps: [{ token: NzNodeBase }, { token: NzTreeView }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive });
  304. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.2", type: NzTreeNodeIndentLineDirective, isStandalone: true, selector: "nz-tree-node[nzTreeNodeIndentLine]", host: { properties: { "class.ant-tree-treenode-leaf-last": "isLast && isLeaf" }, classAttribute: "ant-tree-show-line" }, ngImport: i0 });
  305. }
  306. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeNodeIndentLineDirective, decorators: [{
  307. type: Directive,
  308. args: [{
  309. selector: 'nz-tree-node[nzTreeNodeIndentLine]',
  310. host: {
  311. class: 'ant-tree-show-line',
  312. '[class.ant-tree-treenode-leaf-last]': 'isLast && isLeaf'
  313. }
  314. }]
  315. }], ctorParameters: () => [{ type: NzNodeBase }, { type: NzTreeView }, { type: i0.ChangeDetectorRef }] });
  316. /**
  317. * Use of this source code is governed by an MIT-style license that can be
  318. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  319. */
  320. class NzTreeNodeNoopToggleDirective {
  321. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeNodeNoopToggleDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
  322. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.2", type: NzTreeNodeNoopToggleDirective, isStandalone: true, selector: "nz-tree-node-toggle[nzTreeNodeNoopToggle], [nzTreeNodeNoopToggle]", host: { classAttribute: "ant-tree-switcher ant-tree-switcher-noop" }, ngImport: i0 });
  323. }
  324. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeNodeNoopToggleDirective, decorators: [{
  325. type: Directive,
  326. args: [{
  327. selector: 'nz-tree-node-toggle[nzTreeNodeNoopToggle], [nzTreeNodeNoopToggle]',
  328. host: {
  329. class: 'ant-tree-switcher ant-tree-switcher-noop'
  330. }
  331. }]
  332. }] });
  333. class NzTreeNodeToggleDirective extends CdkTreeNodeToggle {
  334. recursive = false;
  335. get isExpanded() {
  336. return this._treeNode.isExpanded;
  337. }
  338. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeNodeToggleDirective, deps: null, target: i0.ɵɵFactoryTarget.Directive });
  339. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "16.1.0", version: "19.2.2", type: NzTreeNodeToggleDirective, isStandalone: true, selector: "nz-tree-node-toggle:not([nzTreeNodeNoopToggle]), [nzTreeNodeToggle]", inputs: { recursive: ["nzTreeNodeToggleRecursive", "recursive", booleanAttribute] }, host: { properties: { "class.ant-tree-switcher_open": "isExpanded", "class.ant-tree-switcher_close": "!isExpanded" }, classAttribute: "ant-tree-switcher" }, providers: [{ provide: CdkTreeNodeToggle, useExisting: forwardRef(() => NzTreeNodeToggleDirective) }], usesInheritance: true, ngImport: i0 });
  340. }
  341. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeNodeToggleDirective, decorators: [{
  342. type: Directive,
  343. args: [{
  344. selector: 'nz-tree-node-toggle:not([nzTreeNodeNoopToggle]), [nzTreeNodeToggle]',
  345. providers: [{ provide: CdkTreeNodeToggle, useExisting: forwardRef(() => NzTreeNodeToggleDirective) }],
  346. host: {
  347. class: 'ant-tree-switcher',
  348. '[class.ant-tree-switcher_open]': 'isExpanded',
  349. '[class.ant-tree-switcher_close]': '!isExpanded'
  350. }
  351. }]
  352. }], propDecorators: { recursive: [{
  353. type: Input,
  354. args: [{ alias: 'nzTreeNodeToggleRecursive', transform: booleanAttribute }]
  355. }] } });
  356. class NzTreeNodeToggleRotateIconDirective {
  357. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeNodeToggleRotateIconDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
  358. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.2", type: NzTreeNodeToggleRotateIconDirective, isStandalone: true, selector: "[nzTreeNodeToggleRotateIcon]", host: { classAttribute: "ant-tree-switcher-icon" }, ngImport: i0 });
  359. }
  360. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeNodeToggleRotateIconDirective, decorators: [{
  361. type: Directive,
  362. args: [{
  363. selector: '[nzTreeNodeToggleRotateIcon]',
  364. host: {
  365. class: 'ant-tree-switcher-icon'
  366. }
  367. }]
  368. }] });
  369. class NzTreeNodeToggleActiveIconDirective {
  370. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeNodeToggleActiveIconDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
  371. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.2", type: NzTreeNodeToggleActiveIconDirective, isStandalone: true, selector: "[nzTreeNodeToggleActiveIcon]", host: { classAttribute: "ant-tree-switcher-loading-icon" }, ngImport: i0 });
  372. }
  373. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeNodeToggleActiveIconDirective, decorators: [{
  374. type: Directive,
  375. args: [{
  376. selector: '[nzTreeNodeToggleActiveIcon]',
  377. host: {
  378. class: 'ant-tree-switcher-loading-icon'
  379. }
  380. }]
  381. }] });
  382. /**
  383. * Use of this source code is governed by an MIT-style license that can be
  384. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  385. */
  386. class NzTreeNodeComponent extends NzNodeBase {
  387. elementRef;
  388. tree;
  389. indents = [];
  390. disabled = false;
  391. selected = false;
  392. isLeaf = false;
  393. renderer = inject(Renderer2);
  394. cdr = inject(ChangeDetectorRef);
  395. constructor(elementRef, tree) {
  396. super(elementRef, tree);
  397. this.elementRef = elementRef;
  398. this.tree = tree;
  399. this._elementRef.nativeElement.classList.add('ant-tree-treenode');
  400. }
  401. ngOnInit() {
  402. this.isLeaf = !this.tree.treeControl?.isExpandable(this.data);
  403. }
  404. disable() {
  405. this.disabled = true;
  406. this.updateDisabledClass();
  407. }
  408. enable() {
  409. this.disabled = false;
  410. this.updateDisabledClass();
  411. }
  412. select() {
  413. this.selected = true;
  414. this.updateSelectedClass();
  415. }
  416. deselect() {
  417. this.selected = false;
  418. this.updateSelectedClass();
  419. }
  420. setIndents(indents) {
  421. this.indents = indents;
  422. this.cdr.markForCheck();
  423. }
  424. updateSelectedClass() {
  425. if (this.selected) {
  426. this.renderer.addClass(this.elementRef.nativeElement, 'ant-tree-treenode-selected');
  427. }
  428. else {
  429. this.renderer.removeClass(this.elementRef.nativeElement, 'ant-tree-treenode-selected');
  430. }
  431. }
  432. updateDisabledClass() {
  433. if (this.disabled) {
  434. this.renderer.addClass(this.elementRef.nativeElement, 'ant-tree-treenode-disabled');
  435. }
  436. else {
  437. this.renderer.removeClass(this.elementRef.nativeElement, 'ant-tree-treenode-disabled');
  438. }
  439. }
  440. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeNodeComponent, deps: [{ token: i0.ElementRef }, { token: NzTreeView }], target: i0.ɵɵFactoryTarget.Component });
  441. static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.2", type: NzTreeNodeComponent, isStandalone: true, selector: "nz-tree-node:not([builtin])", host: { properties: { "class.ant-tree-treenode-switcher-open": "isExpanded", "class.ant-tree-treenode-switcher-close": "!isExpanded" } }, providers: [
  442. { provide: CdkTreeNode, useExisting: forwardRef(() => NzTreeNodeComponent) },
  443. { provide: NzNodeBase, useExisting: forwardRef(() => NzTreeNodeComponent) }
  444. ], exportAs: ["nzTreeNode"], usesInheritance: true, ngImport: i0, template: `
  445. @if (indents.length) {
  446. <nz-tree-node-indents [indents]="indents"></nz-tree-node-indents>
  447. }
  448. <ng-content select="nz-tree-node-toggle, [nz-tree-node-toggle]"></ng-content>
  449. @if (indents.length && isLeaf) {
  450. <nz-tree-node-toggle class="nz-tree-leaf-line-icon" nzTreeNodeNoopToggle>
  451. <span class="ant-tree-switcher-leaf-line"></span>
  452. </nz-tree-node-toggle>
  453. }
  454. <ng-content select="nz-tree-node-checkbox"></ng-content>
  455. <ng-content select="nz-tree-node-option"></ng-content>
  456. <ng-content></ng-content>
  457. `, isInline: true, dependencies: [{ kind: "component", type: NzTreeNodeIndentsComponent, selector: "nz-tree-node-indents", inputs: ["indents"] }, { kind: "directive", type: NzTreeNodeNoopToggleDirective, selector: "nz-tree-node-toggle[nzTreeNodeNoopToggle], [nzTreeNodeNoopToggle]" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
  458. }
  459. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeNodeComponent, decorators: [{
  460. type: Component,
  461. args: [{
  462. selector: 'nz-tree-node:not([builtin])',
  463. exportAs: 'nzTreeNode',
  464. changeDetection: ChangeDetectionStrategy.OnPush,
  465. providers: [
  466. { provide: CdkTreeNode, useExisting: forwardRef(() => NzTreeNodeComponent) },
  467. { provide: NzNodeBase, useExisting: forwardRef(() => NzTreeNodeComponent) }
  468. ],
  469. template: `
  470. @if (indents.length) {
  471. <nz-tree-node-indents [indents]="indents"></nz-tree-node-indents>
  472. }
  473. <ng-content select="nz-tree-node-toggle, [nz-tree-node-toggle]"></ng-content>
  474. @if (indents.length && isLeaf) {
  475. <nz-tree-node-toggle class="nz-tree-leaf-line-icon" nzTreeNodeNoopToggle>
  476. <span class="ant-tree-switcher-leaf-line"></span>
  477. </nz-tree-node-toggle>
  478. }
  479. <ng-content select="nz-tree-node-checkbox"></ng-content>
  480. <ng-content select="nz-tree-node-option"></ng-content>
  481. <ng-content></ng-content>
  482. `,
  483. host: {
  484. '[class.ant-tree-treenode-switcher-open]': 'isExpanded',
  485. '[class.ant-tree-treenode-switcher-close]': '!isExpanded'
  486. },
  487. imports: [NzTreeNodeIndentsComponent, NzTreeNodeNoopToggleDirective]
  488. }]
  489. }], ctorParameters: () => [{ type: i0.ElementRef }, { type: NzTreeView }] });
  490. class NzTreeNodeDefDirective extends CdkTreeNodeDef {
  491. when = null;
  492. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeNodeDefDirective, deps: null, target: i0.ɵɵFactoryTarget.Directive });
  493. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.2", type: NzTreeNodeDefDirective, isStandalone: true, selector: "[nzTreeNodeDef]", inputs: { when: ["nzTreeNodeDefWhen", "when"] }, providers: [
  494. {
  495. provide: CdkTreeNodeDef,
  496. useExisting: forwardRef(() => NzTreeNodeDefDirective)
  497. }
  498. ], usesInheritance: true, ngImport: i0 });
  499. }
  500. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeNodeDefDirective, decorators: [{
  501. type: Directive,
  502. args: [{
  503. selector: '[nzTreeNodeDef]',
  504. providers: [
  505. {
  506. provide: CdkTreeNodeDef,
  507. useExisting: forwardRef(() => NzTreeNodeDefDirective)
  508. }
  509. ]
  510. }]
  511. }], propDecorators: { when: [{
  512. type: Input,
  513. args: ['nzTreeNodeDefWhen']
  514. }] } });
  515. class NzTreeVirtualScrollNodeOutletDirective {
  516. _viewContainerRef;
  517. _viewRef = null;
  518. data;
  519. compareBy;
  520. constructor(_viewContainerRef) {
  521. this._viewContainerRef = _viewContainerRef;
  522. }
  523. ngOnChanges(changes) {
  524. const recreateView = this.shouldRecreateView(changes);
  525. if (recreateView) {
  526. const viewContainerRef = this._viewContainerRef;
  527. if (this._viewRef) {
  528. viewContainerRef.remove(viewContainerRef.indexOf(this._viewRef));
  529. }
  530. this._viewRef = this.data
  531. ? viewContainerRef.createEmbeddedView(this.data.nodeDef.template, this.data.context)
  532. : null;
  533. if (CdkTreeNode.mostRecentTreeNode && this._viewRef) {
  534. CdkTreeNode.mostRecentTreeNode.data = this.data.data;
  535. }
  536. }
  537. else if (this._viewRef && this.data.context) {
  538. this.updateExistingContext(this.data.context);
  539. }
  540. }
  541. shouldRecreateView(changes) {
  542. const ctxChange = changes.data;
  543. return ctxChange && this.hasContextShapeChanged(ctxChange);
  544. }
  545. hasContextShapeChanged(ctxChange) {
  546. const prevCtxKeys = Object.keys(ctxChange.previousValue || {});
  547. const currCtxKeys = Object.keys(ctxChange.currentValue || {});
  548. if (prevCtxKeys.length === currCtxKeys.length) {
  549. for (const propName of currCtxKeys) {
  550. if (prevCtxKeys.indexOf(propName) === -1) {
  551. return true;
  552. }
  553. }
  554. return (this.innerCompareBy(ctxChange.previousValue?.data ?? null) !==
  555. this.innerCompareBy(ctxChange.currentValue?.data ?? null));
  556. }
  557. return true;
  558. }
  559. get innerCompareBy() {
  560. return value => {
  561. if (value === null)
  562. return value;
  563. if (this.compareBy)
  564. return this.compareBy(value);
  565. return value;
  566. };
  567. }
  568. updateExistingContext(ctx) {
  569. for (const propName of Object.keys(ctx)) {
  570. this._viewRef.context[propName] = this.data.context[propName];
  571. }
  572. }
  573. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeVirtualScrollNodeOutletDirective, deps: [{ token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive });
  574. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.2", type: NzTreeVirtualScrollNodeOutletDirective, isStandalone: true, selector: "[nzTreeVirtualScrollNodeOutlet]", inputs: { data: "data", compareBy: "compareBy" }, usesOnChanges: true, ngImport: i0 });
  575. }
  576. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeVirtualScrollNodeOutletDirective, decorators: [{
  577. type: Directive,
  578. args: [{
  579. selector: '[nzTreeVirtualScrollNodeOutlet]'
  580. }]
  581. }], ctorParameters: () => [{ type: i0.ViewContainerRef }], propDecorators: { data: [{
  582. type: Input
  583. }], compareBy: [{
  584. type: Input
  585. }] } });
  586. /**
  587. * Use of this source code is governed by an MIT-style license that can be
  588. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  589. */
  590. class NzTreeNodeOptionComponent {
  591. ngZone;
  592. host;
  593. destroy$;
  594. treeNode;
  595. nzSelected = false;
  596. nzDisabled = false;
  597. nzClick = new EventEmitter();
  598. constructor(ngZone, host, destroy$, treeNode) {
  599. this.ngZone = ngZone;
  600. this.host = host;
  601. this.destroy$ = destroy$;
  602. this.treeNode = treeNode;
  603. }
  604. get isExpanded() {
  605. return this.treeNode.isExpanded;
  606. }
  607. ngOnChanges(changes) {
  608. const { nzDisabled, nzSelected } = changes;
  609. if (nzDisabled) {
  610. if (nzDisabled.currentValue) {
  611. this.treeNode.disable();
  612. }
  613. else {
  614. this.treeNode.enable();
  615. }
  616. }
  617. if (nzSelected) {
  618. if (nzSelected.currentValue) {
  619. this.treeNode.select();
  620. }
  621. else {
  622. this.treeNode.deselect();
  623. }
  624. }
  625. }
  626. ngOnInit() {
  627. fromEventOutsideAngular(this.host.nativeElement, 'click')
  628. .pipe(filter(() => !this.nzDisabled && this.nzClick.observers.length > 0), takeUntil(this.destroy$))
  629. .subscribe(event => {
  630. this.ngZone.run(() => this.nzClick.emit(event));
  631. });
  632. }
  633. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeNodeOptionComponent, deps: [{ token: i0.NgZone }, { token: i0.ElementRef }, { token: i1.NzDestroyService }, { token: NzTreeNodeComponent }], target: i0.ɵɵFactoryTarget.Component });
  634. static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "16.1.0", version: "19.2.2", type: NzTreeNodeOptionComponent, isStandalone: true, selector: "nz-tree-node-option", inputs: { nzSelected: ["nzSelected", "nzSelected", booleanAttribute], nzDisabled: ["nzDisabled", "nzDisabled", booleanAttribute] }, outputs: { nzClick: "nzClick" }, host: { properties: { "class.ant-tree-node-content-wrapper-open": "isExpanded", "class.ant-tree-node-selected": "nzSelected" }, classAttribute: "ant-tree-node-content-wrapper" }, providers: [NzDestroyService], usesOnChanges: true, ngImport: i0, template: ` <span class="ant-tree-title"><ng-content></ng-content></span> `, isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush });
  635. }
  636. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeNodeOptionComponent, decorators: [{
  637. type: Component,
  638. args: [{
  639. selector: 'nz-tree-node-option',
  640. template: ` <span class="ant-tree-title"><ng-content></ng-content></span> `,
  641. changeDetection: ChangeDetectionStrategy.OnPush,
  642. host: {
  643. class: 'ant-tree-node-content-wrapper',
  644. '[class.ant-tree-node-content-wrapper-open]': 'isExpanded',
  645. '[class.ant-tree-node-selected]': 'nzSelected'
  646. },
  647. providers: [NzDestroyService]
  648. }]
  649. }], ctorParameters: () => [{ type: i0.NgZone }, { type: i0.ElementRef }, { type: i1.NzDestroyService }, { type: NzTreeNodeComponent }], propDecorators: { nzSelected: [{
  650. type: Input,
  651. args: [{ transform: booleanAttribute }]
  652. }], nzDisabled: [{
  653. type: Input,
  654. args: [{ transform: booleanAttribute }]
  655. }], nzClick: [{
  656. type: Output
  657. }] } });
  658. /**
  659. * Use of this source code is governed by an MIT-style license that can be
  660. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  661. */
  662. class NzTreeNodeOutletDirective {
  663. viewContainer;
  664. _node = inject(CDK_TREE_NODE_OUTLET_NODE, { optional: true });
  665. constructor(viewContainer) {
  666. this.viewContainer = viewContainer;
  667. }
  668. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeNodeOutletDirective, deps: [{ token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive });
  669. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.2", type: NzTreeNodeOutletDirective, isStandalone: true, selector: "[nzTreeNodeOutlet]", providers: [
  670. {
  671. provide: CdkTreeNodeOutlet,
  672. useExisting: forwardRef(() => NzTreeNodeOutletDirective)
  673. }
  674. ], ngImport: i0 });
  675. }
  676. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeNodeOutletDirective, decorators: [{
  677. type: Directive,
  678. args: [{
  679. selector: '[nzTreeNodeOutlet]',
  680. providers: [
  681. {
  682. provide: CdkTreeNodeOutlet,
  683. useExisting: forwardRef(() => NzTreeNodeOutletDirective)
  684. }
  685. ]
  686. }]
  687. }], ctorParameters: () => [{ type: i0.ViewContainerRef }] });
  688. /**
  689. * Use of this source code is governed by an MIT-style license that can be
  690. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  691. */
  692. class NzTreeNodePaddingDirective extends CdkTreeNodePadding {
  693. _indent = 24;
  694. get level() {
  695. return this._level;
  696. }
  697. set level(value) {
  698. this._setLevelInput(value);
  699. }
  700. get indent() {
  701. return this._indent;
  702. }
  703. set indent(indent) {
  704. this._setIndentInput(indent);
  705. }
  706. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeNodePaddingDirective, deps: null, target: i0.ɵɵFactoryTarget.Directive });
  707. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "16.1.0", version: "19.2.2", type: NzTreeNodePaddingDirective, isStandalone: true, selector: "[nzTreeNodePadding]", inputs: { level: ["nzTreeNodePadding", "level", numberAttribute], indent: ["nzTreeNodePaddingIndent", "indent"] }, providers: [{ provide: CdkTreeNodePadding, useExisting: forwardRef(() => NzTreeNodePaddingDirective) }], usesInheritance: true, ngImport: i0 });
  708. }
  709. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeNodePaddingDirective, decorators: [{
  710. type: Directive,
  711. args: [{
  712. selector: '[nzTreeNodePadding]',
  713. providers: [{ provide: CdkTreeNodePadding, useExisting: forwardRef(() => NzTreeNodePaddingDirective) }]
  714. }]
  715. }], propDecorators: { level: [{
  716. type: Input,
  717. args: [{ alias: 'nzTreeNodePadding', transform: numberAttribute }]
  718. }], indent: [{
  719. type: Input,
  720. args: ['nzTreeNodePaddingIndent']
  721. }] } });
  722. /**
  723. * Use of this source code is governed by an MIT-style license that can be
  724. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  725. */
  726. class NzTreeViewComponent extends NzTreeView {
  727. nodeOutlet;
  728. _afterViewInit = false;
  729. ngAfterViewInit() {
  730. Promise.resolve().then(() => {
  731. this._afterViewInit = true;
  732. this.changeDetectorRef.markForCheck();
  733. });
  734. }
  735. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeViewComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
  736. static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.2", type: NzTreeViewComponent, isStandalone: true, selector: "nz-tree-view", host: { properties: { "class.ant-tree-block-node": "nzDirectoryTree || nzBlockNode", "class.ant-tree-directory": "nzDirectoryTree", "class.ant-tree-rtl": "dir === 'rtl'" }, classAttribute: "ant-tree" }, providers: [
  737. { provide: CdkTree, useExisting: forwardRef(() => NzTreeViewComponent) },
  738. { provide: NzTreeView, useExisting: forwardRef(() => NzTreeViewComponent) }
  739. ], viewQueries: [{ propertyName: "nodeOutlet", first: true, predicate: NzTreeNodeOutletDirective, descendants: true, static: true }], exportAs: ["nzTreeView"], usesInheritance: true, ngImport: i0, template: `
  740. <div class="ant-tree-list-holder">
  741. <div
  742. [@.disabled]="!_afterViewInit || !!noAnimation?.nzNoAnimation"
  743. [@treeCollapseMotion]="_nodeOutlet.viewContainer.length"
  744. class="ant-tree-list-holder-inner"
  745. >
  746. <ng-container nzTreeNodeOutlet></ng-container>
  747. </div>
  748. </div>
  749. `, isInline: true, dependencies: [{ kind: "directive", type: NzTreeNodeOutletDirective, selector: "[nzTreeNodeOutlet]" }], animations: [treeCollapseMotion], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
  750. }
  751. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeViewComponent, decorators: [{
  752. type: Component,
  753. args: [{
  754. selector: 'nz-tree-view',
  755. exportAs: 'nzTreeView',
  756. template: `
  757. <div class="ant-tree-list-holder">
  758. <div
  759. [@.disabled]="!_afterViewInit || !!noAnimation?.nzNoAnimation"
  760. [@treeCollapseMotion]="_nodeOutlet.viewContainer.length"
  761. class="ant-tree-list-holder-inner"
  762. >
  763. <ng-container nzTreeNodeOutlet></ng-container>
  764. </div>
  765. </div>
  766. `,
  767. encapsulation: ViewEncapsulation.None,
  768. changeDetection: ChangeDetectionStrategy.OnPush,
  769. providers: [
  770. { provide: CdkTree, useExisting: forwardRef(() => NzTreeViewComponent) },
  771. { provide: NzTreeView, useExisting: forwardRef(() => NzTreeViewComponent) }
  772. ],
  773. host: {
  774. class: 'ant-tree',
  775. '[class.ant-tree-block-node]': 'nzDirectoryTree || nzBlockNode',
  776. '[class.ant-tree-directory]': 'nzDirectoryTree',
  777. '[class.ant-tree-rtl]': `dir === 'rtl'`
  778. },
  779. animations: [treeCollapseMotion],
  780. imports: [NzTreeNodeOutletDirective]
  781. }]
  782. }], propDecorators: { nodeOutlet: [{
  783. type: ViewChild,
  784. args: [NzTreeNodeOutletDirective, { static: true }]
  785. }] } });
  786. /**
  787. * Use of this source code is governed by an MIT-style license that can be
  788. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  789. */
  790. const DEFAULT_SIZE = 28;
  791. class NzTreeVirtualScrollViewComponent extends NzTreeView {
  792. nodeOutlet;
  793. virtualScrollViewport;
  794. nzItemSize = DEFAULT_SIZE;
  795. nzMinBufferPx = DEFAULT_SIZE * 5;
  796. nzMaxBufferPx = DEFAULT_SIZE * 10;
  797. trackBy = null;
  798. nodes = [];
  799. innerTrackBy = i => i;
  800. ngOnChanges({ trackBy }) {
  801. if (trackBy) {
  802. if (typeof trackBy.currentValue === 'function') {
  803. this.innerTrackBy = (index, n) => this.trackBy(index, n.data);
  804. }
  805. else {
  806. this.innerTrackBy = i => i;
  807. }
  808. }
  809. }
  810. get compareBy() {
  811. const baseTreeControl = this.treeControl;
  812. if (baseTreeControl.trackBy) {
  813. return baseTreeControl.trackBy;
  814. }
  815. return null;
  816. }
  817. renderNodeChanges(data) {
  818. this.nodes = new Array(...data).map((n, i) => this.createNode(n, i));
  819. this._dataSourceChanged.next();
  820. this.changeDetectorRef.markForCheck();
  821. }
  822. /**
  823. * @note
  824. * angular/cdk v18.2.0 breaking changes: https://github.com/angular/components/pull/29062
  825. * Temporary workaround: revert to old method of getting level
  826. * TODO: refactor tree-view, remove #treeControl and adopt #levelAccessor and #childrenAccessor
  827. * */
  828. _getLevel(nodeData) {
  829. if (this.treeControl?.getLevel) {
  830. return this.treeControl.getLevel(nodeData);
  831. }
  832. return;
  833. }
  834. createNode(nodeData, index) {
  835. const node = this._getNodeDef(nodeData, index);
  836. const context = new CdkTreeNodeOutletContext(nodeData);
  837. if (this.treeControl?.getLevel) {
  838. context.level = this.treeControl.getLevel(nodeData);
  839. }
  840. else {
  841. context.level = 0;
  842. }
  843. return {
  844. data: nodeData,
  845. context,
  846. nodeDef: node
  847. };
  848. }
  849. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeVirtualScrollViewComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
  850. static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.2", type: NzTreeVirtualScrollViewComponent, isStandalone: true, selector: "nz-tree-virtual-scroll-view", inputs: { nzItemSize: "nzItemSize", nzMinBufferPx: "nzMinBufferPx", nzMaxBufferPx: "nzMaxBufferPx", trackBy: "trackBy" }, host: { properties: { "class.ant-tree-block-node": "nzDirectoryTree || nzBlockNode", "class.ant-tree-directory": "nzDirectoryTree", "class.ant-tree-rtl": "dir === 'rtl'" }, classAttribute: "ant-tree" }, providers: [
  851. { provide: NzTreeView, useExisting: forwardRef(() => NzTreeVirtualScrollViewComponent) },
  852. { provide: CdkTree, useExisting: forwardRef(() => NzTreeVirtualScrollViewComponent) }
  853. ], viewQueries: [{ propertyName: "nodeOutlet", first: true, predicate: NzTreeNodeOutletDirective, descendants: true, static: true }, { propertyName: "virtualScrollViewport", first: true, predicate: CdkVirtualScrollViewport, descendants: true, static: true }], exportAs: ["nzTreeVirtualScrollView"], usesInheritance: true, usesOnChanges: true, ngImport: i0, template: `
  854. <div class="ant-tree-list">
  855. <cdk-virtual-scroll-viewport
  856. class="ant-tree-list-holder"
  857. [itemSize]="nzItemSize"
  858. [minBufferPx]="nzMinBufferPx"
  859. [maxBufferPx]="nzMaxBufferPx"
  860. >
  861. <ng-container *cdkVirtualFor="let item of nodes; let i = index; trackBy: innerTrackBy">
  862. <ng-template nzTreeVirtualScrollNodeOutlet [data]="item" [compareBy]="compareBy"></ng-template>
  863. </ng-container>
  864. </cdk-virtual-scroll-viewport>
  865. </div>
  866. <ng-container nzTreeNodeOutlet></ng-container>
  867. `, isInline: true, dependencies: [{ kind: "directive", type: NzTreeVirtualScrollNodeOutletDirective, selector: "[nzTreeVirtualScrollNodeOutlet]", inputs: ["data", "compareBy"] }, { kind: "directive", type: CdkVirtualForOf, selector: "[cdkVirtualFor][cdkVirtualForOf]", inputs: ["cdkVirtualForOf", "cdkVirtualForTrackBy", "cdkVirtualForTemplate", "cdkVirtualForTemplateCacheSize"] }, { kind: "directive", type: NzTreeNodeOutletDirective, selector: "[nzTreeNodeOutlet]" }, { kind: "component", type: CdkVirtualScrollViewport, selector: "cdk-virtual-scroll-viewport", inputs: ["orientation", "appendOnly"], outputs: ["scrolledIndexChange"] }, { kind: "directive", type: CdkFixedSizeVirtualScroll, selector: "cdk-virtual-scroll-viewport[itemSize]", inputs: ["itemSize", "minBufferPx", "maxBufferPx"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
  868. }
  869. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeVirtualScrollViewComponent, decorators: [{
  870. type: Component,
  871. args: [{
  872. selector: 'nz-tree-virtual-scroll-view',
  873. exportAs: 'nzTreeVirtualScrollView',
  874. template: `
  875. <div class="ant-tree-list">
  876. <cdk-virtual-scroll-viewport
  877. class="ant-tree-list-holder"
  878. [itemSize]="nzItemSize"
  879. [minBufferPx]="nzMinBufferPx"
  880. [maxBufferPx]="nzMaxBufferPx"
  881. >
  882. <ng-container *cdkVirtualFor="let item of nodes; let i = index; trackBy: innerTrackBy">
  883. <ng-template nzTreeVirtualScrollNodeOutlet [data]="item" [compareBy]="compareBy"></ng-template>
  884. </ng-container>
  885. </cdk-virtual-scroll-viewport>
  886. </div>
  887. <ng-container nzTreeNodeOutlet></ng-container>
  888. `,
  889. encapsulation: ViewEncapsulation.None,
  890. changeDetection: ChangeDetectionStrategy.OnPush,
  891. providers: [
  892. { provide: NzTreeView, useExisting: forwardRef(() => NzTreeVirtualScrollViewComponent) },
  893. { provide: CdkTree, useExisting: forwardRef(() => NzTreeVirtualScrollViewComponent) }
  894. ],
  895. host: {
  896. class: 'ant-tree',
  897. '[class.ant-tree-block-node]': 'nzDirectoryTree || nzBlockNode',
  898. '[class.ant-tree-directory]': 'nzDirectoryTree',
  899. '[class.ant-tree-rtl]': `dir === 'rtl'`
  900. },
  901. imports: [
  902. NzTreeVirtualScrollNodeOutletDirective,
  903. CdkVirtualForOf,
  904. NzTreeNodeOutletDirective,
  905. CdkVirtualScrollViewport,
  906. CdkFixedSizeVirtualScroll
  907. ]
  908. }]
  909. }], propDecorators: { nodeOutlet: [{
  910. type: ViewChild,
  911. args: [NzTreeNodeOutletDirective, { static: true }]
  912. }], virtualScrollViewport: [{
  913. type: ViewChild,
  914. args: [CdkVirtualScrollViewport, { static: true }]
  915. }], nzItemSize: [{
  916. type: Input
  917. }], nzMinBufferPx: [{
  918. type: Input
  919. }], nzMaxBufferPx: [{
  920. type: Input
  921. }], trackBy: [{
  922. type: Input
  923. }] } });
  924. /**
  925. * Use of this source code is governed by an MIT-style license that can be
  926. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  927. */
  928. const treeWithControlComponents = [
  929. NzTreeView,
  930. NzTreeNodeOutletDirective,
  931. NzTreeViewComponent,
  932. NzTreeNodeDefDirective,
  933. NzTreeNodeComponent,
  934. NzTreeNodeToggleDirective,
  935. NzTreeNodePaddingDirective,
  936. NzTreeNodeToggleRotateIconDirective,
  937. NzTreeNodeToggleActiveIconDirective,
  938. NzTreeNodeOptionComponent,
  939. NzTreeNodeNoopToggleDirective,
  940. NzTreeNodeCheckboxComponent,
  941. NzTreeNodeIndentsComponent,
  942. NzTreeVirtualScrollViewComponent,
  943. NzTreeVirtualScrollNodeOutletDirective,
  944. NzTreeNodeIndentLineDirective
  945. ];
  946. class NzTreeViewModule {
  947. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeViewModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
  948. static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.2", ngImport: i0, type: NzTreeViewModule, imports: [NzTreeView,
  949. NzTreeNodeOutletDirective,
  950. NzTreeViewComponent,
  951. NzTreeNodeDefDirective,
  952. NzTreeNodeComponent,
  953. NzTreeNodeToggleDirective,
  954. NzTreeNodePaddingDirective,
  955. NzTreeNodeToggleRotateIconDirective,
  956. NzTreeNodeToggleActiveIconDirective,
  957. NzTreeNodeOptionComponent,
  958. NzTreeNodeNoopToggleDirective,
  959. NzTreeNodeCheckboxComponent,
  960. NzTreeNodeIndentsComponent,
  961. NzTreeVirtualScrollViewComponent,
  962. NzTreeVirtualScrollNodeOutletDirective,
  963. NzTreeNodeIndentLineDirective], exports: [NzTreeView,
  964. NzTreeNodeOutletDirective,
  965. NzTreeViewComponent,
  966. NzTreeNodeDefDirective,
  967. NzTreeNodeComponent,
  968. NzTreeNodeToggleDirective,
  969. NzTreeNodePaddingDirective,
  970. NzTreeNodeToggleRotateIconDirective,
  971. NzTreeNodeToggleActiveIconDirective,
  972. NzTreeNodeOptionComponent,
  973. NzTreeNodeNoopToggleDirective,
  974. NzTreeNodeCheckboxComponent,
  975. NzTreeNodeIndentsComponent,
  976. NzTreeVirtualScrollViewComponent,
  977. NzTreeVirtualScrollNodeOutletDirective,
  978. NzTreeNodeIndentLineDirective] });
  979. static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeViewModule, imports: [NzTreeVirtualScrollViewComponent] });
  980. }
  981. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTreeViewModule, decorators: [{
  982. type: NgModule,
  983. args: [{
  984. imports: [treeWithControlComponents],
  985. exports: [treeWithControlComponents]
  986. }]
  987. }] });
  988. /**
  989. * Use of this source code is governed by an MIT-style license that can be
  990. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  991. */
  992. class NzTreeFlattener {
  993. transformFunction;
  994. getLevel;
  995. isExpandable;
  996. getChildren;
  997. constructor(transformFunction, getLevel, isExpandable, getChildren) {
  998. this.transformFunction = transformFunction;
  999. this.getLevel = getLevel;
  1000. this.isExpandable = isExpandable;
  1001. this.getChildren = getChildren;
  1002. }
  1003. flattenNode(node, level, resultNodes, parentMap) {
  1004. const flatNode = this.transformFunction(node, level);
  1005. resultNodes.push(flatNode);
  1006. if (this.isExpandable(flatNode)) {
  1007. const childrenNodes = this.getChildren(node);
  1008. if (childrenNodes) {
  1009. if (Array.isArray(childrenNodes)) {
  1010. this.flattenChildren(childrenNodes, level, resultNodes, parentMap);
  1011. }
  1012. else {
  1013. childrenNodes.pipe(take(1)).subscribe(children => {
  1014. this.flattenChildren(children, level, resultNodes, parentMap);
  1015. });
  1016. }
  1017. }
  1018. }
  1019. return resultNodes;
  1020. }
  1021. flattenChildren(children, level, resultNodes, parentMap) {
  1022. children.forEach((child, index) => {
  1023. const childParentMap = parentMap.slice();
  1024. childParentMap.push(index !== children.length - 1);
  1025. this.flattenNode(child, level + 1, resultNodes, childParentMap);
  1026. });
  1027. }
  1028. /**
  1029. * Flatten a list of node type T to flattened version of node F.
  1030. * Please note that type T may be nested, and the length of `structuredData` may be different
  1031. * from that of returned list `F[]`.
  1032. */
  1033. flattenNodes(structuredData) {
  1034. const resultNodes = [];
  1035. structuredData.forEach(node => this.flattenNode(node, 0, resultNodes, []));
  1036. return resultNodes;
  1037. }
  1038. /**
  1039. * Expand flattened node with current expansion status.
  1040. * The returned list may have different length.
  1041. */
  1042. expandFlattenedNodes(nodes, treeControl) {
  1043. const results = [];
  1044. const currentExpand = [];
  1045. currentExpand[0] = true;
  1046. nodes.forEach(node => {
  1047. let expand = true;
  1048. for (let i = 0; i <= this.getLevel(node); i++) {
  1049. expand = expand && currentExpand[i];
  1050. }
  1051. if (expand) {
  1052. results.push(node);
  1053. }
  1054. if (this.isExpandable(node)) {
  1055. currentExpand[this.getLevel(node) + 1] = treeControl.isExpanded(node);
  1056. }
  1057. });
  1058. return results;
  1059. }
  1060. }
  1061. class NzTreeFlatDataSource extends DataSource {
  1062. _treeControl;
  1063. _treeFlattener;
  1064. _flattenedData = new BehaviorSubject([]);
  1065. _expandedData = new BehaviorSubject([]);
  1066. _data;
  1067. constructor(_treeControl, _treeFlattener, initialData = []) {
  1068. super();
  1069. this._treeControl = _treeControl;
  1070. this._treeFlattener = _treeFlattener;
  1071. this._data = new BehaviorSubject(initialData);
  1072. this.flatNodes();
  1073. }
  1074. setData(value) {
  1075. this._data.next(value);
  1076. this.flatNodes();
  1077. }
  1078. getData() {
  1079. return this._data.getValue();
  1080. }
  1081. connect(collectionViewer) {
  1082. const changes = [
  1083. collectionViewer.viewChange,
  1084. this._treeControl.expansionModel.changed.asObservable(),
  1085. this._flattenedData.asObservable()
  1086. ];
  1087. return merge(...changes).pipe(map(() => {
  1088. this._expandedData.next(this._treeFlattener.expandFlattenedNodes(this._flattenedData.value, this._treeControl));
  1089. return this._expandedData.value;
  1090. }));
  1091. }
  1092. disconnect() {
  1093. // no op
  1094. }
  1095. flatNodes() {
  1096. this._flattenedData.next(this._treeFlattener.flattenNodes(this.getData()));
  1097. this._treeControl.dataNodes = this._flattenedData.value;
  1098. }
  1099. }
  1100. /**
  1101. * Use of this source code is governed by an MIT-style license that can be
  1102. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  1103. */
  1104. /**
  1105. * Generated bundle index. Do not edit.
  1106. */
  1107. export { NzTreeFlatDataSource, NzTreeFlattener, NzTreeNodeCheckboxComponent, NzTreeNodeComponent, NzTreeNodeDefDirective, NzTreeNodeIndentLineDirective, NzTreeNodeIndentsComponent, NzTreeNodeNoopToggleDirective, NzTreeNodeOptionComponent, NzTreeNodeOutletDirective, NzTreeNodePaddingDirective, NzTreeNodeToggleActiveIconDirective, NzTreeNodeToggleDirective, NzTreeNodeToggleRotateIconDirective, NzTreeView, NzTreeViewComponent, NzTreeViewModule, NzTreeVirtualScrollNodeOutletDirective, NzTreeVirtualScrollViewComponent, getNextSibling, getParent };
  1108. //# sourceMappingURL=ng-zorro-antd-tree-view.mjs.map