Skip to content

Commit

Permalink
fix Trix: Alpine register style changes even if the text is not changed.
Browse files Browse the repository at this point in the history
  • Loading branch information
tanthammar committed Mar 27, 2021
1 parent a83a84a commit 98a68ae
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions resources/views/components/trix.blade.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
<div class="w-full" x-data="{ trix: @entangle($field->key).defer }">
<div class="w-full"
x-data="{
trix: @entangle($field->key).defer,
notFocused() { return document.activeElement !== this.$refs.trixInput },
setValue() {
{{-- replace content --}}
this.$refs.trixInput.editor.loadHTML(this.trix);
{{-- move cursor to the end--}}
this.$refs.trixInput.editor.setSelectedRange(this.$refs.trixInput.editor.getDocument().toString().length - 1);
},
}"
x-init="$watch('trix', () => notFocused() && setValue())"
x-on:trix-change.debounce.300ms="trix = $refs.trixInput.value"
>
<input value="{{ old($field->key) ?? $value }}" id="trix{{ md5($field->key) }}" name="trix{{ md5($field->key) }}" type="hidden" />
<div wire:ignore x-on:trix-file-accept="return event.preventDefault()" class="no-upload">
<trix-editor x-model.debounce.500ms="trix" input="trix{{ md5($field->key) }}" {{ $attributes->merge(['class' => $errors->has($field->key) ? $error() : $class() ]) }}></trix-editor>
<trix-editor x-ref="trixInput" input="trix{{ md5($field->key) }}" {{ $attributes->merge(['class' => $errors->has($field->key) ? $error() : $class() ]) }}></trix-editor>
</div>
</div>
@if($field->includeScript)
@tfonce('styles:trix')
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/trix/1.2.0/trix.css" media="print" onload="this.media='all'">
@endtfonce
@tfonce('scripts:trix')
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/trix/1.2.0/trix.js"></script>
@endtfonce
@tfonce('styles:trix-no-upload')
<style>
div.no-upload trix-toolbar span.trix-button-group.trix-button-group--file-tools {
display: none;
}
</style>
@endtfonce
@tfonce('styles:trix')
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/trix/1.2.0/trix.css" media="print" onload="this.media='all'">
@endtfonce
@tfonce('scripts:trix')
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/trix/1.2.0/trix.js"></script>
@endtfonce
@tfonce('styles:trix-no-upload')
<style>
div.no-upload trix-toolbar span.trix-button-group.trix-button-group--file-tools {
display: none;
}
</style>
@endtfonce
@endif

0 comments on commit 98a68ae

Please sign in to comment.