@mozaic-ds/angular 2.0.32 → 2.0.33

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.
@@ -7,7 +7,7 @@ import { FormsModule, ReactiveFormsModule, NG_VALUE_ACCESSOR } from '@angular/fo
7
7
  import { WarningCircle32, Uploading32, CheckCircle32, CrossCircleFilled20, Refresh32, Refresh20, Eye20, Upload24, Cross24, ChevronLeft24, ChevronRight24, ChevronLeft20, ChevronRight20, CrossCircleFilled24, More24, Less24, InfoCircle32, CrossCircle32, Cross20, CrossCircle24, ImageAlt32, ChevronDown24, CheckCircleFilled32, WarningCircleFilled32, CrossCircleFilled32, InfoCircleFilled32, SidebarExpand24, ChevronDown20, InfoCircleFilled24, WarningCircleFilled24, CheckCircleFilled24, ArrowBottomRight24, ArrowTopRight24, StarHalf32, StarFilled32, Star32, StarHalf24, StarFilled24, Star24, StarHalf20, StarFilled20, Star20, Check20, Check24, ArrowBack24, ArrowNext24, HelpCircle24, Menu24, Notification24, Search24, PauseCircle24, PlayCircle24, ChevronUp20, Settings20, Drag20, ListAdd20, ViewGridX420, Filter20, FullscreenEnter20, FullscreenExit20, Download20, CheckCircle24 } from '@mozaic-ds/icons-angular';
8
8
  import { Overlay, OverlayConfig, OverlayPositionBuilder, CdkConnectedOverlay, CdkOverlayOrigin } from '@angular/cdk/overlay';
9
9
  import { CdkPortalOutlet, ComponentPortal } from '@angular/cdk/portal';
10
- import { Subject, take } from 'rxjs';
10
+ import { Subject, take, tap, of, firstValueFrom } from 'rxjs';
11
11
  import parsePhoneNumberFromString, { getCountries, getExampleNumber, isValidPhoneNumber, getCountryCallingCode } from 'libphonenumber-js';
12
12
  import examples from 'libphonenumber-js/mobile/examples';
13
13
  import * as i1$1 from '@angular/cdk/scrolling';
@@ -11392,6 +11392,7 @@ class TreeStateService {
11392
11392
  expandedIds = signal(new Set(), ...(ngDevMode ? [{ debugName: "expandedIds" }] : /* istanbul ignore next */ []));
11393
11393
  loadingIds = signal(new Set(), ...(ngDevMode ? [{ debugName: "loadingIds" }] : /* istanbul ignore next */ []));
11394
11394
  internalNodes = signal([], ...(ngDevMode ? [{ debugName: "internalNodes" }] : /* istanbul ignore next */ []));
11395
+ loadChildrenFn = signal(null, ...(ngDevMode ? [{ debugName: "loadChildrenFn" }] : /* istanbul ignore next */ []));
11395
11396
  flatVisibleNodes = computed(() => {
11396
11397
  const result = [];
11397
11398
  this._flatten(this.internalNodes(), result, 0, null);
@@ -11427,6 +11428,21 @@ class TreeStateService {
11427
11428
  return next;
11428
11429
  });
11429
11430
  }
11431
+ expandAndLoad(node) {
11432
+ const wasExpanded = this.expandedIds().has(node.id);
11433
+ this.toggleExpanded(node.id);
11434
+ if (!wasExpanded) {
11435
+ const loadFn = this.loadChildrenFn();
11436
+ if (loadFn && node.children === undefined) {
11437
+ this.addLoading(node.id);
11438
+ return loadFn(node).pipe(take(1), tap((children) => {
11439
+ this.patchChildren(node.id, children);
11440
+ this.removeLoading(node.id);
11441
+ }), tap(() => void 0));
11442
+ }
11443
+ }
11444
+ return of(undefined);
11445
+ }
11430
11446
  addLoading(id) {
11431
11447
  this.loadingIds.update((s) => new Set([...s, id]));
11432
11448
  }
@@ -11451,6 +11467,21 @@ class TreeStateService {
11451
11467
  return n;
11452
11468
  });
11453
11469
  }
11470
+ findNode(nodeId) {
11471
+ return this._findNodeRecursive(this.internalNodes(), nodeId);
11472
+ }
11473
+ _findNodeRecursive(nodes, id) {
11474
+ for (const node of nodes) {
11475
+ if (node.id === id)
11476
+ return node;
11477
+ if (node.children) {
11478
+ const found = this._findNodeRecursive(node.children, id);
11479
+ if (found)
11480
+ return found;
11481
+ }
11482
+ }
11483
+ return null;
11484
+ }
11454
11485
  findParentId(nodeId) {
11455
11486
  const flat = this.flatVisibleNodes();
11456
11487
  const entry = flat.find((f) => f.node.id === nodeId);
@@ -11614,7 +11645,7 @@ class TreeKeyboardService {
11614
11645
  break;
11615
11646
  const isExpanded = this.state.expandedIds().has(current.node.id);
11616
11647
  if (this._hasChildren(current.node) && !isExpanded && !current.node.disabled) {
11617
- this.state.toggleExpanded(current.node.id);
11648
+ this.state.expandAndLoad(current.node).subscribe();
11618
11649
  }
11619
11650
  else if (isExpanded) {
11620
11651
  const firstChild = flat[currentIndex + 1];
@@ -11642,7 +11673,7 @@ class TreeKeyboardService {
11642
11673
  if (!current)
11643
11674
  break;
11644
11675
  if (this._hasChildren(current.node) && !current.node.disabled) {
11645
- this.state.toggleExpanded(current.node.id);
11676
+ this.state.expandAndLoad(current.node).subscribe();
11646
11677
  }
11647
11678
  break;
11648
11679
  }
@@ -11690,7 +11721,7 @@ class TreeKeyboardService {
11690
11721
  const siblings = flat.filter((f) => f.depth === current.depth && f.parentId === current.parentId);
11691
11722
  for (const sibling of siblings) {
11692
11723
  if (this._hasChildren(sibling.node) && !this.state.expandedIds().has(sibling.node.id)) {
11693
- this.state.toggleExpanded(sibling.node.id);
11724
+ this.state.expandAndLoad(sibling.node).subscribe();
11694
11725
  }
11695
11726
  }
11696
11727
  }
@@ -11760,24 +11791,8 @@ class MozTreeNodeComponent {
11760
11791
  }
11761
11792
  }
11762
11793
  onToggleExpand() {
11763
- const node = this.node();
11764
- if (this.isExpanded()) {
11765
- this.stateService.toggleExpanded(node.id);
11766
- this.expandChange.emit(node.id);
11767
- return;
11768
- }
11769
- this.stateService.toggleExpanded(node.id);
11770
- this.expandChange.emit(node.id);
11771
- const loadFn = this.loadChildren();
11772
- if (loadFn && node.children === undefined) {
11773
- this.stateService.addLoading(node.id);
11774
- loadFn(node)
11775
- .pipe(take(1))
11776
- .subscribe((children) => {
11777
- this.stateService.patchChildren(node.id, children);
11778
- this.stateService.removeLoading(node.id);
11779
- });
11780
- }
11794
+ this.stateService.expandAndLoad(this.node()).subscribe();
11795
+ this.expandChange.emit(this.node().id);
11781
11796
  }
11782
11797
  onCheckboxChange(event) {
11783
11798
  if (this.isDisabled())
@@ -11889,6 +11904,9 @@ class MozTreeComponent {
11889
11904
  effect(() => {
11890
11905
  this.selectionService.setRootNodes(this.nodes());
11891
11906
  });
11907
+ effect(() => {
11908
+ this.stateService.loadChildrenFn.set(this.loadChildren());
11909
+ });
11892
11910
  }
11893
11911
  onTreeKeydown(event) {
11894
11912
  this.keyboardService.handleKeydown(event);
@@ -11902,6 +11920,41 @@ class MozTreeComponent {
11902
11920
  onSelectionChange(ids) {
11903
11921
  this.selectionChange.emit(ids);
11904
11922
  }
11923
+ async expandPath(path) {
11924
+ const loadFn = this.stateService.loadChildrenFn();
11925
+ for (let i = 0; i < path.length - 1; i++) {
11926
+ const nodeId = path[i];
11927
+ const node = this.stateService.findNode(nodeId);
11928
+ if (!node)
11929
+ break;
11930
+ // Expand first so the children area is visible
11931
+ if (!this.stateService.expandedIds().has(nodeId)) {
11932
+ this.stateService.toggleExpanded(nodeId);
11933
+ this.expandedIdsChange.emit(new Set(this.stateService.expandedIds()));
11934
+ // Yield to let Angular render the expansion
11935
+ await new Promise((resolve) => setTimeout(resolve));
11936
+ }
11937
+ // Load children if needed
11938
+ if (loadFn && node.children === undefined) {
11939
+ this.stateService.addLoading(nodeId);
11940
+ this.expandedIdsChange.emit(new Set(this.stateService.expandedIds()));
11941
+ // Yield to let Angular render the loader
11942
+ await new Promise((resolve) => setTimeout(resolve));
11943
+ const children = await firstValueFrom(loadFn(node).pipe(take(1)));
11944
+ this.stateService.patchChildren(nodeId, children);
11945
+ this.stateService.removeLoading(nodeId);
11946
+ // Yield to let Angular render the new children
11947
+ await new Promise((resolve) => setTimeout(resolve));
11948
+ }
11949
+ }
11950
+ this.expandedIdsChange.emit(new Set(this.stateService.expandedIds()));
11951
+ }
11952
+ scrollToNode(nodeId) {
11953
+ setTimeout(() => {
11954
+ const el = document.querySelector(`[data-tree-node-id="${nodeId}"]`);
11955
+ el?.scrollIntoView({ block: 'center', behavior: 'smooth' });
11956
+ });
11957
+ }
11905
11958
  expandAll() {
11906
11959
  const flat = this.stateService.flatVisibleNodes();
11907
11960
  const allIds = new Set(flat.map((f) => f.node.id));