|
| 1 | +@namespace PrompterOne.Shared.Components.Editor |
| 2 | + |
| 3 | +<div class="editor-rendered-view" data-test="@UiTestIds.Editor.RenderedView"> |
| 4 | + <div class="editor-rendered-strip" data-test="@UiTestIds.Editor.RenderedStrip"> |
| 5 | + @if (Segments.Count == 0) |
| 6 | + { |
| 7 | + <section class="editor-rendered-card editor-rendered-card--empty" data-test="@UiTestIds.Editor.RenderedEmpty"> |
| 8 | + <span class="editor-rendered-empty-mark">1</span> |
| 9 | + <textarea class="editor-rendered-text editor-rendered-text--empty" |
| 10 | + aria-label="@FallbackLabel" |
| 11 | + data-test="@UiTestIds.Editor.RenderedFallbackText" |
| 12 | + value="@FallbackText" |
| 13 | + @oninput="OnFallbackInputAsync"></textarea> |
| 14 | + </section> |
| 15 | + } |
| 16 | + else |
| 17 | + { |
| 18 | + @foreach (var segment in Segments) |
| 19 | + { |
| 20 | + <section class="editor-rendered-card" data-test="@UiTestIds.Editor.RenderedSegment(segment.Index)"> |
| 21 | + <header class="editor-rendered-card-header"> |
| 22 | + <span class="editor-rendered-number">@segment.Number</span> |
| 23 | + <span class="editor-rendered-meta">@segment.TargetWpmLabel</span> |
| 24 | + </header> |
| 25 | + <div class="editor-rendered-segment-title">@segment.Name</div> |
| 26 | + <div class="editor-rendered-segment-detail"> |
| 27 | + <span>@segment.EmotionLabel</span> |
| 28 | + @if (!string.IsNullOrWhiteSpace(segment.DurationLabel)) |
| 29 | + { |
| 30 | + <span>@segment.DurationLabel</span> |
| 31 | + } |
| 32 | + </div> |
| 33 | + |
| 34 | + @foreach (var block in segment.Blocks) |
| 35 | + { |
| 36 | + <article class="editor-rendered-block" data-test="@UiTestIds.Editor.RenderedBlock(block.SegmentIndex, block.BlockIndex)"> |
| 37 | + <div class="editor-rendered-block-head"> |
| 38 | + <span class="editor-rendered-block-number">@block.Number</span> |
| 39 | + <span class="editor-rendered-block-title">@block.Name</span> |
| 40 | + </div> |
| 41 | + <textarea class="editor-rendered-text" |
| 42 | + aria-label="@block.Name" |
| 43 | + data-test="@UiTestIds.Editor.RenderedBlockText(block.SegmentIndex, block.BlockIndex)" |
| 44 | + value="@block.Text" |
| 45 | + @oninput="@((ChangeEventArgs args) => OnBlockInputAsync(block, args))"></textarea> |
| 46 | + <div class="editor-rendered-block-meta"> |
| 47 | + @if (!string.IsNullOrWhiteSpace(block.EmotionLabel)) |
| 48 | + { |
| 49 | + <span>@block.EmotionLabel</span> |
| 50 | + } |
| 51 | + <span>@block.TargetWpmLabel</span> |
| 52 | + </div> |
| 53 | + </article> |
| 54 | + } |
| 55 | + </section> |
| 56 | + } |
| 57 | + } |
| 58 | + </div> |
| 59 | +</div> |
| 60 | + |
| 61 | +@code { |
| 62 | + [Parameter] public string FallbackText { get; set; } = string.Empty; |
| 63 | + |
| 64 | + [Parameter] public string FallbackLabel { get; set; } = string.Empty; |
| 65 | + |
| 66 | + [Parameter] public IReadOnlyList<EditorRenderedSegmentViewModel> Segments { get; set; } = []; |
| 67 | + |
| 68 | + [Parameter] public EventCallback<EditorRenderedBlockTextChange> TextChanged { get; set; } |
| 69 | + |
| 70 | + private Task OnBlockInputAsync(EditorRenderedBlockViewModel block, ChangeEventArgs args) => |
| 71 | + TextChanged.InvokeAsync(new EditorRenderedBlockTextChange( |
| 72 | + block.SegmentIndex, |
| 73 | + block.BlockIndex, |
| 74 | + args.Value?.ToString() ?? string.Empty)); |
| 75 | + |
| 76 | + private Task OnFallbackInputAsync(ChangeEventArgs args) => |
| 77 | + TextChanged.InvokeAsync(new EditorRenderedBlockTextChange( |
| 78 | + 0, |
| 79 | + 0, |
| 80 | + args.Value?.ToString() ?? string.Empty)); |
| 81 | +} |
0 commit comments