@myrmidon/paged-data-browsers 5.0.2 → 5.1.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/README.md +101 -14
- package/fesm2022/myrmidon-paged-data-browsers.mjs +831 -66
- package/fesm2022/myrmidon-paged-data-browsers.mjs.map +1 -1
- package/index.d.ts +255 -10
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ interface TreeNode {
|
|
|
14
14
|
label: string;
|
|
15
15
|
tag?: string;
|
|
16
16
|
hasChildren?: boolean;
|
|
17
|
+
hilite?: boolean;
|
|
17
18
|
}
|
|
18
19
|
/**
|
|
19
20
|
* A filter for tree nodes.
|
|
@@ -56,7 +57,7 @@ interface PagedTreeStoreService<F extends TreeNodeFilter> {
|
|
|
56
57
|
getNodes(filter: F, pageNumber: number, pageSize: number, hasMockRoot?: boolean): Observable<DataPage<TreeNode>>;
|
|
57
58
|
}
|
|
58
59
|
/**
|
|
59
|
-
* Options for the
|
|
60
|
+
* Options for the PagedTreeStore.
|
|
60
61
|
*/
|
|
61
62
|
interface PagedTreeStoreOptions {
|
|
62
63
|
/**
|
|
@@ -84,11 +85,13 @@ interface PagedTreeStoreOptions {
|
|
|
84
85
|
}
|
|
85
86
|
/**
|
|
86
87
|
* A store for the node browser component. This store is used to keep a
|
|
87
|
-
* list of nodes, and to load them from the
|
|
88
|
-
* node. Every tree node in the list
|
|
89
|
-
* page count and total items, plus
|
|
88
|
+
* list of nodes, and to load them from the injected PagedTreeStoreService<F>.
|
|
89
|
+
* It also keeps the root node(s) in memory. Every tree node in the list
|
|
90
|
+
* is extended with page number, page count and total items, plus
|
|
91
|
+
* expansion-related metadata.
|
|
90
92
|
* The store keeps a flat list of these tree nodes, allowing users to
|
|
91
|
-
* expand and collapse them.
|
|
93
|
+
* expand and collapse them. Each node has its children paged, and optionally
|
|
94
|
+
* filtered.
|
|
92
95
|
* F is the type of the filter object, E is the type of the paged tree nodes.
|
|
93
96
|
*/
|
|
94
97
|
declare class PagedTreeStore<E extends PagedTreeNode<F>, F extends TreeNodeFilter> {
|
|
@@ -121,7 +124,7 @@ declare class PagedTreeStore<E extends PagedTreeNode<F>, F extends TreeNodeFilte
|
|
|
121
124
|
*/
|
|
122
125
|
constructor(_service: PagedTreeStoreService<F>, options?: PagedTreeStoreOptions);
|
|
123
126
|
/**
|
|
124
|
-
* Gets the global filter,
|
|
127
|
+
* Gets the global filter, optionally overridden with values
|
|
125
128
|
* from the specified node's filter.
|
|
126
129
|
* @param node The optional node.
|
|
127
130
|
* @returns The filter.
|
|
@@ -138,7 +141,8 @@ declare class PagedTreeStore<E extends PagedTreeNode<F>, F extends TreeNodeFilte
|
|
|
138
141
|
*/
|
|
139
142
|
getNodes(): Readonly<PagedTreeNode<F>[]>;
|
|
140
143
|
/**
|
|
141
|
-
* Get the root node of the tree.
|
|
144
|
+
* Get the root node of the tree. Given that the store keeps a flat
|
|
145
|
+
* list, this is the first node in the list, if any.
|
|
142
146
|
* @returns The root node of the tree or undefined if empty.
|
|
143
147
|
*/
|
|
144
148
|
getRootNode(): PagedTreeNode<F> | undefined;
|
|
@@ -201,6 +205,11 @@ declare class PagedTreeStore<E extends PagedTreeNode<F>, F extends TreeNodeFilte
|
|
|
201
205
|
* @returns Promise.
|
|
202
206
|
*/
|
|
203
207
|
expandAll(id?: number): Promise<boolean>;
|
|
208
|
+
/**
|
|
209
|
+
* Get the children of the node with the specified ID.
|
|
210
|
+
* @param id The ID of the node whose children you want to get.
|
|
211
|
+
* @returns An array of child nodes.
|
|
212
|
+
*/
|
|
204
213
|
getChildren(id: number): E[];
|
|
205
214
|
private removeDescendants;
|
|
206
215
|
/**
|
|
@@ -219,7 +228,8 @@ declare class PagedTreeStore<E extends PagedTreeNode<F>, F extends TreeNodeFilte
|
|
|
219
228
|
*/
|
|
220
229
|
collapseAll(id?: number): Promise<boolean>;
|
|
221
230
|
/**
|
|
222
|
-
* Change the page including the
|
|
231
|
+
* Change the page including the children of the parent node with
|
|
232
|
+
* the specified ID.
|
|
223
233
|
* @param parentId The ID of the parent node whose children are inside the page
|
|
224
234
|
* you want to change.
|
|
225
235
|
* @param pageNumber The new page number.
|
|
@@ -241,9 +251,98 @@ declare class PagedTreeStore<E extends PagedTreeNode<F>, F extends TreeNodeFilte
|
|
|
241
251
|
* @returns True if the page is in cache, false otherwise.
|
|
242
252
|
*/
|
|
243
253
|
hasCachedPage(pageNumber: number, filter: F): boolean;
|
|
254
|
+
/**
|
|
255
|
+
* Remove all hilite properties from all nodes in the store.
|
|
256
|
+
*/
|
|
257
|
+
removeHilites(): void;
|
|
258
|
+
/**
|
|
259
|
+
* Find all nodes whose labels include the specified search text,
|
|
260
|
+
* highlight them, and ensure they are visible by expanding their ancestors.
|
|
261
|
+
* @param searchText The text to search for in node labels (case-insensitive).
|
|
262
|
+
* @returns Promise that resolves when all matching nodes are highlighted and visible.
|
|
263
|
+
*/
|
|
264
|
+
findLabels(searchText: string): Promise<void>;
|
|
265
|
+
/**
|
|
266
|
+
* Search through all nodes recursively to find matches, including nodes
|
|
267
|
+
* that are not currently loaded/visible.
|
|
268
|
+
* @param searchLower The search text in lowercase.
|
|
269
|
+
* @param matchingNodes Array to collect matching nodes.
|
|
270
|
+
*/
|
|
271
|
+
private searchAllNodes;
|
|
272
|
+
/**
|
|
273
|
+
* Recursively search a node and all its descendants for label matches.
|
|
274
|
+
* @param node The node to search.
|
|
275
|
+
* @param searchLower The search text in lowercase.
|
|
276
|
+
* @param matchingNodes Array to collect matching nodes.
|
|
277
|
+
*/
|
|
278
|
+
private searchNodeAndDescendants;
|
|
279
|
+
/**
|
|
280
|
+
* Ensure a node is visible by expanding all its ancestors.
|
|
281
|
+
* @param nodeId The ID of the node to make visible.
|
|
282
|
+
*/
|
|
283
|
+
private ensureNodeVisible;
|
|
284
|
+
private get _isEditable();
|
|
285
|
+
private get _editableService();
|
|
286
|
+
/**
|
|
287
|
+
* Add a child node to the specified parent.
|
|
288
|
+
* @param parentId The ID of the parent node.
|
|
289
|
+
* @param child The child node to add (without ID).
|
|
290
|
+
* @param first If true, add as first child; otherwise add as last child.
|
|
291
|
+
* @returns The added node with temporary ID, or undefined if service doesn't support editing.
|
|
292
|
+
*/
|
|
293
|
+
addChild(parentId: number, child: Omit<TreeNode, 'id' | 'parentId'>, first?: boolean): Promise<TreeNode | undefined>;
|
|
294
|
+
/**
|
|
295
|
+
* Add a sibling node next to the anchor node.
|
|
296
|
+
* @param anchorId The ID of the anchor node.
|
|
297
|
+
* @param sibling The sibling node to add (without ID).
|
|
298
|
+
* @param before If true, add before anchor; otherwise add after anchor.
|
|
299
|
+
* @returns The added node with temporary ID, or undefined if service doesn't support editing.
|
|
300
|
+
*/
|
|
301
|
+
addSibling(anchorId: number, sibling: Omit<TreeNode, 'id' | 'parentId' | 'y' | 'x'>, before?: boolean): Promise<TreeNode | undefined>;
|
|
302
|
+
/**
|
|
303
|
+
* Remove a node from the tree.
|
|
304
|
+
* We only track the deletion and update visible siblings.
|
|
305
|
+
* Coordinate adjustments for non-visible nodes are handled by applyLocalChanges.
|
|
306
|
+
*/
|
|
307
|
+
removeNode(nodeId: number): Promise<boolean>;
|
|
308
|
+
/**
|
|
309
|
+
* Replace a node with a new one.
|
|
310
|
+
* @param oldNodeId The ID of the node to replace.
|
|
311
|
+
* @param newNode The new node data (without ID).
|
|
312
|
+
* @param keepDescendants If true, keep descendants; otherwise remove them.
|
|
313
|
+
* @returns Promise that resolves to the new node, or undefined if service
|
|
314
|
+
* doesn't support editing.
|
|
315
|
+
*/
|
|
316
|
+
replaceNode(oldNodeId: number, newNode: Omit<TreeNode, 'id' | 'parentId' | 'y' | 'x'>, keepDescendants?: boolean): Promise<TreeNode | undefined>;
|
|
317
|
+
/**
|
|
318
|
+
* Get all descendants of a node.
|
|
319
|
+
*/
|
|
320
|
+
private getDescendants;
|
|
321
|
+
/**
|
|
322
|
+
* Invalidate cache for a specific parent and its ancestors.
|
|
323
|
+
*/
|
|
324
|
+
private invalidateCache;
|
|
325
|
+
/**
|
|
326
|
+
* Save all pending changes if the service supports it.
|
|
327
|
+
* Preserves the current expansion state after saving.
|
|
328
|
+
* @returns Promise that resolves when save is complete,
|
|
329
|
+
* with ID mappings for new nodes.
|
|
330
|
+
*/
|
|
331
|
+
saveChanges(): Promise<Map<number, number> | undefined>;
|
|
332
|
+
/**
|
|
333
|
+
* Check if there are unsaved changes.
|
|
334
|
+
*/
|
|
335
|
+
hasUnsavedChanges(): boolean;
|
|
336
|
+
/**
|
|
337
|
+
* Clear all unsaved changes.
|
|
338
|
+
*/
|
|
339
|
+
clearUnsavedChanges(): void;
|
|
244
340
|
}
|
|
245
341
|
|
|
246
342
|
declare class CompactPagerComponent {
|
|
343
|
+
/**
|
|
344
|
+
* The current paging information.
|
|
345
|
+
*/
|
|
247
346
|
paging: _angular_core.InputSignal<PagingInfo>;
|
|
248
347
|
/**
|
|
249
348
|
* Emits the new paging information when the user changes the page.
|
|
@@ -490,6 +589,152 @@ declare class PagedListStore<F, E> {
|
|
|
490
589
|
hasCachedPage(pageNumber: number, filter: F): boolean;
|
|
491
590
|
}
|
|
492
591
|
|
|
592
|
+
/**
|
|
593
|
+
* Types of operations that can be performed on tree nodes.
|
|
594
|
+
*/
|
|
595
|
+
declare enum ChangeOperationType {
|
|
596
|
+
ADD = "add",
|
|
597
|
+
REMOVE = "remove",
|
|
598
|
+
UPDATE = "update"
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Represents a change operation on a tree node.
|
|
602
|
+
*/
|
|
603
|
+
interface ChangeOperation {
|
|
604
|
+
type: ChangeOperationType;
|
|
605
|
+
id: number;
|
|
606
|
+
node?: TreeNode;
|
|
607
|
+
originalNode?: TreeNode;
|
|
608
|
+
parentId?: number;
|
|
609
|
+
position?: number;
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
* Interface for a service that can handle both reading and editing tree nodes.
|
|
613
|
+
* Extends the base PagedTreeStoreService with editing capabilities.
|
|
614
|
+
*/
|
|
615
|
+
interface EditablePagedTreeStoreService<F extends TreeNodeFilter> extends PagedTreeStoreService<F> {
|
|
616
|
+
/**
|
|
617
|
+
* Add a new node to the tree.
|
|
618
|
+
* @param node The node data (without ID).
|
|
619
|
+
* @param parentId The parent node ID.
|
|
620
|
+
* @param position Optional position hint.
|
|
621
|
+
* @returns The added node with temporary ID.
|
|
622
|
+
*/
|
|
623
|
+
addNode(node: Omit<TreeNode, 'id'>, parentId?: number, position?: number): TreeNode;
|
|
624
|
+
/**
|
|
625
|
+
* Update an existing node.
|
|
626
|
+
* @param id The node ID.
|
|
627
|
+
* @param updates Partial node updates.
|
|
628
|
+
*/
|
|
629
|
+
updateNode(id: number, updates: Partial<TreeNode>): void;
|
|
630
|
+
/**
|
|
631
|
+
* Remove a node from the tree.
|
|
632
|
+
* @param id The node ID.
|
|
633
|
+
*/
|
|
634
|
+
removeNode(id: number): void;
|
|
635
|
+
/**
|
|
636
|
+
* Get a node by ID, including local changes.
|
|
637
|
+
* @param id The node ID.
|
|
638
|
+
* @returns The node or undefined if not found.
|
|
639
|
+
*/
|
|
640
|
+
getNode(id: number): TreeNode | undefined;
|
|
641
|
+
/**
|
|
642
|
+
* Save all pending changes to the data source.
|
|
643
|
+
* @returns Observable that completes when save is finished, emitting any ID mappings
|
|
644
|
+
* for nodes that received new IDs from the backend.
|
|
645
|
+
*/
|
|
646
|
+
saveChanges(): Observable<Map<number, number>>;
|
|
647
|
+
/**
|
|
648
|
+
* Check if there are any unsaved changes.
|
|
649
|
+
* @returns True if there are pending changes.
|
|
650
|
+
*/
|
|
651
|
+
hasChanges(): boolean;
|
|
652
|
+
/**
|
|
653
|
+
* Clear all pending changes without saving.
|
|
654
|
+
*/
|
|
655
|
+
clearChanges(): void;
|
|
656
|
+
/**
|
|
657
|
+
* Get all pending change operations.
|
|
658
|
+
* @returns Array of change operations.
|
|
659
|
+
*/
|
|
660
|
+
getChanges(): ChangeOperation[];
|
|
661
|
+
}
|
|
662
|
+
/**
|
|
663
|
+
* Base implementation of EditablePagedTreeStoreService that handles change tracking
|
|
664
|
+
* and provides common editing functionality. Implementers only need to override
|
|
665
|
+
* the abstract methods for actual data persistence.
|
|
666
|
+
*/
|
|
667
|
+
declare abstract class EditablePagedTreeStoreServiceBase<F extends TreeNodeFilter> implements EditablePagedTreeStoreService<F> {
|
|
668
|
+
protected _changes: ChangeOperation[];
|
|
669
|
+
protected _nextTempId: number;
|
|
670
|
+
protected _nodes: Map<number, TreeNode>;
|
|
671
|
+
protected _removedNodes: Set<number>;
|
|
672
|
+
private _hasChanges$;
|
|
673
|
+
/**
|
|
674
|
+
* Observable that emits when the change state changes.
|
|
675
|
+
*/
|
|
676
|
+
hasChanges$: Observable<boolean>;
|
|
677
|
+
/**
|
|
678
|
+
* Abstract method to be implemented by subclasses to fetch nodes from the actual data source.
|
|
679
|
+
*/
|
|
680
|
+
protected abstract fetchNodes(filter: F, pageNumber: number, pageSize: number, hasMockRoot?: boolean): Observable<DataPage<TreeNode>>;
|
|
681
|
+
/**
|
|
682
|
+
* Abstract method to be implemented by subclasses to persist changes to the data source.
|
|
683
|
+
* @param changes The changes to persist.
|
|
684
|
+
* @returns Observable that emits a map of temporary IDs to permanent IDs.
|
|
685
|
+
*/
|
|
686
|
+
protected abstract persistChanges(changes: ChangeOperation[]): Observable<Map<number, number>>;
|
|
687
|
+
/**
|
|
688
|
+
* Get nodes, including any local changes that haven't been saved yet.
|
|
689
|
+
*/
|
|
690
|
+
getNodes(filter: F, pageNumber: number, pageSize: number, hasMockRoot?: boolean): Observable<DataPage<TreeNode>>;
|
|
691
|
+
/**
|
|
692
|
+
* Apply local changes to a page of nodes.
|
|
693
|
+
* This includes applying x-coordinate adjustments for siblings of deleted nodes.
|
|
694
|
+
*/
|
|
695
|
+
private applyLocalChanges;
|
|
696
|
+
/**
|
|
697
|
+
* Check if a node matches the given filter.
|
|
698
|
+
*/
|
|
699
|
+
private matchesFilter;
|
|
700
|
+
/**
|
|
701
|
+
* Add a new node to the tree.
|
|
702
|
+
*/
|
|
703
|
+
addNode(node: Omit<TreeNode, 'id'>, parentId?: number, position?: number): TreeNode;
|
|
704
|
+
/**
|
|
705
|
+
* Remove a node from the tree.
|
|
706
|
+
*/
|
|
707
|
+
removeNode(id: number): void;
|
|
708
|
+
/**
|
|
709
|
+
* Update an existing node.
|
|
710
|
+
* If the node is in cache, update it with the partial updates.
|
|
711
|
+
* If not in cache and updates is a complete TreeNode, add it to cache.
|
|
712
|
+
* Otherwise skip (normal for pagination).
|
|
713
|
+
*/
|
|
714
|
+
updateNode(id: number, updates: Partial<TreeNode>): void;
|
|
715
|
+
/**
|
|
716
|
+
* Save all pending changes.
|
|
717
|
+
*/
|
|
718
|
+
saveChanges(): Observable<Map<number, number>>;
|
|
719
|
+
/**
|
|
720
|
+
* Check if there are unsaved changes.
|
|
721
|
+
*/
|
|
722
|
+
hasChanges(): boolean;
|
|
723
|
+
/**
|
|
724
|
+
* Clear all pending changes.
|
|
725
|
+
*/
|
|
726
|
+
clearChanges(): void;
|
|
727
|
+
/**
|
|
728
|
+
* Get all pending changes.
|
|
729
|
+
*/
|
|
730
|
+
getChanges(): ChangeOperation[];
|
|
731
|
+
/**
|
|
732
|
+
* Get a node by ID, including local changes.
|
|
733
|
+
*/
|
|
734
|
+
getNode(id: number): TreeNode | undefined;
|
|
735
|
+
protected updateHasChanges(): void;
|
|
736
|
+
}
|
|
737
|
+
|
|
493
738
|
/**
|
|
494
739
|
* A Least Recently Used cache that can be used to store any type of object.
|
|
495
740
|
* The cache works in two modes: considering the size of the objects or not.
|
|
@@ -550,5 +795,5 @@ declare class LRUCache<T> {
|
|
|
550
795
|
static calculateObjectSize(obj: any): number;
|
|
551
796
|
}
|
|
552
797
|
|
|
553
|
-
export { BrowserTreeNodeComponent, CompactPagerComponent, DEFAULT_PAGED_LIST_STORE_OPTIONS, LRUCache, PagedListStore, PagedTreeStore, RangeViewComponent };
|
|
554
|
-
export type { PageChangeRequest, PagedListStoreOptions, PagedListStoreService, PagedTreeNode, PagedTreeStoreOptions, PagedTreeStoreService, PagingInfo, TreeNode, TreeNodeFilter };
|
|
798
|
+
export { BrowserTreeNodeComponent, ChangeOperationType, CompactPagerComponent, DEFAULT_PAGED_LIST_STORE_OPTIONS, EditablePagedTreeStoreServiceBase, LRUCache, PagedListStore, PagedTreeStore, RangeViewComponent };
|
|
799
|
+
export type { ChangeOperation, EditablePagedTreeStoreService, PageChangeRequest, PagedListStoreOptions, PagedListStoreService, PagedTreeNode, PagedTreeStoreOptions, PagedTreeStoreService, PagingInfo, TreeNode, TreeNodeFilter };
|