|
3 | 3 | :field="$field" |
4 | 4 |
|
5 | 5 | > |
6 | | - @php |
7 | | - ray($getStatePath()) |
8 | | - @endphp |
9 | 6 | <div |
10 | 7 | x-data="{ state: $wire.{{ $applyStateBindingModifiers("\$entangle('{$getStatePath()}')") }} }" |
11 | 8 | style="position: relative; border-radius: 0.375rem;" |
|
14 | 11 | <div |
15 | 12 | wire:ignore |
16 | 13 | x-init=" |
17 | | - codeMirrorEditor = CodeMirror($refs.input, { |
| 14 | + {{ str_replace('.', '', $getId()) }} = CodeMirror($refs.{{ str_replace('.', '', $getId()) }}, { |
18 | 15 | mode: 'application/json', |
19 | 16 | lineNumbers: {{ json_encode($getHasLineNumbers()) }}, |
20 | 17 | lineWrapping: {{ json_encode($getHasLineWrapping()) }}, |
|
57 | 54 | } |
58 | 55 | }); |
59 | 56 |
|
60 | | - codeMirrorEditor.setSize('100%', '100%'); |
61 | | - codeMirrorEditor.setValue(state ?? '{}'); |
| 57 | + {{ str_replace('.', '', $getId()) }}.setSize('100%', '100%'); |
| 58 | + {{ str_replace('.', '', $getId()) }}.setValue({{ json_encode(json_encode($getState(), JSON_PRETTY_PRINT), JSON_UNESCAPED_SLASHES) }} ?? '{}'); |
62 | 59 |
|
63 | 60 | setTimeout(function() { |
64 | | - codeMirrorEditor.refresh(); |
| 61 | + {{ str_replace('.', '', $getId()) }}.refresh(); |
65 | 62 | }, 1); |
66 | 63 |
|
67 | | - codeMirrorEditor.on('change', () => state = codeMirrorEditor.getValue()) |
| 64 | + {{ str_replace('.', '', $getId()) }}.on('change', function () { |
| 65 | + try { |
| 66 | + state = JSON.parse({{ str_replace('.', '', $getId()) }}.getValue()) |
| 67 | + } catch (e) { |
| 68 | + state = {{ str_replace('.', '', $getId()) }}.getValue(); |
| 69 | + } |
| 70 | + }); |
68 | 71 | " |
69 | 72 | > |
70 | 73 | <div |
71 | 74 | wire:ignore |
72 | | - x-ref="input" |
| 75 | + x-ref="{{ str_replace('.', '', $getId()) }}" |
73 | 76 | ></div> |
74 | 77 | </div> |
75 | 78 | </div> |
|
0 commit comments