| | | 1 | | using Chronicis.Shared.DTOs; |
| | | 2 | | |
| | | 3 | | namespace Chronicis.Client.Services; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Service for managing wiki link autocomplete state and operations |
| | | 7 | | /// </summary> |
| | | 8 | | public interface IWikiLinkAutocompleteService |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// Event raised when autocomplete should be shown |
| | | 12 | | /// </summary> |
| | | 13 | | event Action? OnShow; |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// Event raised when autocomplete should be hidden |
| | | 17 | | /// </summary> |
| | | 18 | | event Action? OnHide; |
| | | 19 | | |
| | | 20 | | /// <summary> |
| | | 21 | | /// Event raised when suggestions have been updated |
| | | 22 | | /// </summary> |
| | | 23 | | event Action? OnSuggestionsUpdated; |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// Current autocomplete position (x, y) |
| | | 27 | | /// </summary> |
| | | 28 | | (double X, double Y) Position { get; } |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Whether autocomplete is currently visible |
| | | 32 | | /// </summary> |
| | | 33 | | bool IsVisible { get; } |
| | | 34 | | |
| | | 35 | | /// <summary> |
| | | 36 | | /// Current search query |
| | | 37 | | /// </summary> |
| | | 38 | | string Query { get; } |
| | | 39 | | |
| | | 40 | | /// <summary> |
| | | 41 | | /// Whether this is an external resource query (e.g., srd/...) |
| | | 42 | | /// </summary> |
| | | 43 | | bool IsExternalQuery { get; } |
| | | 44 | | |
| | | 45 | | /// <summary> |
| | | 46 | | /// External source key (e.g., "srd") |
| | | 47 | | /// </summary> |
| | | 48 | | string? ExternalSourceKey { get; } |
| | | 49 | | |
| | | 50 | | /// <summary> |
| | | 51 | | /// Current autocomplete suggestions |
| | | 52 | | /// </summary> |
| | | 53 | | List<WikiLinkAutocompleteItem> Suggestions { get; } |
| | | 54 | | |
| | | 55 | | /// <summary> |
| | | 56 | | /// Currently selected suggestion index |
| | | 57 | | /// </summary> |
| | | 58 | | int SelectedIndex { get; } |
| | | 59 | | |
| | | 60 | | /// <summary> |
| | | 61 | | /// Whether suggestions are currently loading |
| | | 62 | | /// </summary> |
| | | 63 | | bool IsLoading { get; } |
| | | 64 | | |
| | | 65 | | /// <summary> |
| | | 66 | | /// Show autocomplete at the specified position with the given query |
| | | 67 | | /// </summary> |
| | | 68 | | Task ShowAsync(string query, double x, double y, Guid? worldId); |
| | | 69 | | |
| | | 70 | | /// <summary> |
| | | 71 | | /// Hide the autocomplete |
| | | 72 | | /// </summary> |
| | | 73 | | void Hide(); |
| | | 74 | | |
| | | 75 | | /// <summary> |
| | | 76 | | /// Move selection down |
| | | 77 | | /// </summary> |
| | | 78 | | void SelectNext(); |
| | | 79 | | |
| | | 80 | | /// <summary> |
| | | 81 | | /// Move selection up |
| | | 82 | | /// </summary> |
| | | 83 | | void SelectPrevious(); |
| | | 84 | | |
| | | 85 | | /// <summary> |
| | | 86 | | /// Set the selected index directly |
| | | 87 | | /// </summary> |
| | | 88 | | void SetSelectedIndex(int index); |
| | | 89 | | |
| | | 90 | | /// <summary> |
| | | 91 | | /// Get the currently selected suggestion |
| | | 92 | | /// </summary> |
| | | 93 | | WikiLinkAutocompleteItem? GetSelectedSuggestion(); |
| | | 94 | | } |
| | | 95 | | |
| | | 96 | | /// <summary> |
| | | 97 | | /// Autocomplete item representing either an internal article or external resource |
| | | 98 | | /// </summary> |
| | | 99 | | public class WikiLinkAutocompleteItem |
| | | 100 | | { |
| | 0 | 101 | | public string DisplayText { get; set; } = string.Empty; |
| | 0 | 102 | | public string? ArticleId { get; set; } |
| | 0 | 103 | | public string? ExternalKey { get; set; } |
| | 0 | 104 | | public string? Tooltip { get; set; } |
| | 0 | 105 | | public bool IsExternal { get; set; } |
| | 0 | 106 | | public bool IsCategory { get; set; } |
| | | 107 | | |
| | | 108 | | public static WikiLinkAutocompleteItem FromInternal(LinkSuggestionDto suggestion) |
| | | 109 | | { |
| | 0 | 110 | | return new WikiLinkAutocompleteItem |
| | 0 | 111 | | { |
| | 0 | 112 | | DisplayText = suggestion.Title, |
| | 0 | 113 | | ArticleId = suggestion.ArticleId.ToString(), |
| | 0 | 114 | | Tooltip = suggestion.DisplayPath, |
| | 0 | 115 | | IsExternal = false, |
| | 0 | 116 | | IsCategory = false |
| | 0 | 117 | | }; |
| | | 118 | | } |
| | | 119 | | |
| | | 120 | | public static WikiLinkAutocompleteItem FromExternal(ExternalLinkSuggestionDto suggestion) |
| | | 121 | | { |
| | 0 | 122 | | return new WikiLinkAutocompleteItem |
| | 0 | 123 | | { |
| | 0 | 124 | | DisplayText = suggestion.Title, |
| | 0 | 125 | | ExternalKey = suggestion.Id, |
| | 0 | 126 | | Tooltip = suggestion.Source, |
| | 0 | 127 | | IsExternal = true, |
| | 0 | 128 | | IsCategory = !string.IsNullOrEmpty(suggestion.Category) |
| | 0 | 129 | | }; |
| | | 130 | | } |
| | | 131 | | } |