@sdcorejs/angular 21.0.4 → 21.0.6
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/assets/{scss/README.md → STYLE-GUIDE.md} +3 -0
- package/fesm2022/sdcorejs-angular-components-form-generic.mjs +2 -2
- package/fesm2022/sdcorejs-angular-components-form-generic.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-org-chart.mjs +110 -0
- package/fesm2022/sdcorejs-angular-components-org-chart.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-components-query-bar.mjs +37 -8
- package/fesm2022/sdcorejs-angular-components-query-bar.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-query-builder.mjs +258 -60
- package/fesm2022/sdcorejs-angular-components-query-builder.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-section.mjs +8 -5
- package/fesm2022/sdcorejs-angular-components-section.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-splitter.mjs +24 -13
- package/fesm2022/sdcorejs-angular-components-splitter.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-table.mjs +6 -2
- package/fesm2022/sdcorejs-angular-components-table.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-tree.mjs +526 -0
- package/fesm2022/sdcorejs-angular-components-tree.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-components.mjs +2 -0
- package/fesm2022/sdcorejs-angular-components.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-autocomplete.mjs +2 -2
- package/fesm2022/sdcorejs-angular-forms-autocomplete.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-select.mjs +66 -7
- package/fesm2022/sdcorejs-angular-forms-select.mjs.map +1 -1
- package/package.json +10 -2
- package/types/sdcorejs-angular-components-org-chart.d.ts +67 -0
- package/types/sdcorejs-angular-components-query-bar.d.ts +37 -2
- package/types/sdcorejs-angular-components-query-builder.d.ts +96 -30
- package/types/sdcorejs-angular-components-section.d.ts +4 -1
- package/types/sdcorejs-angular-components-splitter.d.ts +20 -1
- package/types/sdcorejs-angular-components-table.d.ts +2 -0
- package/types/sdcorejs-angular-components-tree.d.ts +253 -0
- package/types/sdcorejs-angular-components.d.ts +2 -0
- package/types/sdcorejs-angular-forms-select.d.ts +29 -3
|
@@ -0,0 +1,526 @@
|
|
|
1
|
+
import * as i1 from '@angular/common';
|
|
2
|
+
import { CommonModule } from '@angular/common';
|
|
3
|
+
import * as i0 from '@angular/core';
|
|
4
|
+
import { inject, TemplateRef, Directive, input, booleanAttribute, output, contentChild, computed, signal, effect, isSignal, untracked, ChangeDetectionStrategy, Component } from '@angular/core';
|
|
5
|
+
import * as i2 from '@angular/material/button';
|
|
6
|
+
import { MatButtonModule } from '@angular/material/button';
|
|
7
|
+
import * as i3 from '@angular/material/checkbox';
|
|
8
|
+
import { MatCheckboxModule } from '@angular/material/checkbox';
|
|
9
|
+
import * as i4 from '@angular/material/icon';
|
|
10
|
+
import { MatIconModule } from '@angular/material/icon';
|
|
11
|
+
import * as i5 from '@angular/material/menu';
|
|
12
|
+
import { MatMenuModule } from '@angular/material/menu';
|
|
13
|
+
import * as i6 from '@angular/material/progress-spinner';
|
|
14
|
+
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
|
15
|
+
import { MatTooltipModule } from '@angular/material/tooltip';
|
|
16
|
+
import { SdButton } from '@sdcorejs/angular/components/button';
|
|
17
|
+
import { SdQuickAction } from '@sdcorejs/angular/components/quick-action';
|
|
18
|
+
|
|
19
|
+
class SdTreeItemDefDirective {
|
|
20
|
+
static ngTemplateContextGuard(_dir, ctx) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
templateRef = inject(TemplateRef);
|
|
24
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: SdTreeItemDefDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
25
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.16", type: SdTreeItemDefDirective, isStandalone: true, selector: "[sdTreeItemDef]", ngImport: i0 });
|
|
26
|
+
}
|
|
27
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: SdTreeItemDefDirective, decorators: [{
|
|
28
|
+
type: Directive,
|
|
29
|
+
args: [{
|
|
30
|
+
selector: '[sdTreeItemDef]',
|
|
31
|
+
standalone: true,
|
|
32
|
+
}]
|
|
33
|
+
}] });
|
|
34
|
+
|
|
35
|
+
const DEFAULT_STATIC_TREE = { loadType: 'static' };
|
|
36
|
+
const EMPTY_TREE_ITEMS = [];
|
|
37
|
+
class SdTree {
|
|
38
|
+
autoIdInput = input(undefined, { ...(ngDevMode ? { debugName: "autoIdInput" } : /* istanbul ignore next */ {}), alias: 'autoId' });
|
|
39
|
+
option = input(undefined, ...(ngDevMode ? [{ debugName: "option" }] : /* istanbul ignore next */ []));
|
|
40
|
+
/** Migration bridge. New usage should put the data source in `option.items`. */
|
|
41
|
+
items = input(undefined, ...(ngDevMode ? [{ debugName: "items" }] : /* istanbul ignore next */ []));
|
|
42
|
+
/** Migration bridge. New usage should put static/lazy config in `option.tree`. */
|
|
43
|
+
tree = input(DEFAULT_STATIC_TREE, ...(ngDevMode ? [{ debugName: "tree" }] : /* istanbul ignore next */ []));
|
|
44
|
+
selectedItemsInput = input(undefined, { ...(ngDevMode ? { debugName: "selectedItemsInput" } : /* istanbul ignore next */ {}), alias: 'selectedItems' });
|
|
45
|
+
commands = input([], ...(ngDevMode ? [{ debugName: "commands" }] : /* istanbul ignore next */ []));
|
|
46
|
+
selectable = input(true, { ...(ngDevMode ? { debugName: "selectable" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
47
|
+
selector = input(undefined, ...(ngDevMode ? [{ debugName: "selector" }] : /* istanbul ignore next */ []));
|
|
48
|
+
itemTemplate = input(undefined, ...(ngDevMode ? [{ debugName: "itemTemplate" }] : /* istanbul ignore next */ []));
|
|
49
|
+
selectedItemsChange = output();
|
|
50
|
+
selectChange = output();
|
|
51
|
+
expandChange = output();
|
|
52
|
+
collapseChange = output();
|
|
53
|
+
itemDef = contentChild((SdTreeItemDefDirective), ...(ngDevMode ? [{ debugName: "itemDef" }] : /* istanbul ignore next */ []));
|
|
54
|
+
resolvedItemsSource = computed(() => {
|
|
55
|
+
return this.option()?.items ?? this.items() ?? EMPTY_TREE_ITEMS;
|
|
56
|
+
}, ...(ngDevMode ? [{ debugName: "resolvedItemsSource" }] : /* istanbul ignore next */ []));
|
|
57
|
+
resolvedTree = computed(() => this.option()?.tree ?? this.tree() ?? DEFAULT_STATIC_TREE, ...(ngDevMode ? [{ debugName: "resolvedTree" }] : /* istanbul ignore next */ []));
|
|
58
|
+
resolvedSelector = computed(() => this.option()?.selector ?? this.selector(), ...(ngDevMode ? [{ debugName: "resolvedSelector" }] : /* istanbul ignore next */ []));
|
|
59
|
+
resolvedCommands = computed(() => this.option()?.commands ?? this.commands() ?? [], ...(ngDevMode ? [{ debugName: "resolvedCommands" }] : /* istanbul ignore next */ []));
|
|
60
|
+
resolvedSelectable = computed(() => this.option()?.selectable ?? this.selectable(), ...(ngDevMode ? [{ debugName: "resolvedSelectable" }] : /* istanbul ignore next */ []));
|
|
61
|
+
autoId = computed(() => {
|
|
62
|
+
const scope = this.option()?.autoId ?? this.autoIdInput();
|
|
63
|
+
return scope ? `components-tree-${scope}` : undefined;
|
|
64
|
+
}, ...(ngDevMode ? [{ debugName: "autoId" }] : /* istanbul ignore next */ []));
|
|
65
|
+
resolvedItemTemplate = computed(() => {
|
|
66
|
+
return this.itemDef()?.templateRef || this.option()?.itemTemplate || this.itemTemplate() || undefined;
|
|
67
|
+
}, ...(ngDevMode ? [{ debugName: "resolvedItemTemplate" }] : /* istanbul ignore next */ []));
|
|
68
|
+
indentSize = computed(() => this.resolvedTree().indentSize ?? 20, ...(ngDevMode ? [{ debugName: "indentSize" }] : /* istanbul ignore next */ []));
|
|
69
|
+
#rootItems = signal([], ...(ngDevMode ? [{ debugName: "#rootItems" }] : /* istanbul ignore next */ []));
|
|
70
|
+
#expandedState = signal({}, ...(ngDevMode ? [{ debugName: "#expandedState" }] : /* istanbul ignore next */ []));
|
|
71
|
+
#loadingState = signal({}, ...(ngDevMode ? [{ debugName: "#loadingState" }] : /* istanbul ignore next */ []));
|
|
72
|
+
#lazyChildren = signal({}, ...(ngDevMode ? [{ debugName: "#lazyChildren" }] : /* istanbul ignore next */ []));
|
|
73
|
+
#selectedIds = signal(new Set(), ...(ngDevMode ? [{ debugName: "#selectedIds" }] : /* istanbul ignore next */ []));
|
|
74
|
+
#filterText = signal('', ...(ngDevMode ? [{ debugName: "#filterText" }] : /* istanbul ignore next */ []));
|
|
75
|
+
#reloadTick = signal(0, ...(ngDevMode ? [{ debugName: "#reloadTick" }] : /* istanbul ignore next */ []));
|
|
76
|
+
#rootLoadId = 0;
|
|
77
|
+
#lastSource;
|
|
78
|
+
#lastSourceValue;
|
|
79
|
+
#lastReloadTick = -1;
|
|
80
|
+
normalizedFilterText = computed(() => normalizeText(this.#filterText()), ...(ngDevMode ? [{ debugName: "normalizedFilterText" }] : /* istanbul ignore next */ []));
|
|
81
|
+
selectionVisible = computed(() => this.resolvedSelectable() && this.resolvedSelector()?.visible === true, ...(ngDevMode ? [{ debugName: "selectionVisible" }] : /* istanbul ignore next */ []));
|
|
82
|
+
selectedIdSet = computed(() => {
|
|
83
|
+
const selectedItems = this.option()?.selectedItems ?? this.selectedItemsInput();
|
|
84
|
+
return selectedItems ? this.#idsFromSelectedItems(selectedItems) : this.#selectedIds();
|
|
85
|
+
}, ...(ngDevMode ? [{ debugName: "selectedIdSet" }] : /* istanbul ignore next */ []));
|
|
86
|
+
rootNodes = computed(() => this.#buildNodes(this.#rootItems(), 0, null), ...(ngDevMode ? [{ debugName: "rootNodes" }] : /* istanbul ignore next */ []));
|
|
87
|
+
visibleNodes = computed(() => {
|
|
88
|
+
const filterText = this.normalizedFilterText();
|
|
89
|
+
const result = [];
|
|
90
|
+
const walk = (nodes) => {
|
|
91
|
+
for (const node of nodes) {
|
|
92
|
+
const nodeOrDescendantMatches = this.#subtreeMatches(node, filterText);
|
|
93
|
+
if (!filterText || nodeOrDescendantMatches) {
|
|
94
|
+
result.push(node);
|
|
95
|
+
}
|
|
96
|
+
const shouldShowChildren = filterText ? nodeOrDescendantMatches : node.isExpanded;
|
|
97
|
+
if (shouldShowChildren) {
|
|
98
|
+
walk(node.children);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
walk(this.rootNodes());
|
|
103
|
+
return result;
|
|
104
|
+
}, ...(ngDevMode ? [{ debugName: "visibleNodes" }] : /* istanbul ignore next */ []));
|
|
105
|
+
selectedItems = computed(() => this.#selectedItemsFromIds(this.selectedIdSet()), ...(ngDevMode ? [{ debugName: "selectedItems" }] : /* istanbul ignore next */ []));
|
|
106
|
+
selectedCount = computed(() => this.selectedItems().length, ...(ngDevMode ? [{ debugName: "selectedCount" }] : /* istanbul ignore next */ []));
|
|
107
|
+
selectionMessage = computed(() => {
|
|
108
|
+
const items = this.selectedItems();
|
|
109
|
+
const message = this.resolvedSelector()?.message;
|
|
110
|
+
if (typeof message === 'function')
|
|
111
|
+
return message(items);
|
|
112
|
+
return message || `Đã chọn ${items.length} mục`;
|
|
113
|
+
}, ...(ngDevMode ? [{ debugName: "selectionMessage" }] : /* istanbul ignore next */ []));
|
|
114
|
+
visibleSelectionActions = computed(() => {
|
|
115
|
+
const items = this.selectedItems();
|
|
116
|
+
return (this.resolvedSelector()?.actions || []).filter(action => {
|
|
117
|
+
const hidden = typeof action.hidden === 'function' ? action.hidden(items) : action.hidden;
|
|
118
|
+
return !hidden;
|
|
119
|
+
});
|
|
120
|
+
}, ...(ngDevMode ? [{ debugName: "visibleSelectionActions" }] : /* istanbul ignore next */ []));
|
|
121
|
+
selectionActionViews = computed(() => {
|
|
122
|
+
return this.visibleSelectionActions().map((action, index) => ({
|
|
123
|
+
action,
|
|
124
|
+
autoId: this.#selectionActionAutoId(index),
|
|
125
|
+
}));
|
|
126
|
+
}, ...(ngDevMode ? [{ debugName: "selectionActionViews" }] : /* istanbul ignore next */ []));
|
|
127
|
+
clearSelectionAutoId = computed(() => {
|
|
128
|
+
const base = this.autoId();
|
|
129
|
+
return base ? `${base}-clear-selection` : null;
|
|
130
|
+
}, ...(ngDevMode ? [{ debugName: "clearSelectionAutoId" }] : /* istanbul ignore next */ []));
|
|
131
|
+
/**
|
|
132
|
+
* Template-facing row model. Expensive/variable values are resolved once per
|
|
133
|
+
* signal recomputation so the HTML does not call helper methods for every CD pass.
|
|
134
|
+
*/
|
|
135
|
+
visibleViewNodes = computed(() => {
|
|
136
|
+
const selectedIds = this.selectedIdSet();
|
|
137
|
+
const selectedItems = this.selectedItems();
|
|
138
|
+
const selector = this.resolvedSelector();
|
|
139
|
+
const commands = this.resolvedCommands();
|
|
140
|
+
return this.visibleNodes().map(node => this.#toViewNode(node, selectedIds, selectedItems, selector, commands));
|
|
141
|
+
}, ...(ngDevMode ? [{ debugName: "visibleViewNodes" }] : /* istanbul ignore next */ []));
|
|
142
|
+
trackByNode = (_index, node) => node.id;
|
|
143
|
+
constructor() {
|
|
144
|
+
effect(() => {
|
|
145
|
+
const source = this.resolvedItemsSource();
|
|
146
|
+
const reloadTick = this.#reloadTick();
|
|
147
|
+
// Data sources can be arrays, signals, sync loaders, or async loaders.
|
|
148
|
+
// The effect normalizes them into #rootItems; `reload()` only bumps the tick.
|
|
149
|
+
if (isSignal(source)) {
|
|
150
|
+
const items = source();
|
|
151
|
+
untracked(() => this.#applySignalSource(source, items, reloadTick));
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
untracked(() => {
|
|
155
|
+
if (source === this.#lastSource && reloadTick === this.#lastReloadTick)
|
|
156
|
+
return;
|
|
157
|
+
this.#lastSource = source;
|
|
158
|
+
this.#lastSourceValue = undefined;
|
|
159
|
+
this.#lastReloadTick = reloadTick;
|
|
160
|
+
this.#loadRootItems(source);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
reload() {
|
|
165
|
+
this.#reloadTick.update(value => value + 1);
|
|
166
|
+
}
|
|
167
|
+
filter(searchText) {
|
|
168
|
+
this.#filterText.set(searchText ?? '');
|
|
169
|
+
}
|
|
170
|
+
isSelected(node) {
|
|
171
|
+
return this.selectedIdSet().has(node.id);
|
|
172
|
+
}
|
|
173
|
+
nodeIcon(node) {
|
|
174
|
+
return this.#iconOf(node);
|
|
175
|
+
}
|
|
176
|
+
visibleCommands(node) {
|
|
177
|
+
return this.resolvedCommands().filter(command => !this.#resolveBoolean(command.hidden, node.data));
|
|
178
|
+
}
|
|
179
|
+
isSelectionDisabled(node) {
|
|
180
|
+
const disabled = this.resolvedSelector()?.disabled;
|
|
181
|
+
return disabled ? disabled(node.data, this.selectedItems()) : false;
|
|
182
|
+
}
|
|
183
|
+
commandTitle(command, item) {
|
|
184
|
+
return typeof command.title === 'function' ? command.title(item) : command.title;
|
|
185
|
+
}
|
|
186
|
+
commandIcon(command, item) {
|
|
187
|
+
const icon = typeof command.icon === 'function' ? command.icon(item) : command.icon;
|
|
188
|
+
return icon || 'more_horiz';
|
|
189
|
+
}
|
|
190
|
+
isCommandDisabled(command, item) {
|
|
191
|
+
return this.#resolveBoolean(command.disabled, item);
|
|
192
|
+
}
|
|
193
|
+
async toggle(node, event) {
|
|
194
|
+
event?.stopPropagation();
|
|
195
|
+
const currentNode = this.#findNode(node.id) ?? node;
|
|
196
|
+
if (!currentNode.hasChildren || currentNode.isLoading)
|
|
197
|
+
return;
|
|
198
|
+
if (currentNode.isExpanded) {
|
|
199
|
+
this.#expandedState.update(state => ({ ...state, [currentNode.id]: false }));
|
|
200
|
+
const toggleEvent = { item: currentNode.data, expanded: false, node: { ...currentNode, isExpanded: false } };
|
|
201
|
+
this.option()?.onCollapse?.(toggleEvent);
|
|
202
|
+
this.collapseChange.emit(toggleEvent);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
await this.#ensureLazyChildren(currentNode);
|
|
206
|
+
const nextNode = this.#findNode(currentNode.id) ?? currentNode;
|
|
207
|
+
if (!nextNode.hasChildren)
|
|
208
|
+
return;
|
|
209
|
+
this.#expandedState.update(state => ({ ...state, [currentNode.id]: true }));
|
|
210
|
+
const toggleEvent = { item: currentNode.data, expanded: true, node: { ...nextNode, isExpanded: true } };
|
|
211
|
+
this.option()?.onExpand?.(toggleEvent);
|
|
212
|
+
this.expandChange.emit(toggleEvent);
|
|
213
|
+
}
|
|
214
|
+
toggleSelection(node, event) {
|
|
215
|
+
event?.stopPropagation();
|
|
216
|
+
if (!this.selectionVisible() || this.isSelectionDisabled(node))
|
|
217
|
+
return;
|
|
218
|
+
const selectedIds = new Set(this.selectedIdSet());
|
|
219
|
+
const nextSelected = !selectedIds.has(node.id);
|
|
220
|
+
if (nextSelected) {
|
|
221
|
+
selectedIds.add(node.id);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
selectedIds.delete(node.id);
|
|
225
|
+
}
|
|
226
|
+
this.#selectedIds.set(selectedIds);
|
|
227
|
+
const selectedItems = this.#selectedItemsFromIds(selectedIds);
|
|
228
|
+
this.option()?.onSelectedItemsChange?.(selectedItems);
|
|
229
|
+
this.selectedItemsChange.emit(selectedItems);
|
|
230
|
+
const selectionEvent = { item: node.data, selected: nextSelected, selectedItems };
|
|
231
|
+
this.option()?.onSelect?.(selectionEvent);
|
|
232
|
+
this.selectChange.emit(selectionEvent);
|
|
233
|
+
}
|
|
234
|
+
clearSelection() {
|
|
235
|
+
this.#selectedIds.set(new Set());
|
|
236
|
+
this.option()?.onSelectedItemsChange?.([]);
|
|
237
|
+
this.selectedItemsChange.emit([]);
|
|
238
|
+
}
|
|
239
|
+
onSelectionAction(action) {
|
|
240
|
+
action.click(this.selectedItems());
|
|
241
|
+
}
|
|
242
|
+
createContext(node) {
|
|
243
|
+
return this.#createContext(node, this.isSelected(node));
|
|
244
|
+
}
|
|
245
|
+
nodeAutoId(node, part) {
|
|
246
|
+
const base = this.autoId();
|
|
247
|
+
return base ? `${base}-${part}-${sanitizeId(node.id)}` : undefined;
|
|
248
|
+
}
|
|
249
|
+
commandAutoId(node, command) {
|
|
250
|
+
const base = this.nodeAutoId(node, 'command');
|
|
251
|
+
return base ? `${base}-${sanitizeId(command.key)}` : undefined;
|
|
252
|
+
}
|
|
253
|
+
#applySignalSource(source, items, reloadTick) {
|
|
254
|
+
if (source === this.#lastSource && items === this.#lastSourceValue && reloadTick === this.#lastReloadTick)
|
|
255
|
+
return;
|
|
256
|
+
this.#lastSource = source;
|
|
257
|
+
this.#lastSourceValue = items;
|
|
258
|
+
this.#lastReloadTick = reloadTick;
|
|
259
|
+
this.#setRootItems(items);
|
|
260
|
+
}
|
|
261
|
+
#loadRootItems(source) {
|
|
262
|
+
const loadId = ++this.#rootLoadId;
|
|
263
|
+
try {
|
|
264
|
+
const result = this.#readItemsSource(source);
|
|
265
|
+
if (isPromiseLike(result)) {
|
|
266
|
+
result
|
|
267
|
+
.then(items => {
|
|
268
|
+
if (loadId === this.#rootLoadId) {
|
|
269
|
+
this.#setRootItems(items);
|
|
270
|
+
}
|
|
271
|
+
})
|
|
272
|
+
.catch(() => {
|
|
273
|
+
if (loadId === this.#rootLoadId) {
|
|
274
|
+
this.#setRootItems([]);
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
if (loadId === this.#rootLoadId) {
|
|
280
|
+
this.#setRootItems(result);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
catch {
|
|
284
|
+
if (loadId === this.#rootLoadId) {
|
|
285
|
+
this.#setRootItems([]);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
#readItemsSource(source) {
|
|
290
|
+
if (isSignal(source))
|
|
291
|
+
return source();
|
|
292
|
+
if (typeof source === 'function')
|
|
293
|
+
return source();
|
|
294
|
+
return source;
|
|
295
|
+
}
|
|
296
|
+
#setRootItems(items) {
|
|
297
|
+
this.#rootItems.set([...(items ?? [])]);
|
|
298
|
+
this.#lazyChildren.set({});
|
|
299
|
+
this.#loadingState.set({});
|
|
300
|
+
}
|
|
301
|
+
#toViewNode(node, selectedIds, selectedItems, selector, commands) {
|
|
302
|
+
const selected = selectedIds.has(node.id);
|
|
303
|
+
const selectionDisabled = selector?.disabled ? selector.disabled(node.data, selectedItems) : false;
|
|
304
|
+
const viewNode = {
|
|
305
|
+
...node,
|
|
306
|
+
icon: this.#iconOf(node),
|
|
307
|
+
selected,
|
|
308
|
+
selectionDisabled,
|
|
309
|
+
toggleDisabled: !node.hasChildren || node.isLoading,
|
|
310
|
+
toggleLabel: node.isExpanded ? 'Collapse tree item' : 'Expand tree item',
|
|
311
|
+
ariaExpanded: node.hasChildren ? node.isExpanded : null,
|
|
312
|
+
autoIds: this.#nodeAutoIds(node),
|
|
313
|
+
commands: this.#commandViews(node, commands),
|
|
314
|
+
context: undefined,
|
|
315
|
+
};
|
|
316
|
+
viewNode.context = this.#createContext(viewNode, selected);
|
|
317
|
+
return viewNode;
|
|
318
|
+
}
|
|
319
|
+
#commandViews(node, commands) {
|
|
320
|
+
return commands
|
|
321
|
+
.filter(command => !this.#resolveBoolean(command.hidden, node.data))
|
|
322
|
+
.map(command => ({
|
|
323
|
+
key: command.key,
|
|
324
|
+
command,
|
|
325
|
+
title: this.commandTitle(command, node.data),
|
|
326
|
+
icon: this.commandIcon(command, node.data),
|
|
327
|
+
color: command.color || 'secondary',
|
|
328
|
+
fontSet: command.fontSet || 'material-icons-outlined',
|
|
329
|
+
disabled: this.isCommandDisabled(command, node.data),
|
|
330
|
+
autoId: this.commandAutoId(node, command),
|
|
331
|
+
defaultColor: !command.color,
|
|
332
|
+
}));
|
|
333
|
+
}
|
|
334
|
+
#createContext(node, selected) {
|
|
335
|
+
return {
|
|
336
|
+
$implicit: node.data,
|
|
337
|
+
item: node.data,
|
|
338
|
+
treeItem: node.treeItem,
|
|
339
|
+
node,
|
|
340
|
+
level: node.level,
|
|
341
|
+
expanded: node.isExpanded,
|
|
342
|
+
selected,
|
|
343
|
+
loading: node.isLoading,
|
|
344
|
+
hasChildren: node.hasChildren,
|
|
345
|
+
isLeaf: !node.hasChildren,
|
|
346
|
+
toggle: () => void this.toggle(node),
|
|
347
|
+
select: () => this.toggleSelection(node),
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
#nodeAutoIds(node) {
|
|
351
|
+
return {
|
|
352
|
+
row: this.nodeAutoId(node, 'row'),
|
|
353
|
+
toggle: this.nodeAutoId(node, 'toggle'),
|
|
354
|
+
checkbox: this.nodeAutoId(node, 'checkbox'),
|
|
355
|
+
icon: this.nodeAutoId(node, 'icon'),
|
|
356
|
+
label: this.nodeAutoId(node, 'label'),
|
|
357
|
+
command: this.nodeAutoId(node, 'command'),
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
#selectionActionAutoId(index) {
|
|
361
|
+
const base = this.autoId();
|
|
362
|
+
return base ? `${base}-selection-action-${index}` : null;
|
|
363
|
+
}
|
|
364
|
+
#buildNodes(items, level, parent) {
|
|
365
|
+
const option = this.resolvedTree();
|
|
366
|
+
const maxDepth = option.maxDepth;
|
|
367
|
+
if (maxDepth !== undefined && level > maxDepth)
|
|
368
|
+
return [];
|
|
369
|
+
return items.map(item => {
|
|
370
|
+
const rawChildren = this.#childrenOf(item);
|
|
371
|
+
const hasChildren = rawChildren.length > 0 || this.#hasLazyChildren(item);
|
|
372
|
+
const isExpanded = this.#expandedState()[item.id] ?? item.expanded ?? this.#defaultExpanded(level);
|
|
373
|
+
const node = {
|
|
374
|
+
treeItem: item,
|
|
375
|
+
data: item.data,
|
|
376
|
+
id: item.id,
|
|
377
|
+
label: item.label,
|
|
378
|
+
level,
|
|
379
|
+
parent,
|
|
380
|
+
children: [],
|
|
381
|
+
hasChildren,
|
|
382
|
+
isExpanded,
|
|
383
|
+
isLoading: this.#loadingState()[item.id] ?? false,
|
|
384
|
+
};
|
|
385
|
+
node.children = this.#buildNodes(rawChildren, level + 1, node);
|
|
386
|
+
return node;
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
#childrenOf(item) {
|
|
390
|
+
const option = this.resolvedTree();
|
|
391
|
+
// Static items own their `children`; lazy items keep loaded children in component state.
|
|
392
|
+
if (option.loadType === 'lazy') {
|
|
393
|
+
return this.#lazyChildren()[item.id] ?? [];
|
|
394
|
+
}
|
|
395
|
+
return item.children ?? [];
|
|
396
|
+
}
|
|
397
|
+
#hasLazyChildren(item) {
|
|
398
|
+
const option = this.resolvedTree();
|
|
399
|
+
if (option.loadType !== 'lazy' || this.#lazyChildren()[item.id])
|
|
400
|
+
return false;
|
|
401
|
+
// Lazy mode uses `hasChildren` as the branch hint before children are loaded.
|
|
402
|
+
return item.hasChildren ?? true;
|
|
403
|
+
}
|
|
404
|
+
#defaultExpanded(level) {
|
|
405
|
+
const option = this.resolvedTree();
|
|
406
|
+
if (option.loadType !== 'static')
|
|
407
|
+
return false;
|
|
408
|
+
const value = option.defaultExpanded ?? false;
|
|
409
|
+
if (value === true)
|
|
410
|
+
return true;
|
|
411
|
+
if (value === false)
|
|
412
|
+
return false;
|
|
413
|
+
return level < value;
|
|
414
|
+
}
|
|
415
|
+
#iconOf(node) {
|
|
416
|
+
// One optional `treeItem.icon` handles both branch and leaf overrides.
|
|
417
|
+
// Without it, branches get folder icons while leaves intentionally render no icon.
|
|
418
|
+
if (node.treeItem.icon)
|
|
419
|
+
return node.treeItem.icon;
|
|
420
|
+
if (!node.hasChildren)
|
|
421
|
+
return undefined;
|
|
422
|
+
return node.isExpanded ? 'folder_open' : 'folder';
|
|
423
|
+
}
|
|
424
|
+
async #ensureLazyChildren(node) {
|
|
425
|
+
const option = this.resolvedTree();
|
|
426
|
+
if (option.loadType !== 'lazy' || node.children.length > 0 || this.#lazyChildren()[node.id])
|
|
427
|
+
return;
|
|
428
|
+
this.#loadingState.update(state => ({ ...state, [node.id]: true }));
|
|
429
|
+
try {
|
|
430
|
+
const lazyItem = node.treeItem;
|
|
431
|
+
const children = await Promise.resolve(option.onExpandChildren(lazyItem));
|
|
432
|
+
this.#lazyChildren.update(state => ({ ...state, [node.id]: children }));
|
|
433
|
+
// Do not write `children` onto lazy items; that field belongs to static items only.
|
|
434
|
+
lazyItem.hasChildren = children.length > 0;
|
|
435
|
+
}
|
|
436
|
+
finally {
|
|
437
|
+
this.#loadingState.update(state => ({ ...state, [node.id]: false }));
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
#findNode(id) {
|
|
441
|
+
return this.#flattenAll(this.rootNodes()).find(node => node.id === id);
|
|
442
|
+
}
|
|
443
|
+
#flattenAll(nodes) {
|
|
444
|
+
const result = [];
|
|
445
|
+
const walk = (current) => {
|
|
446
|
+
for (const node of current) {
|
|
447
|
+
result.push(node);
|
|
448
|
+
walk(node.children);
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
walk(nodes);
|
|
452
|
+
return result;
|
|
453
|
+
}
|
|
454
|
+
#selectedItemsFromIds(selectedIds) {
|
|
455
|
+
return this.#flattenAll(this.rootNodes())
|
|
456
|
+
.filter(node => selectedIds.has(node.id))
|
|
457
|
+
.map(node => node.data);
|
|
458
|
+
}
|
|
459
|
+
#idsFromSelectedItems(selectedItems) {
|
|
460
|
+
const selectedRefs = new Set(selectedItems);
|
|
461
|
+
const selectedDataIds = new Set(selectedItems.map(item => this.#dataId(item)).filter((id) => !!id));
|
|
462
|
+
const result = new Set();
|
|
463
|
+
for (const node of this.#flattenAll(this.rootNodes())) {
|
|
464
|
+
const dataId = this.#dataId(node.data);
|
|
465
|
+
if (selectedRefs.has(node.data) || (dataId && selectedDataIds.has(dataId))) {
|
|
466
|
+
result.add(node.id);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
return result;
|
|
470
|
+
}
|
|
471
|
+
#dataId(item) {
|
|
472
|
+
const record = item;
|
|
473
|
+
const value = record?.['id'] ?? record?.['code'] ?? record?.['value'];
|
|
474
|
+
return value != null && value !== '' ? String(value) : undefined;
|
|
475
|
+
}
|
|
476
|
+
#nodeMatches(node, filterText) {
|
|
477
|
+
return normalizeText(node.label).includes(filterText);
|
|
478
|
+
}
|
|
479
|
+
#subtreeMatches(node, filterText) {
|
|
480
|
+
if (this.#nodeMatches(node, filterText))
|
|
481
|
+
return true;
|
|
482
|
+
return node.children.some(child => this.#subtreeMatches(child, filterText));
|
|
483
|
+
}
|
|
484
|
+
#resolveBoolean(resolver, item) {
|
|
485
|
+
return typeof resolver === 'function' ? resolver(item) : !!resolver;
|
|
486
|
+
}
|
|
487
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: SdTree, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
488
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.16", type: SdTree, isStandalone: true, selector: "sd-tree", inputs: { autoIdInput: { classPropertyName: "autoIdInput", publicName: "autoId", isSignal: true, isRequired: false, transformFunction: null }, option: { classPropertyName: "option", publicName: "option", isSignal: true, isRequired: false, transformFunction: null }, items: { classPropertyName: "items", publicName: "items", isSignal: true, isRequired: false, transformFunction: null }, tree: { classPropertyName: "tree", publicName: "tree", isSignal: true, isRequired: false, transformFunction: null }, selectedItemsInput: { classPropertyName: "selectedItemsInput", publicName: "selectedItems", isSignal: true, isRequired: false, transformFunction: null }, commands: { classPropertyName: "commands", publicName: "commands", isSignal: true, isRequired: false, transformFunction: null }, selectable: { classPropertyName: "selectable", publicName: "selectable", isSignal: true, isRequired: false, transformFunction: null }, selector: { classPropertyName: "selector", publicName: "selector", isSignal: true, isRequired: false, transformFunction: null }, itemTemplate: { classPropertyName: "itemTemplate", publicName: "itemTemplate", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { selectedItemsChange: "selectedItemsChange", selectChange: "selectChange", expandChange: "expandChange", collapseChange: "collapseChange" }, host: { properties: { "attr.data-autoid": "autoId()" } }, queries: [{ propertyName: "itemDef", first: true, predicate: (SdTreeItemDefDirective), descendants: true, isSignal: true }], ngImport: i0, template: "@let _templateRef = resolvedItemTemplate();\n@let _selectionVisible = selectionVisible();\n@let _selectedCount = selectedCount();\n@let _selectionMessage = selectionMessage();\n@let _selectionActions = selectionActionViews();\n\n<div class=\"sd-tree\" role=\"tree\" [style.--sd-tree-indent-size]=\"indentSize() + 'px'\">\n @for (node of visibleViewNodes(); track node.id) {\n <div\n class=\"sd-tree__row\"\n role=\"treeitem\"\n [class.sd-tree__row--selected]=\"node.selected\"\n [style.--sd-tree-level]=\"node.level\"\n [attr.aria-expanded]=\"node.ariaExpanded\"\n [attr.aria-selected]=\"_selectionVisible ? node.selected : null\"\n [attr.data-autoid]=\"node.autoIds.row\">\n <div class=\"sd-tree__main\">\n <button\n type=\"button\"\n class=\"sd-tree__toggle\"\n [class.sd-tree__toggle--placeholder]=\"!node.hasChildren\"\n [disabled]=\"node.toggleDisabled\"\n [attr.aria-label]=\"node.toggleLabel\"\n [attr.data-autoid]=\"node.autoIds.toggle\"\n (click)=\"toggle(node, $event)\">\n @if (node.isLoading) {\n <mat-progress-spinner diameter=\"16\" mode=\"indeterminate\" />\n } @else if (node.hasChildren) {\n <mat-icon>{{ node.isExpanded ? 'expand_more' : 'chevron_right' }}</mat-icon>\n }\n </button>\n\n @if (_selectionVisible) {\n <mat-checkbox\n class=\"sd-tree__checkbox\"\n [checked]=\"node.selected\"\n [disabled]=\"node.selectionDisabled\"\n [attr.data-autoid]=\"node.autoIds.checkbox\"\n (click)=\"$event.stopPropagation()\"\n (change)=\"toggleSelection(node)\" />\n }\n\n @if (node.icon) {\n <mat-icon class=\"sd-tree__item-icon\" color=\"primary\" [attr.data-autoid]=\"node.autoIds.icon\">{{ node.icon }}</mat-icon>\n }\n\n <div class=\"sd-tree__content\" [class.sd-tree__content--custom]=\"_templateRef\" [attr.data-autoid]=\"node.autoIds.label\">\n @if (_templateRef) {\n <ng-container *ngTemplateOutlet=\"_templateRef; context: node.context\" />\n } @else {\n <span class=\"sd-tree__label\">{{ node.label }}</span>\n }\n </div>\n </div>\n\n @if (node.commands.length) {\n <button\n type=\"button\"\n class=\"sd-tree__command-trigger\"\n mat-icon-button\n [matMenuTriggerFor]=\"commandMenu\"\n [attr.data-autoid]=\"node.autoIds.command\"\n (click)=\"$event.stopPropagation()\">\n <mat-icon class=\"c-icon\" fontSet=\"material-icons-outlined\">more_vert</mat-icon>\n </button>\n <mat-menu #commandMenu=\"matMenu\" class=\"sd-tree__command-menu\">\n @for (command of node.commands; track command.key) {\n <button\n type=\"button\"\n class=\"sd-tree__command-menu-item\"\n mat-menu-item\n [disabled]=\"command.disabled\"\n [attr.data-autoid]=\"command.autoId\"\n (click)=\"command.command.click(node.data)\">\n <span class=\"sd-tree__command-menu-content\">\n <mat-icon\n class=\"c-icon sd-tree__command-menu-icon\"\n [class.sd-tree__command-menu-icon--default]=\"command.defaultColor\"\n [color]=\"command.color\"\n [fontSet]=\"command.fontSet\">\n {{ command.icon }}\n </mat-icon>\n <span class=\"sd-tree__command-title\">{{ command.title }}</span>\n </span>\n </button>\n }\n </mat-menu>\n }\n </div>\n }\n</div>\n\n<sd-quick-action [opened]=\"_selectedCount > 0\">\n <div class=\"d-flex align-items-center\" sdMessage>\n <div class=\"c-bg-length\">\n <span class=\"c-length sd-tree__qa-count\">{{ _selectedCount }}</span>\n </div>\n <div class=\"c-message\">\n {{ _selectionMessage }}\n </div>\n </div>\n\n <div class=\"d-flex align-items-center mr-8 sd-tree__qa-actions\" sdAction>\n @for (actionView of _selectionActions; track $index) {\n <sd-button\n [autoId]=\"actionView.autoId\"\n class=\"ml-4\"\n [tooltip]=\"actionView.action.tooltip\"\n [prefixIcon]=\"actionView.action.icon\"\n [color]=\"actionView.action.color || 'primary'\"\n [type]=\"actionView.action.type || 'light'\"\n [fontSet]=\"actionView.action.fontSet\"\n [title]=\"actionView.action.title\"\n (click)=\"onSelectionAction(actionView.action)\" />\n }\n <sd-button\n [autoId]=\"clearSelectionAutoId()\"\n class=\"ml-4\"\n prefixIcon=\"close\"\n color=\"secondary\"\n type=\"outline\"\n width=\"35px\"\n (click)=\"clearSelection()\" />\n </div>\n</sd-quick-action>\n", styles: [".text-primary{color:var(--sd-primary)!important}.bg-primary{background:var(--sd-primary)!important}.border-primary{border-color:var(--sd-primary)!important}.text-primary-light{color:var(--sd-primary-light)!important}.bg-primary-light{background:var(--sd-primary-light)!important}.border-primary-light{border-color:var(--sd-primary-light)!important}.text-primary-dark{color:var(--sd-primary-dark)!important}.bg-primary-dark{background:var(--sd-primary-dark)!important}.border-primary-dark{border-color:var(--sd-primary-dark)!important}.text-info{color:var(--sd-info)!important}.bg-info{background:var(--sd-info)!important}.border-info{border-color:var(--sd-info)!important}.text-info-light{color:var(--sd-info-light)!important}.bg-info-light{background:var(--sd-info-light)!important}.border-info-light{border-color:var(--sd-info-light)!important}.text-info-dark{color:var(--sd-info-dark)!important}.bg-info-dark{background:var(--sd-info-dark)!important}.border-info-dark{border-color:var(--sd-info-dark)!important}.text-success{color:var(--sd-success)!important}.bg-success{background:var(--sd-success)!important}.border-success{border-color:var(--sd-success)!important}.text-success-light{color:var(--sd-success-light)!important}.bg-success-light{background:var(--sd-success-light)!important}.border-success-light{border-color:var(--sd-success-light)!important}.text-success-dark{color:var(--sd-success-dark)!important}.bg-success-dark{background:var(--sd-success-dark)!important}.border-success-dark{border-color:var(--sd-success-dark)!important}.text-warning{color:var(--sd-warning)!important}.bg-warning{background:var(--sd-warning)!important}.border-warning{border-color:var(--sd-warning)!important}.text-warning-light{color:var(--sd-warning-light)!important}.bg-warning-light{background:var(--sd-warning-light)!important}.border-warning-light{border-color:var(--sd-warning-light)!important}.text-warning-dark{color:var(--sd-warning-dark)!important}.bg-warning-dark{background:var(--sd-warning-dark)!important}.border-warning-dark{border-color:var(--sd-warning-dark)!important}.text-error{color:var(--sd-error)!important}.bg-error{background:var(--sd-error)!important}.border-error{border-color:var(--sd-error)!important}.text-error-light{color:var(--sd-error-light)!important}.bg-error-light{background:var(--sd-error-light)!important}.border-error-light{border-color:var(--sd-error-light)!important}.text-error-dark{color:var(--sd-error-dark)!important}.bg-error-dark{background:var(--sd-error-dark)!important}.border-error-dark{border-color:var(--sd-error-dark)!important}.text-secondary{color:var(--sd-secondary)!important}.bg-secondary{background:var(--sd-secondary)!important}.border-secondary{border-color:var(--sd-secondary)!important}.text-secondary-light{color:var(--sd-secondary-light)!important}.bg-secondary-light{background:var(--sd-secondary-light)!important}.border-secondary-light{border-color:var(--sd-secondary-light)!important}.text-secondary-dark{color:var(--sd-secondary-dark)!important}.bg-secondary-dark{background:var(--sd-secondary-dark)!important}.border-secondary-dark{border-color:var(--sd-secondary-dark)!important}.text-light{color:var(--sd-light)!important}.bg-light{background:var(--sd-light)!important}.border-light{border-color:var(--sd-light)!important}.text-dark{color:var(--sd-dark)!important}.bg-dark{background:var(--sd-dark)!important}.border-dark{border-color:var(--sd-dark)!important}.text-black500{color:var(--sd-black500)!important}.bg-black500{background:var(--sd-black500)!important}.border-black500{border-color:var(--sd-black500)!important}.text-black400{color:var(--sd-black400)!important}.bg-black400{background:var(--sd-black400)!important}.border-black400{border-color:var(--sd-black400)!important}.text-black300{color:var(--sd-black300)!important}.bg-black300{background:var(--sd-black300)!important}.border-black300{border-color:var(--sd-black300)!important}.text-black200{color:var(--sd-black200)!important}.bg-black200{background:var(--sd-black200)!important}.border-black200{border-color:var(--sd-black200)!important}.text-black100{color:var(--sd-black100)!important}.bg-black100{background:var(--sd-black100)!important}.border-black100{border-color:var(--sd-black100)!important}.text-white{color:#fff!important}.bg-white{background:#fff!important}.border-white{border-color:#fff!important}.text-black{color:#000!important}.bg-black{background:#000!important}.border-black{border-color:#000!important}:host{--sd-tree-row-height: 44px;--sd-tree-control-size: 28px;--sd-tree-indent-size: 20px;--sd-tree-selected-bg: color-mix(in srgb, var(--sd-primary, #2a66f4) 12%, #ffffff);--sd-tree-hover-bg: rgba(15, 23, 42, .04);--sd-tree-text: #102047;--sd-tree-muted: #5f6f89;display:block}.sd-tree{display:flex;flex-direction:column;width:100%}.sd-tree__row{position:relative;display:flex;align-items:center;min-height:var(--sd-tree-row-height);box-sizing:border-box;padding:6px 4px 6px calc(4px + var(--sd-tree-level) * var(--sd-tree-indent-size));color:var(--sd-tree-text);border-radius:0}.sd-tree__row:hover{background:var(--sd-tree-hover-bg)}.sd-tree__row--selected{background:var(--sd-tree-selected-bg)}.sd-tree__main{display:flex;align-items:center;min-width:0;flex:1 1 auto}.sd-tree__toggle{display:inline-flex;align-items:center;justify-content:center;flex:0 0 var(--sd-tree-control-size);width:var(--sd-tree-control-size);height:var(--sd-tree-control-size);padding:0;color:var(--sd-tree-muted);background:transparent;border:0;border-radius:4px;cursor:pointer}.sd-tree__toggle:disabled{cursor:default}.sd-tree__toggle--placeholder{visibility:hidden}.sd-tree__toggle mat-icon{width:20px;height:20px;font-size:20px;line-height:20px}.sd-tree__checkbox{flex:0 0 auto;height:var(--sd-tree-control-size);margin:0 4px 0 0;transform:scale(.85);transform-origin:center;--mdc-checkbox-selected-checkmark-color: #ffffff;--mdc-checkbox-selected-focus-icon-color: var(--sd-primary, #2a66f4);--mdc-checkbox-selected-hover-icon-color: var(--sd-primary, #2a66f4);--mdc-checkbox-selected-icon-color: var(--sd-primary, #2a66f4);--mdc-checkbox-selected-pressed-icon-color: var(--sd-primary, #2a66f4)}.sd-tree__item-icon{flex:0 0 auto;width:20px;height:20px;margin:0 8px 0 0;font-size:20px;line-height:20px}.sd-tree__content{display:-webkit-box;min-width:0;min-height:var(--sd-tree-control-size);padding:4px 0;overflow:hidden;overflow-wrap:anywhere;-webkit-box-orient:vertical;-webkit-line-clamp:2;line-height:20px}.sd-tree__content--custom{display:block;max-height:none;-webkit-line-clamp:unset}.sd-tree__label{font-size:14px;font-weight:500}.sd-tree__command-trigger{display:inline-flex;align-items:center;justify-content:center;flex:0 0 auto;align-self:center;width:24px;height:24px;padding:0;margin-left:8px;line-height:24px;opacity:0;transition:opacity .12s ease}.sd-tree__row:hover .sd-tree__command-trigger,.sd-tree__command-trigger[aria-expanded=true]{opacity:1}.sd-tree__command-trigger mat-icon.c-icon,.sd-tree__command-menu-icon{width:16px;height:16px;font-size:16px;line-height:16px}.sd-tree__command-trigger mat-icon.c-icon,.sd-tree__command-menu-icon--default{color:var(--sd-black400)!important}::ng-deep .mat-mdc-menu-panel.sd-tree__command-menu .mat-mdc-menu-item.sd-tree__command-menu-item,::ng-deep .mat-menu-panel.sd-tree__command-menu .mat-menu-item.sd-tree__command-menu-item{min-height:40px;padding:0 12px}::ng-deep .mat-mdc-menu-panel.sd-tree__command-menu .mat-mdc-menu-item.sd-tree__command-menu-item .mat-mdc-menu-item-text,::ng-deep .mat-mdc-menu-panel.sd-tree__command-menu .mat-mdc-menu-item.sd-tree__command-menu-item .mdc-list-item__primary-text,::ng-deep .mat-menu-panel.sd-tree__command-menu .mat-menu-item.sd-tree__command-menu-item{width:100%;min-width:0}.sd-tree__command-menu-content{display:flex;align-items:center;gap:6px;width:100%;min-width:0;line-height:20px}.sd-tree__command-menu-icon{display:flex;align-items:center;justify-content:center;flex:0 0 16px;margin:0!important;padding:0;text-align:center;overflow:hidden}.sd-tree__command-title{display:block;min-width:0;line-height:20px}.c-bg-length{display:flex;flex-direction:column;align-items:flex-start;position:static;width:auto;min-width:48px;height:48px;padding:12px 8px;background:var(--sd-primary);border-radius:4px 0 0 4px}.c-bg-length .c-length{position:static;width:auto;min-width:32px;height:24px;color:#fff;font-family:Roboto,sans-serif;font-size:16px;font-style:normal;font-weight:500;line-height:24px;text-align:center}.c-message{position:static;min-width:200px;height:20px;margin:0 0 0 8px;color:#000;font-family:Roboto,sans-serif;font-size:14px;font-style:normal;font-weight:400;line-height:20px}.sd-tree__qa-actions{align-items:center;gap:4px;margin-right:8px}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "ngmodule", type: MatButtonModule }, { kind: "component", type: i2.MatIconButton, selector: "button[mat-icon-button], a[mat-icon-button], button[matIconButton], a[matIconButton]", exportAs: ["matButton", "matAnchor"] }, { kind: "ngmodule", type: MatCheckboxModule }, { kind: "component", type: i3.MatCheckbox, selector: "mat-checkbox", inputs: ["aria-label", "aria-labelledby", "aria-describedby", "aria-expanded", "aria-controls", "aria-owns", "id", "required", "labelPosition", "name", "value", "disableRipple", "tabIndex", "color", "disabledInteractive", "checked", "disabled", "indeterminate"], outputs: ["change", "indeterminateChange"], exportAs: ["matCheckbox"] }, { kind: "ngmodule", type: MatIconModule }, { kind: "component", type: i4.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "ngmodule", type: MatMenuModule }, { kind: "component", type: i5.MatMenu, selector: "mat-menu", inputs: ["backdropClass", "aria-label", "aria-labelledby", "aria-describedby", "xPosition", "yPosition", "overlapTrigger", "hasBackdrop", "class", "classList"], outputs: ["closed", "close"], exportAs: ["matMenu"] }, { kind: "component", type: i5.MatMenuItem, selector: "[mat-menu-item]", inputs: ["role", "disabled", "disableRipple"], exportAs: ["matMenuItem"] }, { kind: "directive", type: i5.MatMenuTrigger, selector: "[mat-menu-trigger-for], [matMenuTriggerFor]", inputs: ["mat-menu-trigger-for", "matMenuTriggerFor", "matMenuTriggerData", "matMenuTriggerRestoreFocus"], outputs: ["menuOpened", "onMenuOpen", "menuClosed", "onMenuClose"], exportAs: ["matMenuTrigger"] }, { kind: "ngmodule", type: MatProgressSpinnerModule }, { kind: "component", type: i6.MatProgressSpinner, selector: "mat-progress-spinner, mat-spinner", inputs: ["color", "mode", "value", "diameter", "strokeWidth"], exportAs: ["matProgressSpinner"] }, { kind: "ngmodule", type: MatTooltipModule }, { kind: "component", type: SdButton, selector: "sd-button", inputs: ["autoId", "type", "color", "size", "fontSet", "title", "width", "tooltip", "prefixIcon", "suffixIcon", "disabled", "loading", "block", "htmlType"], outputs: ["click"] }, { kind: "component", type: SdQuickAction, selector: "sd-quick-action", inputs: ["opened"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
489
|
+
}
|
|
490
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: SdTree, decorators: [{
|
|
491
|
+
type: Component,
|
|
492
|
+
args: [{ selector: 'sd-tree', standalone: true, imports: [
|
|
493
|
+
CommonModule,
|
|
494
|
+
MatButtonModule,
|
|
495
|
+
MatCheckboxModule,
|
|
496
|
+
MatIconModule,
|
|
497
|
+
MatMenuModule,
|
|
498
|
+
MatProgressSpinnerModule,
|
|
499
|
+
MatTooltipModule,
|
|
500
|
+
SdButton,
|
|
501
|
+
SdQuickAction,
|
|
502
|
+
], changeDetection: ChangeDetectionStrategy.OnPush, host: {
|
|
503
|
+
'[attr.data-autoid]': 'autoId()',
|
|
504
|
+
}, template: "@let _templateRef = resolvedItemTemplate();\n@let _selectionVisible = selectionVisible();\n@let _selectedCount = selectedCount();\n@let _selectionMessage = selectionMessage();\n@let _selectionActions = selectionActionViews();\n\n<div class=\"sd-tree\" role=\"tree\" [style.--sd-tree-indent-size]=\"indentSize() + 'px'\">\n @for (node of visibleViewNodes(); track node.id) {\n <div\n class=\"sd-tree__row\"\n role=\"treeitem\"\n [class.sd-tree__row--selected]=\"node.selected\"\n [style.--sd-tree-level]=\"node.level\"\n [attr.aria-expanded]=\"node.ariaExpanded\"\n [attr.aria-selected]=\"_selectionVisible ? node.selected : null\"\n [attr.data-autoid]=\"node.autoIds.row\">\n <div class=\"sd-tree__main\">\n <button\n type=\"button\"\n class=\"sd-tree__toggle\"\n [class.sd-tree__toggle--placeholder]=\"!node.hasChildren\"\n [disabled]=\"node.toggleDisabled\"\n [attr.aria-label]=\"node.toggleLabel\"\n [attr.data-autoid]=\"node.autoIds.toggle\"\n (click)=\"toggle(node, $event)\">\n @if (node.isLoading) {\n <mat-progress-spinner diameter=\"16\" mode=\"indeterminate\" />\n } @else if (node.hasChildren) {\n <mat-icon>{{ node.isExpanded ? 'expand_more' : 'chevron_right' }}</mat-icon>\n }\n </button>\n\n @if (_selectionVisible) {\n <mat-checkbox\n class=\"sd-tree__checkbox\"\n [checked]=\"node.selected\"\n [disabled]=\"node.selectionDisabled\"\n [attr.data-autoid]=\"node.autoIds.checkbox\"\n (click)=\"$event.stopPropagation()\"\n (change)=\"toggleSelection(node)\" />\n }\n\n @if (node.icon) {\n <mat-icon class=\"sd-tree__item-icon\" color=\"primary\" [attr.data-autoid]=\"node.autoIds.icon\">{{ node.icon }}</mat-icon>\n }\n\n <div class=\"sd-tree__content\" [class.sd-tree__content--custom]=\"_templateRef\" [attr.data-autoid]=\"node.autoIds.label\">\n @if (_templateRef) {\n <ng-container *ngTemplateOutlet=\"_templateRef; context: node.context\" />\n } @else {\n <span class=\"sd-tree__label\">{{ node.label }}</span>\n }\n </div>\n </div>\n\n @if (node.commands.length) {\n <button\n type=\"button\"\n class=\"sd-tree__command-trigger\"\n mat-icon-button\n [matMenuTriggerFor]=\"commandMenu\"\n [attr.data-autoid]=\"node.autoIds.command\"\n (click)=\"$event.stopPropagation()\">\n <mat-icon class=\"c-icon\" fontSet=\"material-icons-outlined\">more_vert</mat-icon>\n </button>\n <mat-menu #commandMenu=\"matMenu\" class=\"sd-tree__command-menu\">\n @for (command of node.commands; track command.key) {\n <button\n type=\"button\"\n class=\"sd-tree__command-menu-item\"\n mat-menu-item\n [disabled]=\"command.disabled\"\n [attr.data-autoid]=\"command.autoId\"\n (click)=\"command.command.click(node.data)\">\n <span class=\"sd-tree__command-menu-content\">\n <mat-icon\n class=\"c-icon sd-tree__command-menu-icon\"\n [class.sd-tree__command-menu-icon--default]=\"command.defaultColor\"\n [color]=\"command.color\"\n [fontSet]=\"command.fontSet\">\n {{ command.icon }}\n </mat-icon>\n <span class=\"sd-tree__command-title\">{{ command.title }}</span>\n </span>\n </button>\n }\n </mat-menu>\n }\n </div>\n }\n</div>\n\n<sd-quick-action [opened]=\"_selectedCount > 0\">\n <div class=\"d-flex align-items-center\" sdMessage>\n <div class=\"c-bg-length\">\n <span class=\"c-length sd-tree__qa-count\">{{ _selectedCount }}</span>\n </div>\n <div class=\"c-message\">\n {{ _selectionMessage }}\n </div>\n </div>\n\n <div class=\"d-flex align-items-center mr-8 sd-tree__qa-actions\" sdAction>\n @for (actionView of _selectionActions; track $index) {\n <sd-button\n [autoId]=\"actionView.autoId\"\n class=\"ml-4\"\n [tooltip]=\"actionView.action.tooltip\"\n [prefixIcon]=\"actionView.action.icon\"\n [color]=\"actionView.action.color || 'primary'\"\n [type]=\"actionView.action.type || 'light'\"\n [fontSet]=\"actionView.action.fontSet\"\n [title]=\"actionView.action.title\"\n (click)=\"onSelectionAction(actionView.action)\" />\n }\n <sd-button\n [autoId]=\"clearSelectionAutoId()\"\n class=\"ml-4\"\n prefixIcon=\"close\"\n color=\"secondary\"\n type=\"outline\"\n width=\"35px\"\n (click)=\"clearSelection()\" />\n </div>\n</sd-quick-action>\n", styles: [".text-primary{color:var(--sd-primary)!important}.bg-primary{background:var(--sd-primary)!important}.border-primary{border-color:var(--sd-primary)!important}.text-primary-light{color:var(--sd-primary-light)!important}.bg-primary-light{background:var(--sd-primary-light)!important}.border-primary-light{border-color:var(--sd-primary-light)!important}.text-primary-dark{color:var(--sd-primary-dark)!important}.bg-primary-dark{background:var(--sd-primary-dark)!important}.border-primary-dark{border-color:var(--sd-primary-dark)!important}.text-info{color:var(--sd-info)!important}.bg-info{background:var(--sd-info)!important}.border-info{border-color:var(--sd-info)!important}.text-info-light{color:var(--sd-info-light)!important}.bg-info-light{background:var(--sd-info-light)!important}.border-info-light{border-color:var(--sd-info-light)!important}.text-info-dark{color:var(--sd-info-dark)!important}.bg-info-dark{background:var(--sd-info-dark)!important}.border-info-dark{border-color:var(--sd-info-dark)!important}.text-success{color:var(--sd-success)!important}.bg-success{background:var(--sd-success)!important}.border-success{border-color:var(--sd-success)!important}.text-success-light{color:var(--sd-success-light)!important}.bg-success-light{background:var(--sd-success-light)!important}.border-success-light{border-color:var(--sd-success-light)!important}.text-success-dark{color:var(--sd-success-dark)!important}.bg-success-dark{background:var(--sd-success-dark)!important}.border-success-dark{border-color:var(--sd-success-dark)!important}.text-warning{color:var(--sd-warning)!important}.bg-warning{background:var(--sd-warning)!important}.border-warning{border-color:var(--sd-warning)!important}.text-warning-light{color:var(--sd-warning-light)!important}.bg-warning-light{background:var(--sd-warning-light)!important}.border-warning-light{border-color:var(--sd-warning-light)!important}.text-warning-dark{color:var(--sd-warning-dark)!important}.bg-warning-dark{background:var(--sd-warning-dark)!important}.border-warning-dark{border-color:var(--sd-warning-dark)!important}.text-error{color:var(--sd-error)!important}.bg-error{background:var(--sd-error)!important}.border-error{border-color:var(--sd-error)!important}.text-error-light{color:var(--sd-error-light)!important}.bg-error-light{background:var(--sd-error-light)!important}.border-error-light{border-color:var(--sd-error-light)!important}.text-error-dark{color:var(--sd-error-dark)!important}.bg-error-dark{background:var(--sd-error-dark)!important}.border-error-dark{border-color:var(--sd-error-dark)!important}.text-secondary{color:var(--sd-secondary)!important}.bg-secondary{background:var(--sd-secondary)!important}.border-secondary{border-color:var(--sd-secondary)!important}.text-secondary-light{color:var(--sd-secondary-light)!important}.bg-secondary-light{background:var(--sd-secondary-light)!important}.border-secondary-light{border-color:var(--sd-secondary-light)!important}.text-secondary-dark{color:var(--sd-secondary-dark)!important}.bg-secondary-dark{background:var(--sd-secondary-dark)!important}.border-secondary-dark{border-color:var(--sd-secondary-dark)!important}.text-light{color:var(--sd-light)!important}.bg-light{background:var(--sd-light)!important}.border-light{border-color:var(--sd-light)!important}.text-dark{color:var(--sd-dark)!important}.bg-dark{background:var(--sd-dark)!important}.border-dark{border-color:var(--sd-dark)!important}.text-black500{color:var(--sd-black500)!important}.bg-black500{background:var(--sd-black500)!important}.border-black500{border-color:var(--sd-black500)!important}.text-black400{color:var(--sd-black400)!important}.bg-black400{background:var(--sd-black400)!important}.border-black400{border-color:var(--sd-black400)!important}.text-black300{color:var(--sd-black300)!important}.bg-black300{background:var(--sd-black300)!important}.border-black300{border-color:var(--sd-black300)!important}.text-black200{color:var(--sd-black200)!important}.bg-black200{background:var(--sd-black200)!important}.border-black200{border-color:var(--sd-black200)!important}.text-black100{color:var(--sd-black100)!important}.bg-black100{background:var(--sd-black100)!important}.border-black100{border-color:var(--sd-black100)!important}.text-white{color:#fff!important}.bg-white{background:#fff!important}.border-white{border-color:#fff!important}.text-black{color:#000!important}.bg-black{background:#000!important}.border-black{border-color:#000!important}:host{--sd-tree-row-height: 44px;--sd-tree-control-size: 28px;--sd-tree-indent-size: 20px;--sd-tree-selected-bg: color-mix(in srgb, var(--sd-primary, #2a66f4) 12%, #ffffff);--sd-tree-hover-bg: rgba(15, 23, 42, .04);--sd-tree-text: #102047;--sd-tree-muted: #5f6f89;display:block}.sd-tree{display:flex;flex-direction:column;width:100%}.sd-tree__row{position:relative;display:flex;align-items:center;min-height:var(--sd-tree-row-height);box-sizing:border-box;padding:6px 4px 6px calc(4px + var(--sd-tree-level) * var(--sd-tree-indent-size));color:var(--sd-tree-text);border-radius:0}.sd-tree__row:hover{background:var(--sd-tree-hover-bg)}.sd-tree__row--selected{background:var(--sd-tree-selected-bg)}.sd-tree__main{display:flex;align-items:center;min-width:0;flex:1 1 auto}.sd-tree__toggle{display:inline-flex;align-items:center;justify-content:center;flex:0 0 var(--sd-tree-control-size);width:var(--sd-tree-control-size);height:var(--sd-tree-control-size);padding:0;color:var(--sd-tree-muted);background:transparent;border:0;border-radius:4px;cursor:pointer}.sd-tree__toggle:disabled{cursor:default}.sd-tree__toggle--placeholder{visibility:hidden}.sd-tree__toggle mat-icon{width:20px;height:20px;font-size:20px;line-height:20px}.sd-tree__checkbox{flex:0 0 auto;height:var(--sd-tree-control-size);margin:0 4px 0 0;transform:scale(.85);transform-origin:center;--mdc-checkbox-selected-checkmark-color: #ffffff;--mdc-checkbox-selected-focus-icon-color: var(--sd-primary, #2a66f4);--mdc-checkbox-selected-hover-icon-color: var(--sd-primary, #2a66f4);--mdc-checkbox-selected-icon-color: var(--sd-primary, #2a66f4);--mdc-checkbox-selected-pressed-icon-color: var(--sd-primary, #2a66f4)}.sd-tree__item-icon{flex:0 0 auto;width:20px;height:20px;margin:0 8px 0 0;font-size:20px;line-height:20px}.sd-tree__content{display:-webkit-box;min-width:0;min-height:var(--sd-tree-control-size);padding:4px 0;overflow:hidden;overflow-wrap:anywhere;-webkit-box-orient:vertical;-webkit-line-clamp:2;line-height:20px}.sd-tree__content--custom{display:block;max-height:none;-webkit-line-clamp:unset}.sd-tree__label{font-size:14px;font-weight:500}.sd-tree__command-trigger{display:inline-flex;align-items:center;justify-content:center;flex:0 0 auto;align-self:center;width:24px;height:24px;padding:0;margin-left:8px;line-height:24px;opacity:0;transition:opacity .12s ease}.sd-tree__row:hover .sd-tree__command-trigger,.sd-tree__command-trigger[aria-expanded=true]{opacity:1}.sd-tree__command-trigger mat-icon.c-icon,.sd-tree__command-menu-icon{width:16px;height:16px;font-size:16px;line-height:16px}.sd-tree__command-trigger mat-icon.c-icon,.sd-tree__command-menu-icon--default{color:var(--sd-black400)!important}::ng-deep .mat-mdc-menu-panel.sd-tree__command-menu .mat-mdc-menu-item.sd-tree__command-menu-item,::ng-deep .mat-menu-panel.sd-tree__command-menu .mat-menu-item.sd-tree__command-menu-item{min-height:40px;padding:0 12px}::ng-deep .mat-mdc-menu-panel.sd-tree__command-menu .mat-mdc-menu-item.sd-tree__command-menu-item .mat-mdc-menu-item-text,::ng-deep .mat-mdc-menu-panel.sd-tree__command-menu .mat-mdc-menu-item.sd-tree__command-menu-item .mdc-list-item__primary-text,::ng-deep .mat-menu-panel.sd-tree__command-menu .mat-menu-item.sd-tree__command-menu-item{width:100%;min-width:0}.sd-tree__command-menu-content{display:flex;align-items:center;gap:6px;width:100%;min-width:0;line-height:20px}.sd-tree__command-menu-icon{display:flex;align-items:center;justify-content:center;flex:0 0 16px;margin:0!important;padding:0;text-align:center;overflow:hidden}.sd-tree__command-title{display:block;min-width:0;line-height:20px}.c-bg-length{display:flex;flex-direction:column;align-items:flex-start;position:static;width:auto;min-width:48px;height:48px;padding:12px 8px;background:var(--sd-primary);border-radius:4px 0 0 4px}.c-bg-length .c-length{position:static;width:auto;min-width:32px;height:24px;color:#fff;font-family:Roboto,sans-serif;font-size:16px;font-style:normal;font-weight:500;line-height:24px;text-align:center}.c-message{position:static;min-width:200px;height:20px;margin:0 0 0 8px;color:#000;font-family:Roboto,sans-serif;font-size:14px;font-style:normal;font-weight:400;line-height:20px}.sd-tree__qa-actions{align-items:center;gap:4px;margin-right:8px}\n"] }]
|
|
505
|
+
}], ctorParameters: () => [], propDecorators: { autoIdInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "autoId", required: false }] }], option: [{ type: i0.Input, args: [{ isSignal: true, alias: "option", required: false }] }], items: [{ type: i0.Input, args: [{ isSignal: true, alias: "items", required: false }] }], tree: [{ type: i0.Input, args: [{ isSignal: true, alias: "tree", required: false }] }], selectedItemsInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectedItems", required: false }] }], commands: [{ type: i0.Input, args: [{ isSignal: true, alias: "commands", required: false }] }], selectable: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectable", required: false }] }], selector: [{ type: i0.Input, args: [{ isSignal: true, alias: "selector", required: false }] }], itemTemplate: [{ type: i0.Input, args: [{ isSignal: true, alias: "itemTemplate", required: false }] }], selectedItemsChange: [{ type: i0.Output, args: ["selectedItemsChange"] }], selectChange: [{ type: i0.Output, args: ["selectChange"] }], expandChange: [{ type: i0.Output, args: ["expandChange"] }], collapseChange: [{ type: i0.Output, args: ["collapseChange"] }], itemDef: [{ type: i0.ContentChild, args: [i0.forwardRef(() => SdTreeItemDefDirective), { isSignal: true }] }] } });
|
|
506
|
+
function normalizeText(value) {
|
|
507
|
+
return value
|
|
508
|
+
.normalize('NFD')
|
|
509
|
+
.replace(/[\u0300-\u036f]/g, '')
|
|
510
|
+
.replace(/[\u0111\u0110]/g, match => (match === '\u0110' ? 'D' : 'd'))
|
|
511
|
+
.toLowerCase()
|
|
512
|
+
.trim();
|
|
513
|
+
}
|
|
514
|
+
function sanitizeId(value) {
|
|
515
|
+
return value.replace(/[^a-zA-Z0-9_-]/g, '-');
|
|
516
|
+
}
|
|
517
|
+
function isPromiseLike(value) {
|
|
518
|
+
return !!value && typeof value.then === 'function';
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* Generated bundle index. Do not edit.
|
|
523
|
+
*/
|
|
524
|
+
|
|
525
|
+
export { SdTree, SdTreeItemDefDirective };
|
|
526
|
+
//# sourceMappingURL=sdcorejs-angular-components-tree.mjs.map
|