Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: tests

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php: [8.3, 8.4]

name: PHP ${{ matrix.php }}

steps:
- name: Checkout code
uses: actions/checkout@v6
with:
persist-credentials: false

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, bcmath, soap, intl, gd, exif, iconv
coverage: none

- name: Install dependencies
run: |
composer config allow-plugins.pestphp/pest-plugin true
composer install --prefer-dist --no-interaction

- name: Install Playwright
run: |
npm install playwright@latest
npx playwright install --with-deps

- name: Execute tests
run: vendor/bin/pest
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ vendor/
composer.lock
.idea
.DS_Store
tests/Browser/Screenshots
node_modules
20 changes: 19 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "library",
"license": "MIT",
"homepage": "https://github.com/power-components/partials",
"minimum-stability": "dev",
"minimum-stability": "stable",
"authors": [
{
"name": "Luan Freitas",
Expand All @@ -23,11 +23,29 @@
"src/functions.php"
]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"extra": {
"laravel": {
"providers": [
"PowerComponents\\Partials\\PartialsServiceProvider"
]
}
},
"require-dev": {
"pestphp/pest": "^4.0",
"pestphp/pest-plugin-laravel": "^4.0",
"orchestra/testbench": "^10.0",
"pestphp/pest-plugin-browser": "^4.0",
"laravel/pint": "^1.29",
"mockery/mockery": "^1.6.12"
},
"config": {
"allow-plugins": {
"pestphp/pest-plugin": true
}
}
}
60 changes: 60 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "partials",
"version": "1.0.0",
"description": "Livewire Partials provide a structured and explicit way to update **specific DOM fragments** of a Livewire component instead of re-rendering the entire component tree. This is especially useful for complex components such as data tables, where partial updates significantly improve performance and user experience.",
"homepage": "https://github.com/Power-Components/partials#readme",
"bugs": {
"url": "https://github.com/Power-Components/partials/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Power-Components/partials.git"
},
"license": "ISC",
"author": "",
"type": "commonjs",
"main": "index.js",
"directories": {
"test": "tests"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"playwright": "^1.60.0"
}
}
32 changes: 32 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Feature">
<directory>tests/Feature</directory>
</testsuite>
<testsuite name="Browser">
<directory>tests/Browser</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>src</directory>
</include>
</source>
<php>
<env name="APP_ENV" value="testing"/>
<env name="APP_MAINTENANCE_DRIVER" value="file"/>
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_STORE" value="array"/>
<!-- <env name="DB_CONNECTION" value="sqlite"/> -->
<!-- <env name="DB_DATABASE" value=":memory:"/> -->
<env name="MAIL_MAILER" value="array"/>
<env name="PULSE_ENABLED" value="false"/>
<env name="QUEUE_CONNECTION" value="sync"/>
<env name="SESSION_DRIVER" value="array"/>
</php>
</phpunit>
4 changes: 0 additions & 4 deletions resources/js/partials.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ document.addEventListener('livewire:init', () => {
continue
}

if (els.length > 1) {
throw `Multiple elements found for partial [${name}].`
}

let el = els[0]

const getIgnoreKey = (node) => {
Expand Down
6 changes: 4 additions & 2 deletions src/PartialsHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

use Closure;
use Illuminate\View\View;
use Livewire\{Component, ComponentHook};
use Livewire\Component;
use Livewire\ComponentHook;
use Livewire\Drawer\Utils;
use Livewire\Mechanisms\HandleComponents\{ComponentContext, ViewContext};
use Livewire\Mechanisms\HandleComponents\ComponentContext;
use Livewire\Mechanisms\HandleComponents\ViewContext;
use PowerComponents\Partials\Attribute\PartialRender;
use ReflectionMethod;

Expand Down
17 changes: 17 additions & 0 deletions src/PartialsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PowerComponents\Partials;

use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;
use Livewire\Mechanisms\DataStore;

Expand All @@ -10,6 +11,22 @@ class PartialsServiceProvider extends ServiceProvider
public function boot(): void
{
$this->publishConfigs();
$this->registerRoutes();
}

private function registerRoutes(): void
{
Route::get('/powergrid-partials/partials.js', function () {
return response(file_get_contents(__DIR__.'/../resources/js/partials.js'), 200, [
'Content-Type' => 'application/javascript',
]);
});

Route::get('/powergrid-partials/utils.js', function () {
return response(file_get_contents(__DIR__.'/../resources/js/utils.js'), 200, [
'Content-Type' => 'application/javascript',
]);
});
}

public function register(): void
Expand Down
Loading