@myrmidon/paged-data-browsers 5.0.3 → 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 +713 -50
- package/fesm2022/myrmidon-paged-data-browsers.mjs.map +1 -1
- package/index.d.ts +224 -10
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -57,7 +57,7 @@ interface PagedTreeStoreService<F extends TreeNodeFilter> {
|
|
|
57
57
|
getNodes(filter: F, pageNumber: number, pageSize: number, hasMockRoot?: boolean): Observable<DataPage<TreeNode>>;
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
|
-
* Options for the
|
|
60
|
+
* Options for the PagedTreeStore.
|
|
61
61
|
*/
|
|
62
62
|
interface PagedTreeStoreOptions {
|
|
63
63
|
/**
|
|
@@ -85,11 +85,13 @@ interface PagedTreeStoreOptions {
|
|
|
85
85
|
}
|
|
86
86
|
/**
|
|
87
87
|
* A store for the node browser component. This store is used to keep a
|
|
88
|
-
* list of nodes, and to load them from the
|
|
89
|
-
* node. Every tree node in the list
|
|
90
|
-
* 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.
|
|
91
92
|
* The store keeps a flat list of these tree nodes, allowing users to
|
|
92
|
-
* expand and collapse them.
|
|
93
|
+
* expand and collapse them. Each node has its children paged, and optionally
|
|
94
|
+
* filtered.
|
|
93
95
|
* F is the type of the filter object, E is the type of the paged tree nodes.
|
|
94
96
|
*/
|
|
95
97
|
declare class PagedTreeStore<E extends PagedTreeNode<F>, F extends TreeNodeFilter> {
|
|
@@ -122,7 +124,7 @@ declare class PagedTreeStore<E extends PagedTreeNode<F>, F extends TreeNodeFilte
|
|
|
122
124
|
*/
|
|
123
125
|
constructor(_service: PagedTreeStoreService<F>, options?: PagedTreeStoreOptions);
|
|
124
126
|
/**
|
|
125
|
-
* Gets the global filter,
|
|
127
|
+
* Gets the global filter, optionally overridden with values
|
|
126
128
|
* from the specified node's filter.
|
|
127
129
|
* @param node The optional node.
|
|
128
130
|
* @returns The filter.
|
|
@@ -139,7 +141,8 @@ declare class PagedTreeStore<E extends PagedTreeNode<F>, F extends TreeNodeFilte
|
|
|
139
141
|
*/
|
|
140
142
|
getNodes(): Readonly<PagedTreeNode<F>[]>;
|
|
141
143
|
/**
|
|
142
|
-
* 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.
|
|
143
146
|
* @returns The root node of the tree or undefined if empty.
|
|
144
147
|
*/
|
|
145
148
|
getRootNode(): PagedTreeNode<F> | undefined;
|
|
@@ -202,6 +205,11 @@ declare class PagedTreeStore<E extends PagedTreeNode<F>, F extends TreeNodeFilte
|
|
|
202
205
|
* @returns Promise.
|
|
203
206
|
*/
|
|
204
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
|
+
*/
|
|
205
213
|
getChildren(id: number): E[];
|
|
206
214
|
private removeDescendants;
|
|
207
215
|
/**
|
|
@@ -220,7 +228,8 @@ declare class PagedTreeStore<E extends PagedTreeNode<F>, F extends TreeNodeFilte
|
|
|
220
228
|
*/
|
|
221
229
|
collapseAll(id?: number): Promise<boolean>;
|
|
222
230
|
/**
|
|
223
|
-
* Change the page including the
|
|
231
|
+
* Change the page including the children of the parent node with
|
|
232
|
+
* the specified ID.
|
|
224
233
|
* @param parentId The ID of the parent node whose children are inside the page
|
|
225
234
|
* you want to change.
|
|
226
235
|
* @param pageNumber The new page number.
|
|
@@ -272,9 +281,68 @@ declare class PagedTreeStore<E extends PagedTreeNode<F>, F extends TreeNodeFilte
|
|
|
272
281
|
* @param nodeId The ID of the node to make visible.
|
|
273
282
|
*/
|
|
274
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;
|
|
275
340
|
}
|
|
276
341
|
|
|
277
342
|
declare class CompactPagerComponent {
|
|
343
|
+
/**
|
|
344
|
+
* The current paging information.
|
|
345
|
+
*/
|
|
278
346
|
paging: _angular_core.InputSignal<PagingInfo>;
|
|
279
347
|
/**
|
|
280
348
|
* Emits the new paging information when the user changes the page.
|
|
@@ -521,6 +589,152 @@ declare class PagedListStore<F, E> {
|
|
|
521
589
|
hasCachedPage(pageNumber: number, filter: F): boolean;
|
|
522
590
|
}
|
|
523
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
|
+
|
|
524
738
|
/**
|
|
525
739
|
* A Least Recently Used cache that can be used to store any type of object.
|
|
526
740
|
* The cache works in two modes: considering the size of the objects or not.
|
|
@@ -581,5 +795,5 @@ declare class LRUCache<T> {
|
|
|
581
795
|
static calculateObjectSize(obj: any): number;
|
|
582
796
|
}
|
|
583
797
|
|
|
584
|
-
export { BrowserTreeNodeComponent, CompactPagerComponent, DEFAULT_PAGED_LIST_STORE_OPTIONS, LRUCache, PagedListStore, PagedTreeStore, RangeViewComponent };
|
|
585
|
-
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 };
|