Skip to content

Commit

Permalink
Upgrade for Laravel 10 compatibility (#5)
Browse files Browse the repository at this point in the history
* Upgrade for Laravel 10 compatibility
  • Loading branch information
JKHarley authored Mar 12, 2023
1 parent aceb24e commit 52240b6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to `filament-trumbowyg` will be documented in this file.

## 2.0.0 - 2023-04-12
- Adds support for Laravel 10
- Fix an issue accessing the editor data through `livewire.data`
- Fixes an issue with double worded fields

## 1.0.0 - 2022-11-30

- Fixes an issue with styling of page overwriting the styling of the wysiwyg
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
"php": "^8.0",
"filament/filament": "^2.0",
"spatie/laravel-package-tools": "^1.13.5",
"illuminate/contracts": "^9.0"
"illuminate/contracts": "^9.0|^10.0"
},
"require-dev": {
"laravel/pint": "^1.0",
"nunomaduro/collision": "^6.0",
"nunomaduro/larastan": "^2.0.1",
"orchestra/testbench": "^7.0",
"orchestra/testbench": "^7.0|^8.0",
"pestphp/pest": "^1.21",
"pestphp/pest-plugin-laravel": "^1.1",
"pestphp/pest-plugin-livewire": "^1.0",
Expand Down
29 changes: 21 additions & 8 deletions resources/views/trumbowyg.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
@php
// Label is used to assign an id to the editor as $getId() causes issues
$editorId = strtolower(str_replace(' ', '-', $getLabel()));
@endphp

<x-dynamic-component
:component="$getFieldWrapperView()"
:id="$getId()"
Expand All @@ -13,11 +18,11 @@
>
<div
wire:ignore
x-data="{ state: $wire.entangle('{{ $getStatePath() }}').defer }"
x-data="{ state: $wire.entangle('{{ $getStatePath() }}').defer }"
>
<textarea
x-on:{{ $getLabel() }}.window="(e) => state = e.detail.text"
id="{{ $getLabel() }}"
x-on:{{ $editorId }}.window="(e) => state = e.detail.text"
id="{{ $editorId }}"
@if (!is_null($getPlaceholder()))
placeholder="{{ $getPlaceholder() }}";
@endif
Expand All @@ -28,24 +33,32 @@
<script>
document.addEventListener("DOMContentLoaded", function() {
if (window.jQuery && window.Alpine) {
const id = '#{{ $editorId }}';
@if(!is_null($getButtons()))
$('#{{ $getLabel() }}').trumbowyg({
$(id).trumbowyg({
resetCss: true,
btns: @json($getButtons())
})
@else
$('#{{ $getLabel() }}').trumbowyg({
$(id).trumbowyg({
resetCss: true,
@if(!is_null(config('filament-trumbowyg.buttons')) && !empty(config('filament-trumbowyg.buttons')))
btns: @json(config('filament-trumbowyg.buttons'))
@endif
});
@endif
$('#{{ $getLabel() }}').trumbowyg('html', window.livewire.data.data['{{ strtolower($getLabel()) }}']);
if (window.livewire.data) {
$(id).trumbowyg('html', window.livewire.data.data['{{ $editorId }}']);
}
if (!window.livewire.data) {
$(id).trumbowyg('html', @this.data['{{ $editorId }}']);
}
$('#{{ $getLabel() }}').on('tbwchange', function (e) {
e.target.dispatchEvent(new CustomEvent('{{ strtolower($getLabel()) }}', {bubbles: true, detail: {text: e.target.value }}))
$(id).on('tbwchange', function (e) {
e.target.dispatchEvent(new CustomEvent('{{ $editorId }}', {bubbles: true, detail: {text: e.target.value }}))
});
} else {
if (!window.jQuery) {
Expand Down

0 comments on commit 52240b6

Please sign in to comment.