@acorex/platform 20.7.5 → 20.7.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.
@@ -6501,24 +6501,46 @@ class AXPEntityCategoryTreeSelectorComponent extends AXBasePageComponent {
6501
6501
  if (this.treeData.categoryEntityDef?.parentKey) {
6502
6502
  this.treeConfig.parentKey = this.treeData.categoryEntityDef.parentKey;
6503
6503
  }
6504
- // Initialize selected nodes and load their data into cache
6505
- // Wait for tree to be ready before syncing selection
6506
- await new Promise((resolve) => setTimeout(resolve, 100));
6507
- await this.updateSelectedNodes(this.selectedValues());
6508
- // After initial sync, wait a bit more and sync again to catch any nodes that loaded late
6509
- await new Promise((resolve) => setTimeout(resolve, 200));
6510
- const finalSelectedIds = this.selectedNodeIds();
6511
- if (finalSelectedIds.length > 0) {
6512
- await this.syncSelectionWithTree(finalSelectedIds);
6504
+ // CRITICAL FIX: Parse initial selected values and set selectedNodeIds BEFORE tree renders.
6505
+ // This allows the datasource callback to mark nodes as selected when they load.
6506
+ // Previously, we tried to sync selection while loading was true, but the tree
6507
+ // component doesn't exist until loading is false, causing sync methods to fail silently.
6508
+ const initialSelectedIds = this.selectedValues().filter((id) => id && id !== 'all');
6509
+ if (initialSelectedIds.length > 0) {
6510
+ // Load missing node data into cache first (needed for path calculation and node display)
6511
+ await this.loadMissingNodeData(initialSelectedIds);
6512
+ // Set selectedNodeIds so datasource callback can use it to mark nodes as selected
6513
+ this.selectedNodeIds.set(initialSelectedIds);
6513
6514
  }
6514
6515
  }
6515
6516
  catch (error) {
6516
6517
  console.error('Error loading entity definition:', error);
6517
6518
  }
6518
6519
  finally {
6520
+ // Now let tree render by setting loading to false
6519
6521
  this.loading.set(false);
6520
- this.isInitializing = false; // Mark initialization as complete
6521
6522
  }
6523
+ // AFTER tree renders, perform selection sync operations.
6524
+ // This must happen after loading.set(false) so the tree component exists in DOM.
6525
+ const selectedIds = this.selectedNodeIds();
6526
+ if (selectedIds.length > 0) {
6527
+ try {
6528
+ // Wait for tree to render and stabilize
6529
+ await new Promise((resolve) => setTimeout(resolve, 150));
6530
+ // Build ancestor chains for path expansion (so selected nodes become visible)
6531
+ const ancestorChains = await this.buildAncestorChains(selectedIds);
6532
+ // Expand ancestor nodes to make selected nodes visible in tree
6533
+ await this.expandAncestorNodesInOrder(ancestorChains);
6534
+ // Wait for tree to process expansions
6535
+ await new Promise((resolve) => setTimeout(resolve, 100));
6536
+ // Final sync to ensure all nodes are properly selected in tree component
6537
+ await this.syncSelectionWithTree(selectedIds);
6538
+ }
6539
+ catch (error) {
6540
+ console.error('Error syncing selection after tree render:', error);
6541
+ }
6542
+ }
6543
+ this.isInitializing = false; // Mark initialization as complete
6522
6544
  }
6523
6545
  //#endregion
6524
6546
  //#region ---- Public Methods ----
@@ -9318,7 +9340,7 @@ class AXPEntityCategoryWidgetEditComponent extends AXPValueWidgetComponent {
9318
9340
  textField: signal(this.textField()),
9319
9341
  valueField: signal(this.valueField()),
9320
9342
  allowMultiple: signal(this.multiple()),
9321
- // selectedValues: signal(selectedIds),
9343
+ selectedValues: signal(selectedIds),
9322
9344
  searchPlaceholder: signal(this.searchPlaceholderText()),
9323
9345
  excludedNodeId: signal(excludedNodeId),
9324
9346
  },