Skip to content

Commit fc64bc9

Browse files
committed
WIP
1 parent c145101 commit fc64bc9

File tree

2 files changed

+47
-13
lines changed

2 files changed

+47
-13
lines changed

resources/views/forms/components/json-input.blade.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<div
1212
wire:ignore
1313
x-init="
14-
codeMirrorEditor = CodeMirror($refs.input, {
14+
{{ str_replace('.', '', $getId()) }} = CodeMirror($refs.{{ str_replace('.', '', $getId()) }}, {
1515
mode: 'application/json',
1616
lineNumbers: {{ json_encode($getHasLineNumbers()) }},
1717
lineWrapping: {{ json_encode($getHasLineWrapping()) }},
@@ -54,25 +54,25 @@
5454
}
5555
});
5656
57-
codeMirrorEditor.setSize('100%', '100%');
58-
codeMirrorEditor.setValue({{ json_encode(json_encode($getState(), JSON_PRETTY_PRINT), JSON_UNESCAPED_SLASHES) }} ?? '{}');
57+
{{ str_replace('.', '', $getId()) }}.setSize('100%', '100%');
58+
{{ str_replace('.', '', $getId()) }}.setValue({{ json_encode(json_encode($getState(), JSON_PRETTY_PRINT), JSON_UNESCAPED_SLASHES) }} ?? '{}');
5959
6060
setTimeout(function() {
61-
codeMirrorEditor.refresh();
61+
{{ str_replace('.', '', $getId()) }}.refresh();
6262
}, 1);
6363
64-
codeMirrorEditor.on('change', function () {
64+
{{ str_replace('.', '', $getId()) }}.on('change', function () {
6565
try {
66-
state = JSON.parse(codeMirrorEditor.getValue())
66+
state = JSON.parse({{ str_replace('.', '', $getId()) }}.getValue())
6767
} catch (e) {
68-
state = codeMirrorEditor.getValue();
68+
state = {{ str_replace('.', '', $getId()) }}.getValue();
6969
}
7070
});
7171
"
7272
>
7373
<div
7474
wire:ignore
75-
x-ref="input"
75+
x-ref="{{ str_replace('.', '', $getId()) }}"
7676
></div>
7777
</div>
7878
</div>

resources/views/infolists/components/json-entry.blade.php

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,62 @@
66
<div
77
wire:ignore
88
x-init="
9-
codeMirrorEditor = CodeMirror($refs.input, {
9+
{{ str_replace('.', '', $getId()) }} = CodeMirror($refs.{{ str_replace('.', '', $getId()) }}, {
1010
mode: 'application/json',
1111
readOnly: true,
1212
lineNumbers: {{ json_encode($getHasLineNumbers()) }},
13+
lineWrapping: {{ json_encode($getHasLineWrapping()) }},
14+
autoCloseBrackets: {{ json_encode($getHasAutoCloseBrackets()) }},
15+
lineNumbers: {{ json_encode($getHasLineNumbers()) }},
1316
viewportMargin: Infinity,
1417
theme: '{{ $getHasDarkTheme() ? 'darcula' : 'default' }}',
18+
foldGutter: {{ json_encode($getHasFoldingCode()) }},
19+
@php
20+
if($getHasFoldingCode()) {
21+
echo "extraKeys: {'Ctrl-Q': function(cm) { cm.foldCode(cm.getCursor()); }},";
22+
}
23+
@endphp
1524
gutters: [
1625
{{ json_encode($getHasLineNumbers()) }} ? 'CodeMirror-linenumbers' : '',
26+
{{ json_encode($getHasFoldingCode()) }} ? 'CodeMirror-foldgutter' : '',
1727
],
28+
foldOptions: {
29+
widget: (from, to) => {
30+
var count = undefined;
31+
32+
// Get open / close token
33+
var startToken = '{', endToken = '}';
34+
var prevLine = codeMirrorEditor.getLine(from.line);
35+
if (prevLine.lastIndexOf('[') > prevLine.lastIndexOf('{')) {
36+
startToken = '[', endToken = ']';
37+
}
38+
39+
// Get json content
40+
var internal = codeMirrorEditor.getRange(from, to);
41+
var toParse = startToken + internal + endToken;
42+
43+
// Get key count
44+
try {
45+
var parsed = JSON.parse(toParse);
46+
count = Object.keys(parsed).length;
47+
} catch(e) { }
48+
49+
return count ? `\u21A4${count}\u21A6` : '\u2194';
50+
}
51+
}
1852
});
1953
20-
codeMirrorEditor.setSize(null, '100%');
21-
codeMirrorEditor.setValue({{ json_encode(json_encode($getState(), JSON_PRETTY_PRINT), JSON_UNESCAPED_SLASHES) }} ?? '{}');
54+
{{ str_replace('.', '', $getId()) }}.setSize(null, '100%');
55+
{{ str_replace('.', '', $getId()) }}.setValue({{ json_encode(json_encode($getState(), JSON_PRETTY_PRINT), JSON_UNESCAPED_SLASHES) }} ?? '{}');
2256
2357
setTimeout(function() {
24-
codeMirrorEditor.refresh();
58+
{{ str_replace('.', '', $getId()) }}.refresh();
2559
}, 1);
2660
"
2761
>
2862
<div
2963
wire:ignore
30-
x-ref="input"
64+
x-ref="{{ str_replace('.', '', $getId()) }}"
3165
></div>
3266
</div>
3367
</div>

0 commit comments

Comments
 (0)