Skip to content

Commit 88bf56b

Browse files
Supports Livewire v4 (#2026)
* Update livewire dependency to allow beta version * supports livewire v4 * update phpstan configuration to use PHP 8.3 * fix: update JavaScript handling for Livewire v3 compatibility * fix: update dependencies for compatibility with PHP 8.4 and add composer/composer --------- Co-authored-by: luanfreitasdev <[email protected]>
1 parent e448368 commit 88bf56b

File tree

13 files changed

+112
-46
lines changed

13 files changed

+112
-46
lines changed

.github/workflows/code-style.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
fail-fast: false
2121
matrix:
2222
php: [ 8.3 ]
23-
laravel: [ 11.* ]
23+
laravel: [ 12.* ]
2424
dependency-version: [ prefer-stable ]
2525

2626
name: PHP:${{ matrix.php }} / L:${{ matrix.laravel }}

.github/workflows/mysql.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,10 @@ jobs:
4040
matrix:
4141
php: [ 8.4, 8.3 ]
4242
laravel: [ 11.*, 12.* ]
43+
livewire: [ 3.*, 4.* ]
4344
dependency-version: [ prefer-stable ]
4445

45-
name: PHP:${{ matrix.php }} / L:${{ matrix.laravel }}
46-
47-
if: github.ref != 'refs/heads/todo-tests'
46+
name: PHP:${{ matrix.php }} / Laravel:${{ matrix.laravel }} / Livewire:${{ matrix.livewire }}
4847

4948
steps:
5049
- name: Checkout
@@ -66,15 +65,11 @@ jobs:
6665
uses: actions/cache@v4
6766
with:
6867
path: $(composer config cache-files-dir)
69-
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
70-
71-
- name: Uninstall Larastan (until laravel 12 support)
72-
run: |
73-
composer remove "larastan/larastan" --dev --no-interaction --no-update
68+
key: dependencies-laravel-${{ matrix.laravel }}-livewire-${{ matrix.livewire}}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
7469

7570
- name: Install Composer dependencies
7671
run: |
77-
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update
72+
composer require "laravel/framework:${{ matrix.laravel }}" "livewire/livewire:${{ matrix.livewire }}" --no-interaction --no-update
7873
composer install
7974
8075
- name: Install openspout/openspout

.github/workflows/phpstan.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ jobs:
2727
strategy:
2828
fail-fast: false
2929
matrix:
30-
php: [ 8.4, 8.3 ]
31-
laravel: [ 11.* ]
30+
php: [ 8.4 ]
31+
laravel: [ 12.* ]
3232
dependency-version: [ prefer-stable ]
3333

3434
name: PHP:${{ matrix.php }} / L:${{ matrix.laravel }}

.github/workflows/postgres.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@ jobs:
4141
matrix:
4242
php: [ 8.4, 8.3 ]
4343
laravel: [ 11.*, 12.* ]
44+
livewire: [ 3.*, 4.* ]
4445
dependency-version: [ prefer-stable ]
4546

46-
name: PHP:${{ matrix.php }} / L:${{ matrix.laravel }}
47-
48-
if: github.ref != 'refs/heads/todo-tests'
47+
name: PHP:${{ matrix.php }} / Laravel:${{ matrix.laravel }} / Livewire:${{ matrix.livewire }}
4948

5049
steps:
5150
- name: Checkout
@@ -67,15 +66,11 @@ jobs:
6766
uses: actions/cache@v4
6867
with:
6968
path: $(composer config cache-files-dir)
70-
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
71-
72-
- name: Uninstall Larastan (until laravel 12 support)
73-
run: |
74-
composer remove "larastan/larastan" --dev --no-interaction --no-update
69+
key: dependencies-laravel-${{ matrix.laravel }}-livewire-${{ matrix.livewire}}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
7570

7671
- name: Install Composer dependencies
7772
run: |
78-
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update
73+
composer require "laravel/framework:${{ matrix.laravel }}" "livewire/livewire:${{ matrix.livewire }}" --no-interaction --no-update
7974
composer install
8075
8176
- name: Install openspout/openspout

.github/workflows/sqlite.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ jobs:
2929
matrix:
3030
php: [8.4, 8.3 ]
3131
laravel: [ 11.*, 12.* ]
32+
livewire: [ 3.*, 4.* ]
3233
dependency-version: [ prefer-stable ]
3334

34-
name: PHP:${{ matrix.php }} / L:${{ matrix.laravel }}
35-
36-
if: github.ref != 'refs/heads/todo-tests'
35+
name: PHP:${{ matrix.php }} / Laravel:${{ matrix.laravel }} / Livewire:${{ matrix.livewire }}
3736

3837
steps:
3938
- name: Checkout
@@ -55,15 +54,11 @@ jobs:
5554
uses: actions/cache@v4
5655
with:
5756
path: $(composer config cache-files-dir)
58-
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
59-
60-
- name: Uninstall Larastan (until laravel 12 support)
61-
run: |
62-
composer remove "larastan/larastan" --dev --no-interaction --no-update
57+
key: dependencies-laravel-${{ matrix.laravel }}-livewire-${{ matrix.livewire}}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
6358

6459
- name: Install Composer dependencies
6560
run: |
66-
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update
61+
composer require "laravel/framework:${{ matrix.laravel }}" "livewire/livewire:${{ matrix.livewire }}" --no-interaction --no-update
6762
composer install
6863
6964
- name: Install openspout/openspout

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@
1919
],
2020
"require": {
2121
"php": "^8.2",
22-
"livewire/livewire": "^3.6.0",
22+
"livewire/livewire": "^3.6.0 || ^4.0",
2323
"laravel/prompts": "*"
2424
},
2525
"require-dev": {
26-
"composer/composer": "^2.7.9",
2726
"laravel/pint": "^1.24",
2827
"pestphp/pest": "^2.35.1|^3.0",
2928
"orchestra/testbench": "^9.4|^10.0",
3029
"larastan/larastan": "^2.0|^3.0",
3130
"laradumps/laradumps": "^3.2|^4.0",
3231
"laravel/scout": "^10.11.3",
33-
"openspout/openspout": "^4.24.5"
32+
"openspout/openspout": "^4.24.5",
33+
"composer/composer": "^2.8"
3434
},
3535
"suggest": {
3636
"openspout/openspout": "Required to export XLS and CSV"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
@php use PowerComponents\LivewirePowerGrid\Providers\SupportLivewireVersions; @endphp
2+
3+
@if (SupportLivewireVersions::isV4())
4+
@script
5+
<script>
6+
this.$js('pgRowTemplates', (rowTemplates) => {
7+
window['pgRowTemplates_' + $wire.id] = JSON.parse(rowTemplates);
8+
})
9+
this.$js('pgResourceIcons', (icons) => {
10+
window.pgResourceIcons = JSON.parse(icons);
11+
})
12+
this.$js('pgActions', (actions) => {
13+
window['pgActions_' + $wire.id] = JSON.parse(actions);
14+
})
15+
this.$js('pgActionsHeader', (actions) => {
16+
window['pgActionsHeader_' + $wire.id] = JSON.parse(actions);
17+
})
18+
</script>
19+
@endscript
20+
@endif

resources/views/components/table-base.blade.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,6 @@ class="{{ theme_style($theme, 'table.body.tbody') }}"
4040

4141
<div x-data="pgLoadMore"></div>
4242
@endif
43+
44+
<x-livewire-powergrid::support-livewire-v4 />
4345
</div>

src/Concerns/HasActions.php

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Support\Str;
77
use Illuminate\View\ComponentAttributeBag;
88
use PowerComponents\LivewirePowerGrid\Button;
9+
use PowerComponents\LivewirePowerGrid\Providers\SupportLivewireVersions;
910

1011
trait HasActions
1112
{
@@ -25,9 +26,13 @@ public function prepareActionsResources(): ?string
2526
$records = (string) $closure();
2627
}
2728

28-
$this->js(<<<JS
29-
this.pgResourceIcons = $records
30-
JS);
29+
if (SupportLivewireVersions::isV3()) {
30+
$this->js(<<<JS
31+
this.pgResourceIcons = $records
32+
JS);
33+
} else {
34+
$this->js('pgResourceIcons', $records);
35+
}
3136

3237
return $records;
3338
}
@@ -68,9 +73,15 @@ public function dispatchActionsToJS(array $actionsHtml): void
6873

6974
$actionsHtml = json_encode($actionsHtml);
7075

71-
$this->js(<<<JS
72-
this[`pgActions_\${\$wire.id}`] = $actionsHtml
73-
JS);
76+
if (SupportLivewireVersions::isV3()) {
77+
$this->js(<<<JS
78+
this[`pgActions_\${\$wire.id}`] = $actionsHtml
79+
JS);
80+
81+
return;
82+
}
83+
84+
$this->js('pgActions', $actionsHtml);
7485
}
7586

7687
public function storeActionsHeaderInJSWindow(): void
@@ -93,9 +104,15 @@ public function storeActionsHeaderInJSWindow(): void
93104

94105
$actionsHtml = json_encode($actionsHtml);
95106

96-
$this->js(<<<JS
97-
this[`pgActionsHeader_\${\$wire.id}`] = $actionsHtml
98-
JS);
107+
if (SupportLivewireVersions::isV3()) {
108+
$this->js(<<<JS
109+
this[`pgActionsHeader_\${\$wire.id}`] = $actionsHtml
110+
JS);
111+
112+
return;
113+
}
114+
115+
$this->js('pgActionsHeader', $actionsHtml);
99116
}
100117

101118
public function prepareActionRulesForRows(mixed $row, ?object $loop = null): array

src/Concerns/ManageRow.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace PowerComponents\LivewirePowerGrid\Concerns;
44

55
use PowerComponents\LivewirePowerGrid\Column;
6+
use PowerComponents\LivewirePowerGrid\Providers\SupportLivewireVersions;
67
use stdClass;
78

89
trait ManageRow
@@ -11,9 +12,15 @@ public function prepareRowTemplates(): void
1112
{
1213
$rowTemplates = json_encode($this->rowTemplates());
1314

14-
$this->js(<<<JS
15-
this[`pgRowTemplates_\${\$wire.id}`] = $rowTemplates
16-
JS);
15+
if (SupportLivewireVersions::isV3()) {
16+
$this->js(<<<JS
17+
window[`pgRowTemplates_\${\$wire.id}`] = $rowTemplates
18+
JS);
19+
20+
return;
21+
}
22+
23+
$this->js('pgRowTemplates', $rowTemplates);
1724
}
1825

1926
public function shouldShowEditOnClick(stdClass|Column|array $column, mixed $row): bool

0 commit comments

Comments
 (0)