@abp/ng.components 7.2.2 → 7.3.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/chart.js/chart.component.d.ts +30 -30
- package/chart.js/chart.module.d.ts +8 -8
- package/chart.js/index.d.ts +5 -5
- package/chart.js/public-api.d.ts +3 -3
- package/chart.js/widget-utils.d.ts +1 -1
- package/{esm2020 → esm2022}/abp-ng.components.mjs +4 -4
- package/{esm2020 → esm2022}/chart.js/abp-ng.components-chart.js.mjs +4 -4
- package/esm2022/chart.js/chart.component.mjs +141 -0
- package/esm2022/chart.js/chart.module.mjs +20 -0
- package/{esm2020 → esm2022}/chart.js/public-api.mjs +3 -3
- package/{esm2020 → esm2022}/chart.js/widget-utils.mjs +10 -10
- package/{esm2020 → esm2022}/page/abp-ng.components-page.mjs +4 -4
- package/esm2022/page/page-part.directive.mjs +77 -0
- package/esm2022/page/page-parts.component.mjs +48 -0
- package/esm2022/page/page.component.mjs +56 -0
- package/esm2022/page/page.module.mjs +39 -0
- package/{esm2020 → esm2022}/page/public-api.mjs +4 -4
- package/{esm2020 → esm2022}/public-api.mjs +4 -4
- package/{esm2020 → esm2022}/tree/abp-ng.components-tree.mjs +4 -4
- package/esm2022/tree/lib/components/tree.component.mjs +154 -0
- package/{esm2020 → esm2022}/tree/lib/disable-tree-style-loading.token.mjs +2 -2
- package/esm2022/tree/lib/templates/expanded-icon-template.directive.mjs +17 -0
- package/esm2022/tree/lib/templates/tree-node-template.directive.mjs +17 -0
- package/esm2022/tree/lib/tree.module.mjs +26 -0
- package/{esm2020 → esm2022}/tree/lib/utils/nz-tree-adapter.mjs +91 -91
- package/{esm2020 → esm2022}/tree/public-api.mjs +6 -6
- package/{fesm2020 → fesm2022}/abp-ng.components-chart.js.mjs +135 -135
- package/fesm2022/abp-ng.components-chart.js.mjs.map +1 -0
- package/{fesm2020 → fesm2022}/abp-ng.components-page.mjs +187 -187
- package/{fesm2020 → fesm2022}/abp-ng.components-page.mjs.map +1 -1
- package/{fesm2020 → fesm2022}/abp-ng.components-tree.mjs +269 -269
- package/fesm2022/abp-ng.components-tree.mjs.map +1 -0
- package/{fesm2020 → fesm2022}/abp-ng.components.mjs +4 -4
- package/index.d.ts +5 -5
- package/package.json +16 -29
- package/page/index.d.ts +5 -5
- package/page/page-part.directive.d.ts +31 -31
- package/page/page-parts.component.d.ts +18 -18
- package/page/page.component.d.ts +21 -21
- package/page/page.module.d.ts +13 -13
- package/page/public-api.d.ts +4 -4
- package/public-api.d.ts +1 -1
- package/tree/index.d.ts +5 -5
- package/tree/lib/components/tree.component.d.ts +51 -51
- package/tree/lib/disable-tree-style-loading.token.d.ts +2 -2
- package/tree/lib/templates/expanded-icon-template.directive.d.ts +8 -8
- package/tree/lib/templates/tree-node-template.directive.d.ts +8 -8
- package/tree/lib/tree.module.d.ts +13 -13
- package/tree/lib/utils/nz-tree-adapter.d.ts +38 -38
- package/tree/public-api.d.ts +6 -6
- package/esm2020/chart.js/chart.component.mjs +0 -140
- package/esm2020/chart.js/chart.module.mjs +0 -19
- package/esm2020/page/page-part.directive.mjs +0 -76
- package/esm2020/page/page-parts.component.mjs +0 -45
- package/esm2020/page/page.component.mjs +0 -55
- package/esm2020/page/page.module.mjs +0 -38
- package/esm2020/tree/lib/components/tree.component.mjs +0 -153
- package/esm2020/tree/lib/templates/expanded-icon-template.directive.mjs +0 -16
- package/esm2020/tree/lib/templates/tree-node-template.directive.mjs +0 -16
- package/esm2020/tree/lib/tree.module.mjs +0 -25
- package/fesm2015/abp-ng.components-chart.js.mjs +0 -175
- package/fesm2015/abp-ng.components-chart.js.mjs.map +0 -1
- package/fesm2015/abp-ng.components-page.mjs +0 -215
- package/fesm2015/abp-ng.components-page.mjs.map +0 -1
- package/fesm2015/abp-ng.components-tree.mjs +0 -300
- package/fesm2015/abp-ng.components-tree.mjs.map +0 -1
- package/fesm2015/abp-ng.components.mjs +0 -4
- package/fesm2015/abp-ng.components.mjs.map +0 -1
- package/fesm2020/abp-ng.components-chart.js.mjs.map +0 -1
- package/fesm2020/abp-ng.components-tree.mjs.map +0 -1
- /package/{fesm2020 → fesm2022}/abp-ng.components.mjs.map +0 -0
|
@@ -11,287 +11,287 @@ import { NzTreeModule } from 'ng-zorro-antd/tree';
|
|
|
11
11
|
import { of } from 'rxjs';
|
|
12
12
|
import * as i2 from '@angular/common';
|
|
13
13
|
|
|
14
|
-
class TreeNodeTemplateDirective {
|
|
15
|
-
constructor(template) {
|
|
16
|
-
this.template = template;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
22
|
-
type: Directive,
|
|
23
|
-
args: [{
|
|
24
|
-
selector: '[abpTreeNodeTemplate],[abp-tree-node-template]',
|
|
25
|
-
}]
|
|
14
|
+
class TreeNodeTemplateDirective {
|
|
15
|
+
constructor(template) {
|
|
16
|
+
this.template = template;
|
|
17
|
+
}
|
|
18
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.1", ngImport: i0, type: TreeNodeTemplateDirective, deps: [{ token: i0.TemplateRef }], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
19
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.0.1", type: TreeNodeTemplateDirective, selector: "[abpTreeNodeTemplate],[abp-tree-node-template]", ngImport: i0 }); }
|
|
20
|
+
}
|
|
21
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.1", ngImport: i0, type: TreeNodeTemplateDirective, decorators: [{
|
|
22
|
+
type: Directive,
|
|
23
|
+
args: [{
|
|
24
|
+
selector: '[abpTreeNodeTemplate],[abp-tree-node-template]',
|
|
25
|
+
}]
|
|
26
26
|
}], ctorParameters: function () { return [{ type: i0.TemplateRef }]; } });
|
|
27
27
|
|
|
28
|
-
class ExpandedIconTemplateDirective {
|
|
29
|
-
constructor(template) {
|
|
30
|
-
this.template = template;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
36
|
-
type: Directive,
|
|
37
|
-
args: [{
|
|
38
|
-
selector: '[abpTreeExpandedIconTemplate],[abp-tree-expanded-icon-template]',
|
|
39
|
-
}]
|
|
28
|
+
class ExpandedIconTemplateDirective {
|
|
29
|
+
constructor(template) {
|
|
30
|
+
this.template = template;
|
|
31
|
+
}
|
|
32
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.1", ngImport: i0, type: ExpandedIconTemplateDirective, deps: [{ token: i0.TemplateRef }], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
33
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.0.1", type: ExpandedIconTemplateDirective, selector: "[abpTreeExpandedIconTemplate],[abp-tree-expanded-icon-template]", ngImport: i0 }); }
|
|
34
|
+
}
|
|
35
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.1", ngImport: i0, type: ExpandedIconTemplateDirective, decorators: [{
|
|
36
|
+
type: Directive,
|
|
37
|
+
args: [{
|
|
38
|
+
selector: '[abpTreeExpandedIconTemplate],[abp-tree-expanded-icon-template]',
|
|
39
|
+
}]
|
|
40
40
|
}], ctorParameters: function () { return [{ type: i0.TemplateRef }]; } });
|
|
41
41
|
|
|
42
42
|
const DISABLE_TREE_STYLE_LOADING_TOKEN = new InjectionToken('DISABLE_TREE_STYLE_LOADING_TOKEN');
|
|
43
43
|
|
|
44
|
-
class TreeComponent {
|
|
45
|
-
constructor(lazyLoadService, subscriptionService, disableTreeStyleLoading, cdr) {
|
|
46
|
-
this.lazyLoadService = lazyLoadService;
|
|
47
|
-
this.subscriptionService = subscriptionService;
|
|
48
|
-
this.disableTreeStyleLoading = disableTreeStyleLoading;
|
|
49
|
-
this.cdr = cdr;
|
|
50
|
-
this.dropdowns = {};
|
|
51
|
-
this.checkedKeysChange = new EventEmitter();
|
|
52
|
-
this.expandedKeysChange = new EventEmitter();
|
|
53
|
-
this.selectedNodeChange = new EventEmitter();
|
|
54
|
-
this.dropOver = new EventEmitter();
|
|
55
|
-
this.nzExpandChange = new EventEmitter();
|
|
56
|
-
this.noAnimation = true;
|
|
57
|
-
this.checkedKeys = [];
|
|
58
|
-
this.nodes = [];
|
|
59
|
-
this.expandedKeys = [];
|
|
60
|
-
this.isNodeSelected = node => this.selectedNode?.id === node.key;
|
|
61
|
-
this.beforeDrop = (event) => {
|
|
62
|
-
this.dropPosition = event.pos;
|
|
63
|
-
return of(false);
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
ngOnInit() {
|
|
67
|
-
this.loadStyle();
|
|
68
|
-
}
|
|
69
|
-
loadStyle() {
|
|
70
|
-
if (this.disableTreeStyleLoading) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
const loaded$ = this.lazyLoadService.load(LOADING_STRATEGY.AppendAnonymousStyleToHead('ng-zorro-antd-tree.css'));
|
|
74
|
-
this.subscriptionService.addOne(loaded$);
|
|
75
|
-
}
|
|
76
|
-
findNode(target, nodes) {
|
|
77
|
-
for (const node of nodes) {
|
|
78
|
-
if (node.key === target.id) {
|
|
79
|
-
return node;
|
|
80
|
-
}
|
|
81
|
-
if (node.children) {
|
|
82
|
-
let res = this.findNode(target, node.children);
|
|
83
|
-
if (res) {
|
|
84
|
-
return res;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
onSelectedNodeChange(node) {
|
|
91
|
-
this.selectedNode = node.origin.entity;
|
|
92
|
-
if (this.changeCheckboxWithNode) {
|
|
93
|
-
let newVal;
|
|
94
|
-
if (node.isChecked) {
|
|
95
|
-
newVal = this.checkedKeys.filter(x => x !== node.key);
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
newVal = [...this.checkedKeys, node.key];
|
|
99
|
-
}
|
|
100
|
-
this.selectedNodeChange.emit(node);
|
|
101
|
-
this.checkedKeys = newVal;
|
|
102
|
-
this.checkedKeysChange.emit(newVal);
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
this.selectedNodeChange.emit(node.origin.entity);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
onCheckboxChange(event) {
|
|
109
|
-
this.checkedKeys = [...event.keys];
|
|
110
|
-
this.checkedKeysChange.emit(event.keys);
|
|
111
|
-
}
|
|
112
|
-
onExpandedKeysChange(event) {
|
|
113
|
-
this.expandedKeys = [...event.keys];
|
|
114
|
-
this.expandedKeysChange.emit(event.keys);
|
|
115
|
-
this.nzExpandChange.emit(event);
|
|
116
|
-
}
|
|
117
|
-
onDrop(event) {
|
|
118
|
-
event.event.stopPropagation();
|
|
119
|
-
event.event.preventDefault();
|
|
120
|
-
event.pos = this.dropPosition;
|
|
121
|
-
this.dropOver.emit(event);
|
|
122
|
-
}
|
|
123
|
-
initDropdown(key, dropdown) {
|
|
124
|
-
this.dropdowns[key] = dropdown;
|
|
125
|
-
}
|
|
126
|
-
setSelectedNode(node) {
|
|
127
|
-
let newSelectedNode = this.findNode(node, this.nodes);
|
|
128
|
-
this.selectedNode = { ...newSelectedNode };
|
|
129
|
-
this.cdr.markForCheck();
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
135
|
-
type: Component,
|
|
136
|
-
args: [{ selector: 'abp-tree', encapsulation: ViewEncapsulation.None, providers: [SubscriptionService], changeDetection: ChangeDetectionStrategy.OnPush, template: "<nz-tree\r\n [nzBeforeDrop]=\"beforeDrop\"\r\n [nzDraggable]=\"draggable\"\r\n [nzCheckStrictly]=\"checkStrictly\"\r\n [nzCheckable]=\"checkable\"\r\n [nzCheckedKeys]=\"checkedKeys\"\r\n [nzData]=\"nodes\"\r\n [nzTreeTemplate]=\"treeTemplate\"\r\n [nzExpandedKeys]=\"expandedKeys\"\r\n [nzExpandedIcon]=\"expandedIconTemplate?.template || defaultIconTemplate\"\r\n (nzExpandChange)=\"onExpandedKeysChange($event)\"\r\n (nzCheckBoxChange)=\"onCheckboxChange($event)\"\r\n (nzOnDrop)=\"onDrop($event)\"\r\n [nzNoAnimation]=\"noAnimation\"\r\n (nzContextMenu)=\"dropdowns[$event.node?.key]?.toggle()\"\r\n></nz-tree>\r\n<ng-template #treeTemplate let-node>\r\n <div\r\n [class.selected]=\"isNodeSelected(node)\"\r\n [title]=\"node.title\"\r\n (click)=\"onSelectedNodeChange(node)\"\r\n >\r\n <ng-container *ngTemplateOutlet=\"nodeTemplate; context: { $implicit: node }\"></ng-container>\r\n\r\n <ng-template #nodeTemplate let-node>\r\n <div class=\"d-inline-block\">\r\n <ng-container\r\n *ngTemplateOutlet=\"\r\n customNodeTemplate ? customNodeTemplate?.template : defaultNodeTemplate;\r\n context: { $implicit: node }\r\n \"\r\n ></ng-container>\r\n </div>\r\n\r\n <div\r\n #dropdown=\"ngbDropdown\"\r\n *ngIf=\"menu\"\r\n class=\"d-inline-block ms-1\"\r\n ngbDropdown\r\n placement=\"bottom\"\r\n container=\"body\"\r\n (abpInit)=\"initDropdown(node.key, dropdown)\"\r\n >\r\n <i\r\n class=\"fas fa-caret-down text-muted\"\r\n ngbDropdownToggle\r\n [class.dropdown-toggle]=\"false\"\r\n ></i>\r\n <div ngbDropdownMenu>\r\n <ng-template *ngTemplateOutlet=\"menu; context: { $implicit: node }\"></ng-template>\r\n </div>\r\n </div>\r\n </ng-template>\r\n\r\n <ng-template #defaultNodeTemplate let-node>\r\n <span>{{ node.title }}</span>\r\n </ng-template>\r\n </div>\r\n</ng-template>\r\n\r\n<ng-template #defaultIconTemplate let-node let-origin=\"origin\">\r\n <i aria-hidden=\"true\">\r\n <ng-container *ngTemplateOutlet=\"node.isExpanded ? minusIcon : plusIcon\"></ng-container\r\n ></i>\r\n</ng-template>\r\n\r\n<ng-template #minusIcon>\r\n <svg\r\n width=\"15\"\r\n height=\"15\"\r\n viewBox=\"0 0 24 24\"\r\n xmlns=\"http://www.w3.org/2000/svg\"\r\n fill-rule=\"evenodd\"\r\n clip-rule=\"evenodd\"\r\n >\r\n <path\r\n d=\"M11.5 0c6.347 0 11.5 5.153 11.5 11.5s-5.153 11.5-11.5 11.5-11.5-5.153-11.5-11.5 5.153-11.5 11.5-11.5zm0 1c5.795 0 10.5 4.705 10.5 10.5s-4.705 10.5-10.5 10.5-10.5-4.705-10.5-10.5 4.705-10.5 10.5-10.5zm-6.5 10h13v1h-13v-1z\"\r\n />\r\n </svg>\r\n</ng-template>\r\n\r\n<ng-template #plusIcon>\r\n <svg\r\n width=\"15\"\r\n height=\"15\"\r\n viewBox=\"0 0 24 24\"\r\n xmlns=\"http://www.w3.org/2000/svg\"\r\n fill-rule=\"evenodd\"\r\n clip-rule=\"evenodd\"\r\n >\r\n <path\r\n d=\"M11.5 0c6.347 0 11.5 5.153 11.5 11.5s-5.153 11.5-11.5 11.5-11.5-5.153-11.5-11.5 5.153-11.5 11.5-11.5zm0 1c5.795 0 10.5 4.705 10.5 10.5s-4.705 10.5-10.5 10.5-10.5-4.705-10.5-10.5 4.705-10.5 10.5-10.5zm.5 10h6v1h-6v6h-1v-6h-6v-1h6v-6h1v6z\"\r\n />\r\n </svg>\r\n</ng-template>\r\n", styles: ["abp-tree .ant-tree{color:inherit}abp-tree .ant-tree .ant-tree-node-content-wrapper.ant-tree-node-selected{background-color:transparent}abp-tree .ant-tree .ant-tree-switcher{line-height:17px;align-items:center;justify-content:center;display:inline-flex}abp-tree .ant-tree .ant-tree-node-content-wrapper{width:100%;padding:0}abp-tree .ant-tree .node-wrapper{width:100%;position:relative;display:inline-block;margin:0;line-height:30px;text-decoration:none;vertical-align:top;border-radius:2px;cursor:pointer;padding:0 5px 0 8px;border:1px solid transparent}abp-tree .ant-tree .ellipsis{position:absolute;right:8px;top:1px;cursor:pointer}\n"] }]
|
|
137
|
-
}], ctorParameters: function () { return [{ type: i1.LazyLoadService }, { type: i1.SubscriptionService }, { type: undefined, decorators: [{
|
|
138
|
-
type: Optional
|
|
139
|
-
}, {
|
|
140
|
-
type: Inject,
|
|
141
|
-
args: [DISABLE_TREE_STYLE_LOADING_TOKEN]
|
|
142
|
-
}] }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { menu: [{
|
|
143
|
-
type: ContentChild,
|
|
144
|
-
args: ['menu']
|
|
145
|
-
}], customNodeTemplate: [{
|
|
146
|
-
type: ContentChild,
|
|
147
|
-
args: [TreeNodeTemplateDirective]
|
|
148
|
-
}], expandedIconTemplate: [{
|
|
149
|
-
type: ContentChild,
|
|
150
|
-
args: [ExpandedIconTemplateDirective]
|
|
151
|
-
}], checkedKeysChange: [{
|
|
152
|
-
type: Output
|
|
153
|
-
}], expandedKeysChange: [{
|
|
154
|
-
type: Output
|
|
155
|
-
}], selectedNodeChange: [{
|
|
156
|
-
type: Output
|
|
157
|
-
}], dropOver: [{
|
|
158
|
-
type: Output
|
|
159
|
-
}], nzExpandChange: [{
|
|
160
|
-
type: Output
|
|
161
|
-
}], noAnimation: [{
|
|
162
|
-
type: Input
|
|
163
|
-
}], draggable: [{
|
|
164
|
-
type: Input
|
|
165
|
-
}], checkable: [{
|
|
166
|
-
type: Input
|
|
167
|
-
}], checkStrictly: [{
|
|
168
|
-
type: Input
|
|
169
|
-
}], checkedKeys: [{
|
|
170
|
-
type: Input
|
|
171
|
-
}], nodes: [{
|
|
172
|
-
type: Input
|
|
173
|
-
}], expandedKeys: [{
|
|
174
|
-
type: Input
|
|
175
|
-
}], selectedNode: [{
|
|
176
|
-
type: Input
|
|
177
|
-
}], changeCheckboxWithNode: [{
|
|
178
|
-
type: Input
|
|
179
|
-
}], isNodeSelected: [{
|
|
180
|
-
type: Input
|
|
181
|
-
}], beforeDrop: [{
|
|
182
|
-
type: Input
|
|
44
|
+
class TreeComponent {
|
|
45
|
+
constructor(lazyLoadService, subscriptionService, disableTreeStyleLoading, cdr) {
|
|
46
|
+
this.lazyLoadService = lazyLoadService;
|
|
47
|
+
this.subscriptionService = subscriptionService;
|
|
48
|
+
this.disableTreeStyleLoading = disableTreeStyleLoading;
|
|
49
|
+
this.cdr = cdr;
|
|
50
|
+
this.dropdowns = {};
|
|
51
|
+
this.checkedKeysChange = new EventEmitter();
|
|
52
|
+
this.expandedKeysChange = new EventEmitter();
|
|
53
|
+
this.selectedNodeChange = new EventEmitter();
|
|
54
|
+
this.dropOver = new EventEmitter();
|
|
55
|
+
this.nzExpandChange = new EventEmitter();
|
|
56
|
+
this.noAnimation = true;
|
|
57
|
+
this.checkedKeys = [];
|
|
58
|
+
this.nodes = [];
|
|
59
|
+
this.expandedKeys = [];
|
|
60
|
+
this.isNodeSelected = node => this.selectedNode?.id === node.key;
|
|
61
|
+
this.beforeDrop = (event) => {
|
|
62
|
+
this.dropPosition = event.pos;
|
|
63
|
+
return of(false);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
ngOnInit() {
|
|
67
|
+
this.loadStyle();
|
|
68
|
+
}
|
|
69
|
+
loadStyle() {
|
|
70
|
+
if (this.disableTreeStyleLoading) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const loaded$ = this.lazyLoadService.load(LOADING_STRATEGY.AppendAnonymousStyleToHead('ng-zorro-antd-tree.css'));
|
|
74
|
+
this.subscriptionService.addOne(loaded$);
|
|
75
|
+
}
|
|
76
|
+
findNode(target, nodes) {
|
|
77
|
+
for (const node of nodes) {
|
|
78
|
+
if (node.key === target.id) {
|
|
79
|
+
return node;
|
|
80
|
+
}
|
|
81
|
+
if (node.children) {
|
|
82
|
+
let res = this.findNode(target, node.children);
|
|
83
|
+
if (res) {
|
|
84
|
+
return res;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
onSelectedNodeChange(node) {
|
|
91
|
+
this.selectedNode = node.origin.entity;
|
|
92
|
+
if (this.changeCheckboxWithNode) {
|
|
93
|
+
let newVal;
|
|
94
|
+
if (node.isChecked) {
|
|
95
|
+
newVal = this.checkedKeys.filter(x => x !== node.key);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
newVal = [...this.checkedKeys, node.key];
|
|
99
|
+
}
|
|
100
|
+
this.selectedNodeChange.emit(node);
|
|
101
|
+
this.checkedKeys = newVal;
|
|
102
|
+
this.checkedKeysChange.emit(newVal);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
this.selectedNodeChange.emit(node.origin.entity);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
onCheckboxChange(event) {
|
|
109
|
+
this.checkedKeys = [...event.keys];
|
|
110
|
+
this.checkedKeysChange.emit(event.keys);
|
|
111
|
+
}
|
|
112
|
+
onExpandedKeysChange(event) {
|
|
113
|
+
this.expandedKeys = [...event.keys];
|
|
114
|
+
this.expandedKeysChange.emit(event.keys);
|
|
115
|
+
this.nzExpandChange.emit(event);
|
|
116
|
+
}
|
|
117
|
+
onDrop(event) {
|
|
118
|
+
event.event.stopPropagation();
|
|
119
|
+
event.event.preventDefault();
|
|
120
|
+
event.pos = this.dropPosition;
|
|
121
|
+
this.dropOver.emit(event);
|
|
122
|
+
}
|
|
123
|
+
initDropdown(key, dropdown) {
|
|
124
|
+
this.dropdowns[key] = dropdown;
|
|
125
|
+
}
|
|
126
|
+
setSelectedNode(node) {
|
|
127
|
+
let newSelectedNode = this.findNode(node, this.nodes);
|
|
128
|
+
this.selectedNode = { ...newSelectedNode };
|
|
129
|
+
this.cdr.markForCheck();
|
|
130
|
+
}
|
|
131
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.1", ngImport: i0, type: TreeComponent, deps: [{ token: i1.LazyLoadService }, { token: i1.SubscriptionService }, { token: DISABLE_TREE_STYLE_LOADING_TOKEN, optional: true }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
132
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.0.1", type: TreeComponent, selector: "abp-tree", inputs: { noAnimation: "noAnimation", draggable: "draggable", checkable: "checkable", checkStrictly: "checkStrictly", checkedKeys: "checkedKeys", nodes: "nodes", expandedKeys: "expandedKeys", selectedNode: "selectedNode", changeCheckboxWithNode: "changeCheckboxWithNode", isNodeSelected: "isNodeSelected", beforeDrop: "beforeDrop" }, outputs: { checkedKeysChange: "checkedKeysChange", expandedKeysChange: "expandedKeysChange", selectedNodeChange: "selectedNodeChange", dropOver: "dropOver", nzExpandChange: "nzExpandChange" }, providers: [SubscriptionService], queries: [{ propertyName: "menu", first: true, predicate: ["menu"], descendants: true }, { propertyName: "customNodeTemplate", first: true, predicate: TreeNodeTemplateDirective, descendants: true }, { propertyName: "expandedIconTemplate", first: true, predicate: ExpandedIconTemplateDirective, descendants: true }], ngImport: i0, template: "<nz-tree\r\n [nzBeforeDrop]=\"beforeDrop\"\r\n [nzDraggable]=\"draggable\"\r\n [nzCheckStrictly]=\"checkStrictly\"\r\n [nzCheckable]=\"checkable\"\r\n [nzCheckedKeys]=\"checkedKeys\"\r\n [nzData]=\"nodes\"\r\n [nzTreeTemplate]=\"treeTemplate\"\r\n [nzExpandedKeys]=\"expandedKeys\"\r\n [nzExpandedIcon]=\"expandedIconTemplate?.template || defaultIconTemplate\"\r\n (nzExpandChange)=\"onExpandedKeysChange($event)\"\r\n (nzCheckBoxChange)=\"onCheckboxChange($event)\"\r\n (nzOnDrop)=\"onDrop($event)\"\r\n [nzNoAnimation]=\"noAnimation\"\r\n (nzContextMenu)=\"dropdowns[$event.node?.key]?.toggle()\"\r\n></nz-tree>\r\n<ng-template #treeTemplate let-node>\r\n <div\r\n [class.selected]=\"isNodeSelected(node)\"\r\n [title]=\"node.title\"\r\n (click)=\"onSelectedNodeChange(node)\"\r\n >\r\n <ng-container *ngTemplateOutlet=\"nodeTemplate; context: { $implicit: node }\"></ng-container>\r\n\r\n <ng-template #nodeTemplate let-node>\r\n <div class=\"d-inline-block\">\r\n <ng-container\r\n *ngTemplateOutlet=\"\r\n customNodeTemplate ? customNodeTemplate?.template : defaultNodeTemplate;\r\n context: { $implicit: node }\r\n \"\r\n ></ng-container>\r\n </div>\r\n\r\n <div\r\n #dropdown=\"ngbDropdown\"\r\n *ngIf=\"menu\"\r\n class=\"d-inline-block ms-1\"\r\n ngbDropdown\r\n placement=\"bottom\"\r\n container=\"body\"\r\n (abpInit)=\"initDropdown(node.key, dropdown)\"\r\n >\r\n <i\r\n class=\"fas fa-caret-down text-muted\"\r\n ngbDropdownToggle\r\n [class.dropdown-toggle]=\"false\"\r\n aria-hidden=\"true\"\r\n ></i>\r\n <div ngbDropdownMenu>\r\n <ng-template *ngTemplateOutlet=\"menu; context: { $implicit: node }\"></ng-template>\r\n </div>\r\n </div>\r\n </ng-template>\r\n\r\n <ng-template #defaultNodeTemplate let-node>\r\n <span>{{ node.title }}</span>\r\n </ng-template>\r\n </div>\r\n</ng-template>\r\n\r\n<ng-template #defaultIconTemplate let-node let-origin=\"origin\">\r\n <i aria-hidden=\"true\">\r\n <ng-container *ngTemplateOutlet=\"node.isExpanded ? minusIcon : plusIcon\"></ng-container\r\n ></i>\r\n</ng-template>\r\n\r\n<ng-template #minusIcon>\r\n <svg\r\n width=\"15\"\r\n height=\"15\"\r\n viewBox=\"0 0 24 24\"\r\n xmlns=\"http://www.w3.org/2000/svg\"\r\n fill-rule=\"evenodd\"\r\n clip-rule=\"evenodd\"\r\n >\r\n <path\r\n d=\"M11.5 0c6.347 0 11.5 5.153 11.5 11.5s-5.153 11.5-11.5 11.5-11.5-5.153-11.5-11.5 5.153-11.5 11.5-11.5zm0 1c5.795 0 10.5 4.705 10.5 10.5s-4.705 10.5-10.5 10.5-10.5-4.705-10.5-10.5 4.705-10.5 10.5-10.5zm-6.5 10h13v1h-13v-1z\"\r\n />\r\n </svg>\r\n</ng-template>\r\n\r\n<ng-template #plusIcon>\r\n <svg\r\n width=\"15\"\r\n height=\"15\"\r\n viewBox=\"0 0 24 24\"\r\n xmlns=\"http://www.w3.org/2000/svg\"\r\n fill-rule=\"evenodd\"\r\n clip-rule=\"evenodd\"\r\n >\r\n <path\r\n d=\"M11.5 0c6.347 0 11.5 5.153 11.5 11.5s-5.153 11.5-11.5 11.5-11.5-5.153-11.5-11.5 5.153-11.5 11.5-11.5zm0 1c5.795 0 10.5 4.705 10.5 10.5s-4.705 10.5-10.5 10.5-10.5-4.705-10.5-10.5 4.705-10.5 10.5-10.5zm.5 10h6v1h-6v6h-1v-6h-6v-1h6v-6h1v6z\"\r\n />\r\n </svg>\r\n</ng-template>\r\n", styles: ["abp-tree .ant-tree{color:inherit}abp-tree .ant-tree .ant-tree-node-content-wrapper.ant-tree-node-selected{background-color:transparent}abp-tree .ant-tree .ant-tree-switcher{line-height:17px;align-items:center;justify-content:center;display:inline-flex}abp-tree .ant-tree .ant-tree-node-content-wrapper{width:100%;padding:0}abp-tree .ant-tree .node-wrapper{width:100%;position:relative;display:inline-block;margin:0;line-height:30px;text-decoration:none;vertical-align:top;border-radius:2px;cursor:pointer;padding:0 5px 0 8px;border:1px solid transparent}abp-tree .ant-tree .ellipsis{position:absolute;right:8px;top:1px;cursor:pointer}\n"], dependencies: [{ kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: i1.InitDirective, selector: "[abpInit]", outputs: ["abpInit"] }, { kind: "component", type: i3.NzTreeComponent, selector: "nz-tree", inputs: ["nzShowIcon", "nzHideUnMatched", "nzBlockNode", "nzExpandAll", "nzSelectMode", "nzCheckStrictly", "nzShowExpand", "nzShowLine", "nzCheckable", "nzAsyncData", "nzDraggable", "nzMultiple", "nzExpandedIcon", "nzVirtualItemSize", "nzVirtualMaxBufferPx", "nzVirtualMinBufferPx", "nzVirtualHeight", "nzTreeTemplate", "nzBeforeDrop", "nzData", "nzExpandedKeys", "nzSelectedKeys", "nzCheckedKeys", "nzSearchValue", "nzSearchFunc"], outputs: ["nzExpandedKeysChange", "nzSelectedKeysChange", "nzCheckedKeysChange", "nzSearchValueChange", "nzClick", "nzDblClick", "nzContextMenu", "nzCheckBoxChange", "nzExpandChange", "nzOnDragStart", "nzOnDragEnter", "nzOnDragOver", "nzOnDragLeave", "nzOnDrop", "nzOnDragEnd"], exportAs: ["nzTree"] }, { kind: "directive", type: i4.NgbDropdown, selector: "[ngbDropdown]", inputs: ["autoClose", "dropdownClass", "open", "placement", "popperOptions", "container", "display"], outputs: ["openChange"], exportAs: ["ngbDropdown"] }, { kind: "directive", type: i4.NgbDropdownToggle, selector: "[ngbDropdownToggle]" }, { kind: "directive", type: i4.NgbDropdownMenu, selector: "[ngbDropdownMenu]" }, { kind: "directive", type: i5.NzNoAnimationDirective, selector: "[nzNoAnimation]", inputs: ["nzNoAnimation"], exportAs: ["nzNoAnimation"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
|
|
133
|
+
}
|
|
134
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.1", ngImport: i0, type: TreeComponent, decorators: [{
|
|
135
|
+
type: Component,
|
|
136
|
+
args: [{ selector: 'abp-tree', encapsulation: ViewEncapsulation.None, providers: [SubscriptionService], changeDetection: ChangeDetectionStrategy.OnPush, template: "<nz-tree\r\n [nzBeforeDrop]=\"beforeDrop\"\r\n [nzDraggable]=\"draggable\"\r\n [nzCheckStrictly]=\"checkStrictly\"\r\n [nzCheckable]=\"checkable\"\r\n [nzCheckedKeys]=\"checkedKeys\"\r\n [nzData]=\"nodes\"\r\n [nzTreeTemplate]=\"treeTemplate\"\r\n [nzExpandedKeys]=\"expandedKeys\"\r\n [nzExpandedIcon]=\"expandedIconTemplate?.template || defaultIconTemplate\"\r\n (nzExpandChange)=\"onExpandedKeysChange($event)\"\r\n (nzCheckBoxChange)=\"onCheckboxChange($event)\"\r\n (nzOnDrop)=\"onDrop($event)\"\r\n [nzNoAnimation]=\"noAnimation\"\r\n (nzContextMenu)=\"dropdowns[$event.node?.key]?.toggle()\"\r\n></nz-tree>\r\n<ng-template #treeTemplate let-node>\r\n <div\r\n [class.selected]=\"isNodeSelected(node)\"\r\n [title]=\"node.title\"\r\n (click)=\"onSelectedNodeChange(node)\"\r\n >\r\n <ng-container *ngTemplateOutlet=\"nodeTemplate; context: { $implicit: node }\"></ng-container>\r\n\r\n <ng-template #nodeTemplate let-node>\r\n <div class=\"d-inline-block\">\r\n <ng-container\r\n *ngTemplateOutlet=\"\r\n customNodeTemplate ? customNodeTemplate?.template : defaultNodeTemplate;\r\n context: { $implicit: node }\r\n \"\r\n ></ng-container>\r\n </div>\r\n\r\n <div\r\n #dropdown=\"ngbDropdown\"\r\n *ngIf=\"menu\"\r\n class=\"d-inline-block ms-1\"\r\n ngbDropdown\r\n placement=\"bottom\"\r\n container=\"body\"\r\n (abpInit)=\"initDropdown(node.key, dropdown)\"\r\n >\r\n <i\r\n class=\"fas fa-caret-down text-muted\"\r\n ngbDropdownToggle\r\n [class.dropdown-toggle]=\"false\"\r\n aria-hidden=\"true\"\r\n ></i>\r\n <div ngbDropdownMenu>\r\n <ng-template *ngTemplateOutlet=\"menu; context: { $implicit: node }\"></ng-template>\r\n </div>\r\n </div>\r\n </ng-template>\r\n\r\n <ng-template #defaultNodeTemplate let-node>\r\n <span>{{ node.title }}</span>\r\n </ng-template>\r\n </div>\r\n</ng-template>\r\n\r\n<ng-template #defaultIconTemplate let-node let-origin=\"origin\">\r\n <i aria-hidden=\"true\">\r\n <ng-container *ngTemplateOutlet=\"node.isExpanded ? minusIcon : plusIcon\"></ng-container\r\n ></i>\r\n</ng-template>\r\n\r\n<ng-template #minusIcon>\r\n <svg\r\n width=\"15\"\r\n height=\"15\"\r\n viewBox=\"0 0 24 24\"\r\n xmlns=\"http://www.w3.org/2000/svg\"\r\n fill-rule=\"evenodd\"\r\n clip-rule=\"evenodd\"\r\n >\r\n <path\r\n d=\"M11.5 0c6.347 0 11.5 5.153 11.5 11.5s-5.153 11.5-11.5 11.5-11.5-5.153-11.5-11.5 5.153-11.5 11.5-11.5zm0 1c5.795 0 10.5 4.705 10.5 10.5s-4.705 10.5-10.5 10.5-10.5-4.705-10.5-10.5 4.705-10.5 10.5-10.5zm-6.5 10h13v1h-13v-1z\"\r\n />\r\n </svg>\r\n</ng-template>\r\n\r\n<ng-template #plusIcon>\r\n <svg\r\n width=\"15\"\r\n height=\"15\"\r\n viewBox=\"0 0 24 24\"\r\n xmlns=\"http://www.w3.org/2000/svg\"\r\n fill-rule=\"evenodd\"\r\n clip-rule=\"evenodd\"\r\n >\r\n <path\r\n d=\"M11.5 0c6.347 0 11.5 5.153 11.5 11.5s-5.153 11.5-11.5 11.5-11.5-5.153-11.5-11.5 5.153-11.5 11.5-11.5zm0 1c5.795 0 10.5 4.705 10.5 10.5s-4.705 10.5-10.5 10.5-10.5-4.705-10.5-10.5 4.705-10.5 10.5-10.5zm.5 10h6v1h-6v6h-1v-6h-6v-1h6v-6h1v6z\"\r\n />\r\n </svg>\r\n</ng-template>\r\n", styles: ["abp-tree .ant-tree{color:inherit}abp-tree .ant-tree .ant-tree-node-content-wrapper.ant-tree-node-selected{background-color:transparent}abp-tree .ant-tree .ant-tree-switcher{line-height:17px;align-items:center;justify-content:center;display:inline-flex}abp-tree .ant-tree .ant-tree-node-content-wrapper{width:100%;padding:0}abp-tree .ant-tree .node-wrapper{width:100%;position:relative;display:inline-block;margin:0;line-height:30px;text-decoration:none;vertical-align:top;border-radius:2px;cursor:pointer;padding:0 5px 0 8px;border:1px solid transparent}abp-tree .ant-tree .ellipsis{position:absolute;right:8px;top:1px;cursor:pointer}\n"] }]
|
|
137
|
+
}], ctorParameters: function () { return [{ type: i1.LazyLoadService }, { type: i1.SubscriptionService }, { type: undefined, decorators: [{
|
|
138
|
+
type: Optional
|
|
139
|
+
}, {
|
|
140
|
+
type: Inject,
|
|
141
|
+
args: [DISABLE_TREE_STYLE_LOADING_TOKEN]
|
|
142
|
+
}] }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { menu: [{
|
|
143
|
+
type: ContentChild,
|
|
144
|
+
args: ['menu']
|
|
145
|
+
}], customNodeTemplate: [{
|
|
146
|
+
type: ContentChild,
|
|
147
|
+
args: [TreeNodeTemplateDirective]
|
|
148
|
+
}], expandedIconTemplate: [{
|
|
149
|
+
type: ContentChild,
|
|
150
|
+
args: [ExpandedIconTemplateDirective]
|
|
151
|
+
}], checkedKeysChange: [{
|
|
152
|
+
type: Output
|
|
153
|
+
}], expandedKeysChange: [{
|
|
154
|
+
type: Output
|
|
155
|
+
}], selectedNodeChange: [{
|
|
156
|
+
type: Output
|
|
157
|
+
}], dropOver: [{
|
|
158
|
+
type: Output
|
|
159
|
+
}], nzExpandChange: [{
|
|
160
|
+
type: Output
|
|
161
|
+
}], noAnimation: [{
|
|
162
|
+
type: Input
|
|
163
|
+
}], draggable: [{
|
|
164
|
+
type: Input
|
|
165
|
+
}], checkable: [{
|
|
166
|
+
type: Input
|
|
167
|
+
}], checkStrictly: [{
|
|
168
|
+
type: Input
|
|
169
|
+
}], checkedKeys: [{
|
|
170
|
+
type: Input
|
|
171
|
+
}], nodes: [{
|
|
172
|
+
type: Input
|
|
173
|
+
}], expandedKeys: [{
|
|
174
|
+
type: Input
|
|
175
|
+
}], selectedNode: [{
|
|
176
|
+
type: Input
|
|
177
|
+
}], changeCheckboxWithNode: [{
|
|
178
|
+
type: Input
|
|
179
|
+
}], isNodeSelected: [{
|
|
180
|
+
type: Input
|
|
181
|
+
}], beforeDrop: [{
|
|
182
|
+
type: Input
|
|
183
183
|
}] } });
|
|
184
184
|
|
|
185
|
-
const templates = [TreeNodeTemplateDirective, ExpandedIconTemplateDirective];
|
|
186
|
-
const exported = [...templates, TreeComponent];
|
|
187
|
-
class TreeModule {
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
193
|
-
type: NgModule,
|
|
194
|
-
args: [{
|
|
195
|
-
imports: [CoreModule, NzTreeModule, NgbDropdownModule, NzNoAnimationModule],
|
|
196
|
-
exports: [...exported],
|
|
197
|
-
declarations: [...exported],
|
|
198
|
-
}]
|
|
185
|
+
const templates = [TreeNodeTemplateDirective, ExpandedIconTemplateDirective];
|
|
186
|
+
const exported = [...templates, TreeComponent];
|
|
187
|
+
class TreeModule {
|
|
188
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.1", ngImport: i0, type: TreeModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
189
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.0.1", ngImport: i0, type: TreeModule, declarations: [TreeNodeTemplateDirective, ExpandedIconTemplateDirective, TreeComponent], imports: [CoreModule, NzTreeModule, NgbDropdownModule, NzNoAnimationModule], exports: [TreeNodeTemplateDirective, ExpandedIconTemplateDirective, TreeComponent] }); }
|
|
190
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.0.1", ngImport: i0, type: TreeModule, imports: [CoreModule, NzTreeModule, NgbDropdownModule, NzNoAnimationModule] }); }
|
|
191
|
+
}
|
|
192
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.1", ngImport: i0, type: TreeModule, decorators: [{
|
|
193
|
+
type: NgModule,
|
|
194
|
+
args: [{
|
|
195
|
+
imports: [CoreModule, NzTreeModule, NgbDropdownModule, NzNoAnimationModule],
|
|
196
|
+
exports: [...exported],
|
|
197
|
+
declarations: [...exported],
|
|
198
|
+
}]
|
|
199
199
|
}] });
|
|
200
200
|
|
|
201
|
-
class BaseNode {
|
|
202
|
-
constructor(id, parentId) {
|
|
203
|
-
this.id = id;
|
|
204
|
-
this.parentId = parentId;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
class TreeNode extends BaseNode {
|
|
208
|
-
constructor(entity, nameResolver = ent => ent.displayName || ent.name) {
|
|
209
|
-
super(entity.id, entity.parentId);
|
|
210
|
-
this.entity = entity;
|
|
211
|
-
this.nameResolver = nameResolver;
|
|
212
|
-
this.icon = null;
|
|
213
|
-
this.children = [];
|
|
214
|
-
this.isLeaf = true;
|
|
215
|
-
this.checked = false;
|
|
216
|
-
this.selected = false;
|
|
217
|
-
this.expanded = false;
|
|
218
|
-
this.selectable = true;
|
|
219
|
-
this.disabled = false;
|
|
220
|
-
this.disableCheckbox = false;
|
|
221
|
-
this.key = entity.id;
|
|
222
|
-
this.title = nameResolver(entity);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
class TreeAdapter {
|
|
226
|
-
constructor(list = []) {
|
|
227
|
-
this.list = list;
|
|
228
|
-
this.tree = createTreeFromList(this.list);
|
|
229
|
-
}
|
|
230
|
-
getList() {
|
|
231
|
-
return this.list;
|
|
232
|
-
}
|
|
233
|
-
getTree() {
|
|
234
|
-
return this.tree;
|
|
235
|
-
}
|
|
236
|
-
handleDrop({ key, parentNode }) {
|
|
237
|
-
const index = this.list.findIndex(({ id }) => id === key);
|
|
238
|
-
this.list[index].parentId = parentNode ? parentNode.key : null;
|
|
239
|
-
this.tree = createTreeFromList(this.list);
|
|
240
|
-
}
|
|
241
|
-
handleRemove({ key }) {
|
|
242
|
-
this.updateTreeFromList(this.list.filter(item => item.id !== key));
|
|
243
|
-
}
|
|
244
|
-
handleUpdate({ key, children }) {
|
|
245
|
-
/**
|
|
246
|
-
* When we need to update a node with new children, first we need to remove any descendant nodes.
|
|
247
|
-
* If we remove immediate children and create a new tree, any other descendant nodes will be removed
|
|
248
|
-
* and we won't need to recursively remove sub children.
|
|
249
|
-
* Then, you simply add back the new children and create a new tree.
|
|
250
|
-
*/
|
|
251
|
-
const listWithDescendantNodesRemoved = this.updateTreeFromList(this.list.filter(item => item.parentId !== key));
|
|
252
|
-
this.updateTreeFromList(listWithDescendantNodesRemoved.concat(children));
|
|
253
|
-
}
|
|
254
|
-
updateTreeFromList(list) {
|
|
255
|
-
this.tree = createTreeFromList(list);
|
|
256
|
-
this.list = createListFromTree(this.tree);
|
|
257
|
-
return this.list;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
// UTILITY FUNCTIONS
|
|
261
|
-
function createTreeFromList(list) {
|
|
262
|
-
const map = createMapFromList(list);
|
|
263
|
-
const tree = [];
|
|
264
|
-
list.forEach(row => {
|
|
265
|
-
const parentId = row.parentId;
|
|
266
|
-
const node = map.get(row.id);
|
|
267
|
-
if (parentId) {
|
|
268
|
-
const parent = map.get(parentId);
|
|
269
|
-
if (!parent)
|
|
270
|
-
return;
|
|
271
|
-
parent.children.push(node);
|
|
272
|
-
parent.isLeaf = false;
|
|
273
|
-
}
|
|
274
|
-
else {
|
|
275
|
-
tree.push(node);
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
return tree;
|
|
279
|
-
}
|
|
280
|
-
function createListFromTree(tree, list = []) {
|
|
281
|
-
tree.forEach(node => {
|
|
282
|
-
list.push({ ...node.entity, parentId: node.parentId });
|
|
283
|
-
if (node.children)
|
|
284
|
-
createListFromTree(node.children, list);
|
|
285
|
-
});
|
|
286
|
-
return list;
|
|
287
|
-
}
|
|
288
|
-
function createMapFromList(list, map = new Map()) {
|
|
289
|
-
list.forEach(row => map.set(row.id, new TreeNode(row)));
|
|
290
|
-
return map;
|
|
201
|
+
class BaseNode {
|
|
202
|
+
constructor(id, parentId) {
|
|
203
|
+
this.id = id;
|
|
204
|
+
this.parentId = parentId;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
class TreeNode extends BaseNode {
|
|
208
|
+
constructor(entity, nameResolver = ent => ent.displayName || ent.name) {
|
|
209
|
+
super(entity.id, entity.parentId);
|
|
210
|
+
this.entity = entity;
|
|
211
|
+
this.nameResolver = nameResolver;
|
|
212
|
+
this.icon = null;
|
|
213
|
+
this.children = [];
|
|
214
|
+
this.isLeaf = true;
|
|
215
|
+
this.checked = false;
|
|
216
|
+
this.selected = false;
|
|
217
|
+
this.expanded = false;
|
|
218
|
+
this.selectable = true;
|
|
219
|
+
this.disabled = false;
|
|
220
|
+
this.disableCheckbox = false;
|
|
221
|
+
this.key = entity.id;
|
|
222
|
+
this.title = nameResolver(entity);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
class TreeAdapter {
|
|
226
|
+
constructor(list = []) {
|
|
227
|
+
this.list = list;
|
|
228
|
+
this.tree = createTreeFromList(this.list);
|
|
229
|
+
}
|
|
230
|
+
getList() {
|
|
231
|
+
return this.list;
|
|
232
|
+
}
|
|
233
|
+
getTree() {
|
|
234
|
+
return this.tree;
|
|
235
|
+
}
|
|
236
|
+
handleDrop({ key, parentNode }) {
|
|
237
|
+
const index = this.list.findIndex(({ id }) => id === key);
|
|
238
|
+
this.list[index].parentId = parentNode ? parentNode.key : null;
|
|
239
|
+
this.tree = createTreeFromList(this.list);
|
|
240
|
+
}
|
|
241
|
+
handleRemove({ key }) {
|
|
242
|
+
this.updateTreeFromList(this.list.filter(item => item.id !== key));
|
|
243
|
+
}
|
|
244
|
+
handleUpdate({ key, children }) {
|
|
245
|
+
/**
|
|
246
|
+
* When we need to update a node with new children, first we need to remove any descendant nodes.
|
|
247
|
+
* If we remove immediate children and create a new tree, any other descendant nodes will be removed
|
|
248
|
+
* and we won't need to recursively remove sub children.
|
|
249
|
+
* Then, you simply add back the new children and create a new tree.
|
|
250
|
+
*/
|
|
251
|
+
const listWithDescendantNodesRemoved = this.updateTreeFromList(this.list.filter(item => item.parentId !== key));
|
|
252
|
+
this.updateTreeFromList(listWithDescendantNodesRemoved.concat(children));
|
|
253
|
+
}
|
|
254
|
+
updateTreeFromList(list) {
|
|
255
|
+
this.tree = createTreeFromList(list);
|
|
256
|
+
this.list = createListFromTree(this.tree);
|
|
257
|
+
return this.list;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
// UTILITY FUNCTIONS
|
|
261
|
+
function createTreeFromList(list) {
|
|
262
|
+
const map = createMapFromList(list);
|
|
263
|
+
const tree = [];
|
|
264
|
+
list.forEach(row => {
|
|
265
|
+
const parentId = row.parentId;
|
|
266
|
+
const node = map.get(row.id);
|
|
267
|
+
if (parentId) {
|
|
268
|
+
const parent = map.get(parentId);
|
|
269
|
+
if (!parent)
|
|
270
|
+
return;
|
|
271
|
+
parent.children.push(node);
|
|
272
|
+
parent.isLeaf = false;
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
tree.push(node);
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
return tree;
|
|
279
|
+
}
|
|
280
|
+
function createListFromTree(tree, list = []) {
|
|
281
|
+
tree.forEach(node => {
|
|
282
|
+
list.push({ ...node.entity, parentId: node.parentId });
|
|
283
|
+
if (node.children)
|
|
284
|
+
createListFromTree(node.children, list);
|
|
285
|
+
});
|
|
286
|
+
return list;
|
|
287
|
+
}
|
|
288
|
+
function createMapFromList(list, map = new Map()) {
|
|
289
|
+
list.forEach(row => map.set(row.id, new TreeNode(row)));
|
|
290
|
+
return map;
|
|
291
291
|
}
|
|
292
292
|
|
|
293
|
-
/**
|
|
294
|
-
* Generated bundle index. Do not edit.
|
|
293
|
+
/**
|
|
294
|
+
* Generated bundle index. Do not edit.
|
|
295
295
|
*/
|
|
296
296
|
|
|
297
297
|
export { BaseNode, DISABLE_TREE_STYLE_LOADING_TOKEN, ExpandedIconTemplateDirective, TreeAdapter, TreeComponent, TreeModule, TreeNode, TreeNodeTemplateDirective };
|