diff --git a/resources/views/filament/infolists/entries/normalized-diff.blade.php b/resources/views/filament/infolists/entries/normalized-diff.blade.php index 80f8361..a8d45a8 100644 --- a/resources/views/filament/infolists/entries/normalized-diff.blade.php +++ b/resources/views/filament/infolists/entries/normalized-diff.blade.php @@ -282,6 +282,51 @@ $isScriptContent = $canHighlightScripts($policyType) && $isScriptKey($name); $ops = $isScriptContent ? $scriptLineDiff((string) $fromText, (string) $toText) : []; $useTorchlight = $isScriptContent && class_exists(\Torchlight\Engine\Engine::class); + + $rows = []; + if ($isScriptContent) { + $count = count($ops); + + for ($i = 0; $i < $count; $i++) { + $op = $ops[$i]; + $next = $ops[$i + 1] ?? null; + $type = $op['type'] ?? null; + $line = (string) ($op['line'] ?? ''); + + if ($type === 'equal') { + $rows[] = [ + 'left' => ['type' => 'equal', 'line' => $line], + 'right' => ['type' => 'equal', 'line' => $line], + ]; + continue; + } + + if ($type === 'delete' && is_array($next) && ($next['type'] ?? null) === 'insert') { + $rows[] = [ + 'left' => ['type' => 'delete', 'line' => $line], + 'right' => ['type' => 'insert', 'line' => (string) ($next['line'] ?? '')], + ]; + $i++; + continue; + } + + if ($type === 'delete') { + $rows[] = [ + 'left' => ['type' => 'delete', 'line' => $line], + 'right' => ['type' => 'blank', 'line' => ''], + ]; + continue; + } + + if ($type === 'insert') { + $rows[] = [ + 'left' => ['type' => 'blank', 'line' => ''], + 'right' => ['type' => 'insert', 'line' => $line], + ]; + continue; + } + } + } @endphp
@php
+foreach ($rows as $row) {
+ $left = $row['left'];
+ $leftType = $left['type'];
+ $leftLine = (string) ($left['line'] ?? '');
+
+ $leftHighlighted = $useTorchlight ? $highlightInline($policyType, $leftLine) : null;
+ $leftRendered = (is_string($leftHighlighted) && $leftHighlighted !== '') ? $leftHighlighted : e($leftLine);
+
+ if ($leftType === 'equal') {
+ if ($useTorchlight) {
+ @endphp
+ @once
+ @include('filament.partials.torchlight-dark-overrides')
+ @endonce
+ @php
+ }
+
+ echo $leftRendered."\n";
+ continue;
+ }
+
+ if ($leftType === 'delete') {
+ if ($useTorchlight) {
+ @endphp
+ @once
+ @include('filament.partials.torchlight-dark-overrides')
+ @endonce
+ @php
+ }
+
+ echo '- '.$leftRendered."\n";
+ continue;
+ }
+
+ echo "\n";
+}
+@endphp
+ @php
+foreach ($rows as $row) {
+ $right = $row['right'];
+ $rightType = $right['type'];
+ $rightLine = (string) ($right['line'] ?? '');
+
+ $rightHighlighted = $useTorchlight ? $highlightInline($policyType, $rightLine) : null;
+ $rightRendered = (is_string($rightHighlighted) && $rightHighlighted !== '') ? $rightHighlighted : e($rightLine);
+
+ if ($rightType === 'equal') {
+ if ($useTorchlight) {
+ @endphp
+ @once
+ @include('filament.partials.torchlight-dark-overrides')
+ @endonce
+ @php
+ }
+
+ echo $rightRendered."\n";
+ continue;
+ }
+
+ if ($rightType === 'insert') {
+ if ($useTorchlight) {
+ @endphp
+ @once
+ @include('filament.partials.torchlight-dark-overrides')
+ @endonce
+ @php
+ }
+
+ echo '+ '.$rightRendered."\n";
+ continue;
+ }
+
+ echo "\n";
+}
+@endphp
+ {{ (string) $fromText }}
+ @endif
+ {{ (string) $toText }}
+ @endif
+