ktsu.Navigation.Core 1.0.7-pre.3

ktsu.Navigation

A robust .NET library for implementing navigation stacks with undo/redo support and persistence capabilities.

Overview

ktsu.Navigation provides a complete navigation stack implementation that supports:

  • Forward/Backward Navigation: Navigate through items with full browser-like back/forward functionality
  • Undo/Redo Operations: Complete undo/redo support for all navigation actions
  • Persistence: Save and restore navigation state to various storage backends
  • Event-Driven Architecture: React to navigation changes with comprehensive event notifications
  • Generic Design: Works with any navigation item type implementing INavigationItem
  • Factory Pattern: Easy creation of navigation stacks with different configurations

Perfect for applications that need robust navigation management, such as:

  • Code editors with file navigation
  • Image viewers with browsing history
  • Document management systems
  • Any application requiring navigation state management

Features

Core Navigation

  • ✅ NavigateTo, GoBack, GoForward operations
  • ✅ Current item tracking with CanGoBack/CanGoForward status
  • ✅ Complete navigation history management
  • ✅ Forward history clearing when navigating to new items
  • ✅ Thread-safe operations

Undo/Redo System

  • ✅ Full undo/redo support for navigation operations
  • ✅ Configurable history size limits
  • ✅ State change notifications
  • ✅ Error handling during undo/redo operations

Persistence

  • ✅ JSON file persistence provider
  • ✅ In-memory persistence for testing
  • ✅ Async operations with cancellation token support
  • ✅ Custom persistence provider support

Events & Extensibility

  • ✅ Navigation change events (NavigateTo, GoBack, GoForward, Clear)
  • ✅ Metadata support for navigation items
  • ✅ Generic design for custom navigation item types
  • ✅ Factory pattern for easy configuration

Installation

Add the NuGet package:

dotnet add package ktsu.Navigation

Quick Start

Basic Navigation

using ktsu.Navigation.Core.Models;
using ktsu.Navigation.Core.Services;

// Create navigation items
var page1 = new NavigationItem("page1", "Home Page");
var page2 = new NavigationItem("page2", "About Page");
var page3 = new NavigationItem("page3", "Contact Page");

// Create a basic navigation stack
var navigation = new Navigation<NavigationItem>();

// Navigate through items
navigation.NavigateTo(page1);  // Current: Home Page
navigation.NavigateTo(page2);  // Current: About Page
navigation.NavigateTo(page3);  // Current: Contact Page

// Go back and forward
var previous = navigation.GoBack();    // Current: About Page
var next = navigation.GoForward();     // Current: Contact Page

// Check navigation state
Console.WriteLine($"Current: {navigation.Current?.DisplayName}");
Console.WriteLine($"Can go back: {navigation.CanGoBack}");
Console.WriteLine($"Can go forward: {navigation.CanGoForward}");

With Undo/Redo Support

using ktsu.Navigation.Core.Services;

// Create navigation with undo/redo support
var undoRedoProvider = new SimpleUndoRedoProvider(maxHistorySize: 50);
var navigation = new Navigation<NavigationItem>(undoRedoProvider);

navigation.NavigateTo(page1);
navigation.NavigateTo(page2);

// Undo the last navigation
undoRedoProvider.Undo();  // Back to page1

// Redo the navigation
undoRedoProvider.Redo();  // Forward to page2 again

With Persistence

using ktsu.Navigation.Core.Services;

// Create navigation with JSON file persistence
var persistenceProvider = new JsonFilePersistenceProvider<NavigationItem>("navigation-state.json");
var navigation = new Navigation<NavigationItem>(persistenceProvider: persistenceProvider);

navigation.NavigateTo(page1);
navigation.NavigateTo(page2);

// Save navigation state
await navigation.SaveStateAsync();

// Later... restore navigation state
await navigation.LoadStateAsync();
Console.WriteLine($"Restored to: {navigation.Current?.DisplayName}");

Complete Example with All Features

using ktsu.Navigation.Core.Services;

// Create providers
var undoRedoProvider = new SimpleUndoRedoProvider();
var persistenceProvider = new JsonFilePersistenceProvider<NavigationItem>("app-navigation.json");

// Create navigation stack with all features
var navigation = new Navigation<NavigationItem>(undoRedoProvider, persistenceProvider);

// Subscribe to navigation events
navigation.NavigationChanged += (sender, e) =>
{
    Console.WriteLine($"Navigation: {e.NavigationType}");
    Console.WriteLine($"From: {e.PreviousItem?.DisplayName ?? "None"}");
    Console.WriteLine($"To: {e.CurrentItem?.DisplayName ?? "None"}");
};

// Use factory for easier creation
var factory = new NavigationStackFactory(undoRedoProvider);
var anotherNavigation = factory.CreateNavigationStack<NavigationItem>(persistenceProvider);

Custom Navigation Items

public class DocumentNavigationItem : INavigationItem
{
    public string Id { get; }
    public string DisplayName { get; set; }
    public DateTime CreatedAt { get; }
    public IReadOnlyDictionary<string, object> Metadata => _metadata.AsReadOnly();
    
    private readonly Dictionary<string, object> _metadata = new();
    
    public DocumentNavigationItem(string filePath, string displayName)
    {
        Id = filePath;
        DisplayName = displayName;
        CreatedAt = DateTime.UtcNow;
        SetMetadata("FilePath", filePath);
        SetMetadata("FileSize", new FileInfo(filePath).Length);
    }
    
    public void SetMetadata(string key, object value) => _metadata[key] = value;
    public bool RemoveMetadata(string key) => _metadata.Remove(key);
}

// Use with navigation
var navigation = new Navigation<DocumentNavigationItem>();
var document = new DocumentNavigationItem("/path/to/file.txt", "My Document");
navigation.NavigateTo(document);

Architecture

The library follows clean architecture principles with well-separated concerns:

  • Models: NavigationItem, NavigationState - Core data structures
  • Contracts: Interfaces defining the contracts for all components
  • Services: Implementation classes for navigation, persistence, and undo/redo

Key Interfaces

  • INavigation<T>: Main navigation stack operations
  • INavigationItem: Contract for items that can be navigated to
  • IPersistenceProvider<T>: Contract for persistence implementations
  • IUndoRedoProvider: Contract for undo/redo implementations

Extension Points

Create custom persistence providers:

public class DatabasePersistenceProvider<T> : IPersistenceProvider<T> where T : INavigationItem
{
    public async Task SaveStateAsync(INavigationState<T> state, CancellationToken cancellationToken = default)
    {
        // Save to database
    }
    
    public async Task<INavigationState<T>?> LoadStateAsync(CancellationToken cancellationToken = default)
    {
        // Load from database
        return null;
    }
    
    // Implement other interface methods...
}

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License. Copyright (c) ktsu.dev

No packages depend on ktsu.Navigation.Core.

## v1.0.7-pre.3 (prerelease) Changes since v1.0.7-pre.2: - Merge remote-tracking branch 'refs/remotes/origin/main' ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync scripts\update-winget-manifests.ps1 ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.0.7-pre.2 (prerelease) Changes since v1.0.7-pre.1: - Sync scripts\update-winget-manifests.ps1 ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync global.json ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync scripts\PSBuild.psm1 ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.0.7-pre.1 (prerelease) Changes since v1.0.6: - Sync global.json ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync scripts\PSBuild.psm1 ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync scripts\PSBuild.psm1 ([@ktsu[bot]](https://github.com/ktsu[bot])) - Merge remote-tracking branch 'refs/remotes/origin/main' ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.0.6 (patch) Changes since v1.0.5: - Refactor interfaces to enforce class constraints and update package references ([@matt-edmondson](https://github.com/matt-edmondson)) - Remove .github\workflows\project.yml ([@matt-edmondson](https://github.com/matt-edmondson)) ## v1.0.6-pre.4 (prerelease) Changes since v1.0.6-pre.3: - Sync scripts\update-winget-manifests.ps1 ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.0.6-pre.3 (prerelease) Changes since v1.0.6-pre.2: - Sync .github\workflows\dotnet.yml ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.0.6-pre.2 (prerelease) Changes since v1.0.6-pre.1: - Sync scripts\PSBuild.psm1 ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync .github\workflows\dotnet.yml ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.0.6-pre.1 (prerelease) Incremental prerelease update. ## v1.0.5 (patch) Changes since v1.0.4: - Update project configuration and dependencies ([@matt-edmondson](https://github.com/matt-edmondson)) ## v1.0.4 (patch) Changes since v1.0.3: - Enhance project documentation and metadata ([@matt-edmondson](https://github.com/matt-edmondson)) - Fix using directive placement in NavigationStackTests.cs for consistency with coding standards ([@matt-edmondson](https://github.com/matt-edmondson)) ## v1.0.3 (patch) Changes since v1.0.2: - Update project configuration and dependencies ([@matt-edmondson](https://github.com/matt-edmondson)) ## v1.0.2 (patch) Changes since v1.0.1: - Refactor navigation-related classes for clarity and performance ([@matt-edmondson](https://github.com/matt-edmondson)) ## v1.0.1 (patch) Changes since v1.0.0: - Refactor navigation services and contracts to enhance code quality. Updated accessibility modifiers to public for several members, moved using directives inside namespace declarations, and renamed NavigationStack to Navigation for consistency. Improved structure in InMemoryPersistenceProvider, JsonFilePersistenceProvider, and other service files. ([@matt-edmondson](https://github.com/matt-edmondson)) - Refactor navigation interfaces and models to improve code quality and adhere to coding standards. Updated INavigationStack to INavigation, modified event handlers to use EventHandler<T> pattern, and ensured public accessibility modifiers are applied. Moved using directives inside namespace declarations to comply with IDE0065 rules across multiple files. ([@matt-edmondson](https://github.com/matt-edmondson)) - Refactor NavigationStackTests to use INavigation interface instead of INavigationStack. Updated test methods to reflect changes in navigation service implementation, ensuring consistency and improved readability. ([@matt-edmondson](https://github.com/matt-edmondson)) ## v1.0.0 (major) - Initial commit for Navigation ([@matt-edmondson](https://github.com/matt-edmondson)) - Enhance coding standards in derived cursor rules and add testing discussion documentation. Updated derived cursor rules to enforce namespace usage for using directives, require explicit accessibility modifiers, and adhere to .NET naming conventions. Included common build error guidelines to improve code quality and maintainability. ([@matt-edmondson](https://github.com/matt-edmondson)) - Add Directory.Packages.props and global.json for centralized package management and SDK configuration. Update Navigation.Core project to handle nullability with default(T?) in NavigationStack. Modify .specstory to include derived cursor rules backup and add testing procedures discussion documentation. ([@matt-edmondson](https://github.com/matt-edmondson)) - Add initial implementation of Navigation Stack Library with core features including navigation management, undo/redo support, and persistence. Introduced contracts, models, and services architecture, along with comprehensive documentation and examples. ([@matt-edmondson](https://github.com/matt-edmondson))

.NET 5.0

  • No dependencies.

.NET 6.0

  • No dependencies.

.NET 7.0

  • No dependencies.

.NET 8.0

  • No dependencies.

.NET 9.0

  • No dependencies.

.NET 10.0

  • No dependencies.

.NET Standard 2.0

.NET Standard 2.1

Version Downloads Last updated
1.0.8 15 02/14/2026
1.0.7 15 02/14/2026
1.0.7-pre.3 55 02/06/2026
1.0.7-pre.2 53 02/05/2026
1.0.7-pre.1 54 02/03/2026
1.0.6 54 02/01/2026