-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix Trix: Alpine register style changes even if the text is not changed.
- Loading branch information
1 parent
a83a84a
commit 98a68ae
Showing
1 changed file
with
28 additions
and
15 deletions.
There are no files selected for viewing
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,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 |