generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
117 additions
and
18 deletions.
There are no files selected for viewing
78 changes: 60 additions & 18 deletions
78
resources/views/infolists/components/json-entry.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,67 @@ | ||
<x-dynamic-component :component="$getEntryWrapperView()" :entry="$entry"> | ||
@php | ||
$identification = $getId(); | ||
@endphp | ||
<div | ||
class="relative rounded-md" | ||
x-cloak | ||
> | ||
<div | ||
wire:ignore | ||
x-init=" | ||
codeMirrorEditor = CodeMirror($refs.input, { | ||
mode: 'application/json', | ||
readOnly: true, | ||
lineNumbers: {{ json_encode($getHasLineNumbers()) }}, | ||
autoCloseBrackets: {{ json_encode($getHasAutoCloseBrackets()) }}, | ||
viewportMargin: Infinity, | ||
theme: '{{ $getHasDarkTheme() ? 'darcula' : 'default' }}', | ||
foldGutter: {{ json_encode($getHasFoldingCode()) }}, | ||
@php | ||
if($getHasFoldingCode()) { | ||
echo "extraKeys: {'Ctrl-Q': function(cm) { cm.foldCode(cm.getCursor()); }},"; | ||
} | ||
@endphp | ||
gutters: [ | ||
'CodeMirror-linenumbers', | ||
{{ json_encode($getHasFoldingCode()) }} ? 'CodeMirror-foldgutter' : '' | ||
], | ||
foldOptions: { | ||
widget: (from, to) => { | ||
var count = undefined; | ||
<div id="{{$identification}}" class="w-full"></div> | ||
// Get open / close token | ||
var startToken = '{', endToken = '}'; | ||
var prevLine = codeMirrorEditor.getLine(from.line); | ||
if (prevLine.lastIndexOf('[') > prevLine.lastIndexOf('{')) { | ||
startToken = '[', endToken = ']'; | ||
} | ||
<script> | ||
var jsonData = @json($getState()); | ||
// Get json content | ||
var internal = codeMirrorEditor.getRange(from, to); | ||
var toParse = startToken + internal + endToken; | ||
var editor = CodeMirror(document.getElementById('{{$identification}}'), { | ||
value: JSON.stringify(jsonData, null, 2), | ||
mode: "application/json", // Set mode to JSON | ||
lineNumbers: true, | ||
readOnly: true, | ||
autoCloseBrackets: true, | ||
viewportMargin: Infinity, | ||
theme: 'default', | ||
}); | ||
editor.setSize(null, "100%"); | ||
// Get key count | ||
try { | ||
var parsed = JSON.parse(toParse); | ||
count = Object.keys(parsed).length; | ||
} catch(e) { } | ||
editor.setValue(JSON.stringify(jsonData, null, 2)); | ||
</script> | ||
return count ? `\u21A4${count}\u21A6` : '\u2194'; | ||
} | ||
} | ||
}); | ||
codeMirrorEditor.setSize(null, '100%'); | ||
codeMirrorEditor.setValue({{ json_encode($getState()) }}); | ||
setTimeout(function() { | ||
codeMirrorEditor.refresh(); | ||
}, 1); | ||
" | ||
> | ||
<div | ||
wire:ignore | ||
x-ref="input" | ||
class="w-full" | ||
></div> | ||
</div> | ||
</div> | ||
</x-dynamic-component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters