refactor: group replace pairs in script diffs

This commit is contained in:
Ahmed Darrazi 2026-01-01 21:38:15 +01:00
parent f165bd059e
commit a6b1a8913b

View File

@ -253,26 +253,52 @@
<div class="text-sm font-medium text-gray-900 dark:text-white"> <div class="text-sm font-medium text-gray-900 dark:text-white">
{{ (string) $name }} {{ (string) $name }}
</div> </div>
<div class="text-sm text-gray-600 dark:text-gray-300">
<span class="text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400">From</span> @if ($isScriptContent)
@if ($isScriptContent || $isExpandable($from)) <div class="text-sm text-gray-600 dark:text-gray-300 sm:col-span-2">
<span class="text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400">Diff</span>
<details class="mt-1"> <details class="mt-1">
<summary class="cursor-pointer text-sm text-gray-700 dark:text-gray-200"> <summary class="cursor-pointer text-sm text-gray-700 dark:text-gray-200">
View View
</summary> </summary>
@if ($isScriptContent)
<pre class="mt-2 overflow-x-auto text-xs text-gray-800 dark:text-gray-200 whitespace-pre"> <div class="mt-2 overflow-x-auto font-mono text-xs text-gray-800 dark:text-gray-200 whitespace-pre">
@foreach ($ops as $op) @php
$count = count($ops);
@endphp
@for ($i = 0; $i < $count; $i++)
@php
$op = $ops[$i];
$next = $ops[$i + 1] ?? null;
@endphp
@if ($op['type'] === 'equal') @if ($op['type'] === 'equal')
{{ $op['line'] }} {{ $op['line'] }}
@elseif ($op['type'] === 'delete' && is_array($next) && ($next['type'] ?? null) === 'insert')
<span class="block bg-danger-50 text-danger-700 dark:bg-danger-950/40 dark:text-danger-200">- {{ $op['line'] }}</span>
<span class="block bg-success-50 text-success-700 dark:bg-success-950/40 dark:text-success-200">+ {{ $next['line'] }}</span>
@php
$i++;
@endphp
@elseif ($op['type'] === 'delete') @elseif ($op['type'] === 'delete')
<span class="block bg-danger-50 text-danger-700 dark:bg-danger-950/40 dark:text-danger-200">- {{ $op['line'] }}</span> <span class="block bg-danger-50 text-danger-700 dark:bg-danger-950/40 dark:text-danger-200">- {{ $op['line'] }}</span>
@elseif ($op['type'] === 'insert')
<span class="block bg-success-50 text-success-700 dark:bg-success-950/40 dark:text-success-200">+ {{ $op['line'] }}</span>
@endif @endif
@endforeach @endfor
</pre> </div>
</details>
</div>
@else @else
<div class="text-sm text-gray-600 dark:text-gray-300">
<span class="text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400">From</span>
@if ($isExpandable($from))
<details class="mt-1">
<summary class="cursor-pointer text-sm text-gray-700 dark:text-gray-200">
View
</summary>
<pre class="mt-2 overflow-x-auto text-xs text-gray-800 dark:text-gray-200">{{ $fromText }}</pre> <pre class="mt-2 overflow-x-auto text-xs text-gray-800 dark:text-gray-200">{{ $fromText }}</pre>
@endif
</details> </details>
@else @else
<div class="mt-1">{{ $fromText }}</div> <div class="mt-1">{{ $fromText }}</div>
@ -280,29 +306,18 @@
</div> </div>
<div class="text-sm text-gray-600 dark:text-gray-300"> <div class="text-sm text-gray-600 dark:text-gray-300">
<span class="text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400">To</span> <span class="text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400">To</span>
@if ($isScriptContent || $isExpandable($to)) @if ($isExpandable($to))
<details class="mt-1"> <details class="mt-1">
<summary class="cursor-pointer text-sm text-gray-700 dark:text-gray-200"> <summary class="cursor-pointer text-sm text-gray-700 dark:text-gray-200">
View View
</summary> </summary>
@if ($isScriptContent)
<pre class="mt-2 overflow-x-auto text-xs text-gray-800 dark:text-gray-200 whitespace-pre">
@foreach ($ops as $op)
@if ($op['type'] === 'equal')
{{ $op['line'] }}
@elseif ($op['type'] === 'insert')
<span class="block bg-success-50 text-success-700 dark:bg-success-950/40 dark:text-success-200">+ {{ $op['line'] }}</span>
@endif
@endforeach
</pre>
@else
<pre class="mt-2 overflow-x-auto text-xs text-gray-800 dark:text-gray-200">{{ $toText }}</pre> <pre class="mt-2 overflow-x-auto text-xs text-gray-800 dark:text-gray-200">{{ $toText }}</pre>
@endif
</details> </details>
@else @else
<div class="mt-1">{{ $toText }}</div> <div class="mt-1">{{ $toText }}</div>
@endif @endif
</div> </div>
@endif
</div> </div>
@else @else
@php @php