editor.blade.php
1 <div class="shadow-sm bg-slate-50" x-data="{ 2 @if ($hasWireModel()) value: @entangle($attributes->wire('model')), 3 @elseif ($hasXModel()) 4 value: {{ $attributes->first('x-model') }}, 5 @else 6 value: {{ \Illuminate\Support\Js::from($value) }}, @endif 7 }"> 8 <x-input type="hidden" name="{{ $name }}" x-bind:value="value" id="{{ $id }}_input" /> 9 <div wire:ignore> 10 <div x-data="{ editorInstance: null }" x-init="Editor.create($refs.{{ $id }}, { 11 mention: { 12 feeds: [{ 13 marker: '@', 14 feed: {{ $ats() }} 15 }, 16 { 17 marker: '#', 18 feed: {{ $hashes() }} 19 } 20 ] 21 } 22 }) 23 .then(function(editor) { 24 if (value) 25 editor.data.set(value); 26 27 Livewire.on('setText', (id, text) => { 28 29 if ('{{ $id }}' == id) { 30 editor.data.set(text); 31 } 32 }); 33 34 editor.model.document.on('change:data', () => { 35 $data.value = editor.getData(); 36 $dispatch('input', editor.getData()) 37 }) 38 39 editor.clearData = function() { 40 editor.setData(''); 41 $data.value = ''; 42 editor.data.set(''); 43 $dispatch('input', '') 44 }; 45 $data.editorInstance = editor; 46 }) 47 .catch(error => { 48 console.error(error); 49 });" wire:ignore wire:key="{{ $id }}" 50 x-ref="{{ $id }}" @reset.window="$data.editorInstance.clearData"> 51 </div> 52 </div> 53 @error($attributes->wire('model')->value) 54 <span class="mt-2 text-sm text-negative-600">{{ $message }}</span> 55 @enderror 56 </div>