@xiriframework/xiri-ng 0.2.32 → 0.2.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.
|
@@ -3518,10 +3518,11 @@ function flatten(roots, expandedIds) {
|
|
|
3518
3518
|
/**
|
|
3519
3519
|
* Search projection: returns each match together with its full subtree (all descendants)
|
|
3520
3520
|
* plus the ancestor path leading to it; everything else is hidden. Matches and their
|
|
3521
|
-
* descendants are shown fully; ancestor-only context nodes are flagged dimmed.
|
|
3522
|
-
*
|
|
3521
|
+
* descendants are shown fully; ancestor-only context nodes are flagged dimmed. Within the
|
|
3522
|
+
* filtered result, expand/collapse follows `expandedIds` (same state model as the flat view) —
|
|
3523
|
+
* pass an all-expanded set to show everything. The `matches` predicate decides hits.
|
|
3523
3524
|
*/
|
|
3524
|
-
function searchProjection(roots, matches) {
|
|
3525
|
+
function searchProjection(roots, matches, expandedIds) {
|
|
3525
3526
|
const visible = new Set();
|
|
3526
3527
|
const inMatchSubtree = new Set(); // node matches itself or sits under a match → shown fully
|
|
3527
3528
|
// underMatch: an ancestor of this node already matched, so the whole subtree is shown.
|
|
@@ -3548,15 +3549,18 @@ function searchProjection(roots, matches) {
|
|
|
3548
3549
|
if (!visible.has(node))
|
|
3549
3550
|
continue;
|
|
3550
3551
|
const visibleChildren = node.children.filter(c => visible.has(c));
|
|
3552
|
+
const hasChildren = visibleChildren.length > 0;
|
|
3553
|
+
const expanded = hasChildren && expandedIds.has(node.id);
|
|
3551
3554
|
node.row._tree = {
|
|
3552
3555
|
level: node.level,
|
|
3553
|
-
hasChildren
|
|
3554
|
-
expanded
|
|
3556
|
+
hasChildren,
|
|
3557
|
+
expanded,
|
|
3555
3558
|
childCount: visibleChildren.length,
|
|
3556
3559
|
dimmed: !inMatchSubtree.has(node),
|
|
3557
3560
|
};
|
|
3558
3561
|
out.push(node.row);
|
|
3559
|
-
|
|
3562
|
+
if (expanded)
|
|
3563
|
+
walk(node.children);
|
|
3560
3564
|
}
|
|
3561
3565
|
};
|
|
3562
3566
|
walk(roots);
|
|
@@ -3607,29 +3611,32 @@ class XiriTableTreeService {
|
|
|
3607
3611
|
this.roots = buildTree(rows, this.config.idField, this.config.parentIdField, this.treeColumnId);
|
|
3608
3612
|
const persisted = this.loadPersisted();
|
|
3609
3613
|
if (persisted)
|
|
3610
|
-
this.expanded = new Set(persisted);
|
|
3611
|
-
else if (this.config.
|
|
3612
|
-
this.expanded =
|
|
3614
|
+
this.expanded = new Set(persisted); // persisted state wins
|
|
3615
|
+
else if (this.config.collapseAllByDefault)
|
|
3616
|
+
this.expanded = new Set(); // opt-in: start collapsed
|
|
3613
3617
|
else
|
|
3614
|
-
this.expanded =
|
|
3618
|
+
this.expanded = collectExpandableIds(this.roots); // default: start fully expanded
|
|
3615
3619
|
}
|
|
3616
3620
|
/** Returns the visible rows: search projection when searching, otherwise the expand-state flatten. */
|
|
3617
3621
|
visibleRows(matches) {
|
|
3618
3622
|
if (this.searchActive && matches)
|
|
3619
|
-
return searchProjection(this.roots, matches);
|
|
3623
|
+
return searchProjection(this.roots, matches, this.expanded);
|
|
3620
3624
|
return flatten(this.roots, this.expanded);
|
|
3621
3625
|
}
|
|
3622
3626
|
/**
|
|
3623
3627
|
* Applies (or clears) a search. On the empty→active transition the current expand-state is
|
|
3624
|
-
* snapshotted
|
|
3628
|
+
* snapshotted and the tree is fully expanded (so all matches are visible); during the search
|
|
3629
|
+
* the same `expanded` state drives expand/collapse, so the arrows work. On active→empty the
|
|
3630
|
+
* pre-search state is restored (Spec §5). Returns the new visible rows.
|
|
3625
3631
|
*/
|
|
3626
3632
|
applySearch(matches) {
|
|
3627
3633
|
if (matches) {
|
|
3628
3634
|
if (!this.searchActive) {
|
|
3629
3635
|
this.savedExpanded = new Set(this.expanded);
|
|
3636
|
+
this.expanded = collectExpandableIds(this.roots); // start fully expanded
|
|
3630
3637
|
this.searchActive = true;
|
|
3631
3638
|
}
|
|
3632
|
-
return searchProjection(this.roots, matches);
|
|
3639
|
+
return searchProjection(this.roots, matches, this.expanded);
|
|
3633
3640
|
}
|
|
3634
3641
|
if (this.searchActive) {
|
|
3635
3642
|
if (this.savedExpanded)
|
|
@@ -3645,7 +3652,10 @@ class XiriTableTreeService {
|
|
|
3645
3652
|
this.expanded.delete(id);
|
|
3646
3653
|
else
|
|
3647
3654
|
this.expanded.add(id);
|
|
3648
|
-
|
|
3655
|
+
// Don't persist transient expand changes made while searching — savedExpanded holds the
|
|
3656
|
+
// real state and is restored on reset.
|
|
3657
|
+
if (!this.searchActive)
|
|
3658
|
+
this.persist();
|
|
3649
3659
|
}
|
|
3650
3660
|
expandAll() {
|
|
3651
3661
|
this.expanded = collectExpandableIds(this.roots);
|