@php $diff = $getState() ?? ['summary' => [], 'added' => [], 'removed' => [], 'changed' => []]; $summary = $diff['summary'] ?? []; $policyType = $diff['policy_type'] ?? null; $groupByBlock = static function (array $items): array { $groups = []; foreach ($items as $path => $value) { if (! is_string($path) || $path === '') { continue; } $parts = explode(' > ', $path, 2); if (count($parts) === 2) { [$group, $label] = $parts; } else { $group = 'Other'; $label = $path; } $groups[$group][$label] = $value; } ksort($groups); return $groups; }; $stringify = static function (mixed $value): string { if ($value === null) { return '—'; } if (is_bool($value)) { return $value ? 'Enabled' : 'Disabled'; } if (is_scalar($value)) { return (string) $value; } return json_encode($value, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) ?: ''; }; $isExpandable = static function (mixed $value): bool { if (is_array($value)) { return true; } return is_string($value) && strlen($value) > 160; }; $isScriptKey = static function (mixed $name): bool { return in_array((string) $name, ['scriptContent', 'detectionScriptContent', 'remediationScriptContent'], true); }; $canHighlightScripts = static function (?string $policyType): bool { return (bool) config('tenantpilot.display.show_script_content', false) && in_array($policyType, ['deviceManagementScript', 'deviceShellScript', 'deviceHealthScript'], true); }; $selectGrammar = static function (?string $policyType, string $code): string { if ($policyType === 'deviceShellScript') { $firstLine = strtok($code, "\n") ?: ''; $shebang = trim($firstLine); if (str_starts_with($shebang, '#!')) { if (str_contains($shebang, 'zsh')) { return 'zsh'; } if (str_contains($shebang, 'bash')) { return 'bash'; } return 'sh'; } return 'sh'; } return 'powershell'; }; $highlight = static function (?string $policyType, string $code, string $fallbackClass = '') use ($selectGrammar): ?string { if (! class_exists(\Torchlight\Engine\Engine::class)) { return null; } try { return (new \Torchlight\Engine\Engine())->codeToHtml( code: $code, grammar: $selectGrammar($policyType, $code), theme: [ 'light' => 'github-light', 'dark' => 'github-dark', ], withGutter: false, withWrapper: true, ); } catch (\Throwable $e) { return null; } }; $splitLines = static function (string $text): array { $text = str_replace(["\r\n", "\r"], "\n", $text); return $text === '' ? [] : explode("\n", $text); }; $myersLineDiff = static function (array $a, array $b): array { $n = count($a); $m = count($b); $max = $n + $m; $v = [1 => 0]; $trace = []; for ($d = 0; $d <= $max; $d++) { $trace[$d] = $v; for ($k = -$d; $k <= $d; $k += 2) { $kPlus = $v[$k + 1] ?? 0; $kMinus = $v[$k - 1] ?? 0; if ($k === -$d || ($k !== $d && $kMinus < $kPlus)) { $x = $kPlus; } else { $x = $kMinus + 1; } $y = $x - $k; while ($x < $n && $y < $m && $a[$x] === $b[$y]) { $x++; $y++; } $v[$k] = $x; if ($x >= $n && $y >= $m) { break 2; } } } $ops = []; $x = $n; $y = $m; for ($d = count($trace) - 1; $d >= 0; $d--) { $v = $trace[$d]; $k = $x - $y; $kPlus = $v[$k + 1] ?? 0; $kMinus = $v[$k - 1] ?? 0; if ($k === -$d || ($k !== $d && $kMinus < $kPlus)) { $prevK = $k + 1; } else { $prevK = $k - 1; } $prevX = $v[$prevK] ?? 0; $prevY = $prevX - $prevK; while ($x > $prevX && $y > $prevY) { $ops[] = ['type' => 'equal', 'line' => $a[$x - 1]]; $x--; $y--; } if ($d === 0) { break; } if ($x === $prevX) { $ops[] = ['type' => 'insert', 'line' => $b[$y - 1] ?? '']; $y--; } else { $ops[] = ['type' => 'delete', 'line' => $a[$x - 1] ?? '']; $x--; } } return array_reverse($ops); }; $scriptLineDiff = static function (string $fromText, string $toText) use ($splitLines, $myersLineDiff): array { return $myersLineDiff($splitLines($fromText), $splitLines($toText)); }; @endphp
@php
foreach ($rows as $row) {
$left = $row['left'];
$leftType = $left['type'];
$leftLine = (string) ($left['line'] ?? '');
if ($leftType === 'equal') {
echo e($leftLine)."\n";
continue;
}
if ($leftType === 'delete') {
echo '- '.e($leftLine)."\n";
continue;
}
echo "\n";
}
@endphp
@php
foreach ($rows as $row) {
$right = $row['right'];
$rightType = $right['type'];
$rightLine = (string) ($right['line'] ?? '');
if ($rightType === 'equal') {
echo e($rightLine)."\n";
continue;
}
if ($rightType === 'insert') {
echo '+ '.e($rightLine)."\n";
continue;
}
echo "\n";
}
@endphp
{{ (string) $fromText }}
{{ (string) $toText }}
{{ $fromText }}
{{ $toText }}
{{ $text }}
@endif