From 1ca7921aa170e170b7e0cfa3eb71454c23529161 Mon Sep 17 00:00:00 2001 From: Shephard Tseisi Date: Sun, 6 Sep 2026 18:44:52 +0200 Subject: [PATCH 1/4] refactor: simplify component preview and frame interactions - Updated ComponentPreview and PreviewFrame components to streamline the expand/collapse functionality and source/code viewing. - Removed unnecessary state management and JavaScript interop for showing/hiding source and code, replacing it with data attributes for better performance and maintainability. - Enhanced accessibility by ensuring buttons have appropriate aria-labels and visual feedback for copy actions. --- .../Content/ComponentPreview.razor | 70 ++++------------- .../Content/PreviewFrame.razor | 75 ++++--------------- 2 files changed, 29 insertions(+), 116 deletions(-) diff --git a/src/ShellDocs.Components/Content/ComponentPreview.razor b/src/ShellDocs.Components/Content/ComponentPreview.razor index 439510d..e8f74e0 100644 --- a/src/ShellDocs.Components/Content/ComponentPreview.razor +++ b/src/ShellDocs.Components/Content/ComponentPreview.razor @@ -3,9 +3,10 @@ @using System.Text @using ShellDocs.Markdown @inject TypeRegistry Registry -@inject IJSRuntime JS -
+@* Source-view expand/collapse + copy handled by shelldocs.js — same JS + delegation that PreviewFrame uses. Works on static-prerender deploys. *@ + @@ -57,10 +46,6 @@ private Type? _target; private IDictionary? _targetParams; private string? _source; - private bool _showSource; - private bool _copied; - private bool _highlighted; - private ElementReference _sourceEl; protected override void OnParametersSet() { @@ -108,31 +93,4 @@ } return sb.ToString(); } - - private void Show() => _showSource = true; - private void Hide() => _showSource = false; - - protected override async Task OnAfterRenderAsync(bool firstRender) - { - if (firstRender && !_highlighted && _source is not null) - { - _highlighted = true; - try { await JS.InvokeVoidAsync("shelldocsHighlightElement", _sourceEl); } catch { } - } - } - - private async Task Copy() - { - if (_source is null) return; - try - { - await JS.InvokeVoidAsync("navigator.clipboard.writeText", _source); - _copied = true; - StateHasChanged(); - await Task.Delay(1400); - _copied = false; - StateHasChanged(); - } - catch { } - } } diff --git a/src/ShellDocs.Components/Content/PreviewFrame.razor b/src/ShellDocs.Components/Content/PreviewFrame.razor index 201fd5d..936ca5c 100644 --- a/src/ShellDocs.Components/Content/PreviewFrame.razor +++ b/src/ShellDocs.Components/Content/PreviewFrame.razor @@ -2,7 +2,10 @@ @attribute [ShellDocsIgnore] @inject MarkdownRenderer Renderer -
+@* Expand/collapse of the source region is handled by shelldocs.js — delegated + click on [data-preview-toggle] toggles the expanded/collapsed class on the + ancestor .preview-frame. Works without a live Blazor runtime. *@ +