diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 7fefe35..4faaef1 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -2,24 +2,32 @@ name: run-tests on: push: - branches: [main] + branches: + - main pull_request: - branches: [main] + branches: + - main jobs: test: runs-on: ${{ matrix.os }} + strategy: fail-fast: true matrix: os: [ubuntu-latest, windows-latest] - php: [8.2, 8.1] - laravel: [10.*] + php: ['8.1', '8.2', '8.3', '8.4', '8.5'] + laravel: ['10.*', '13.*'] stability: [prefer-lowest, prefer-stable] include: - laravel: 10.* testbench: 8.* carbon: ^2.63 + exclude: + - laravel: 13.* + php: '8.1' + - laravel: 13.* + php: '8.2' name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} diff --git a/README.md b/README.md index 825b96c..764e1ce 100644 --- a/README.md +++ b/README.md @@ -664,7 +664,7 @@ Both variants are equal, and it's just up to your personal preference which one whenever you want to mount an action programmatically within a calendar context, such as in the `onDateClick` method (more on this later), you can use the `mountAction` method. ```php -public function onDateClick(DateClickInfo $info) { +protected function onDateClick(DateClickInfo $info): void { $this->mountAction('createFoo'); } ``` @@ -1015,10 +1015,12 @@ To handle the callback, override the `onEventResize` method and implement your o use Illuminate\Database\Eloquent\Model; use Guava\Calendar\ValueObjects\EventResizeInfo; -protected function onEventResize(EventResizeInfo $info, Model $event): void +protected function onEventResize(EventResizeInfo $info, Model $event): bool { // Validate the data and handle the event // Most likely you will want to update the event with the new start /end dates to persist the resize in the database + + return true; } ``` diff --git a/composer.json b/composer.json index 028a2ae..dbef069 100644 --- a/composer.json +++ b/composer.json @@ -18,21 +18,21 @@ "require": { "php": "^8.1|^8.2", "filament/filament": "^5.0", - "illuminate/contracts": "^11.0|^12.0", + "illuminate/contracts": "^11.0|^12.0|^13.0", "spatie/laravel-package-tools": "^1.14.0" }, "require-dev": { "laravel/pint": "^1.0", "nunomaduro/collision": "^7.8|^8.0", "nunomaduro/larastan": "^2.0.1", - "orchestra/testbench": "^9.0|^10.0", - "pestphp/pest": "^2.36", - "pestphp/pest-plugin": "^2.1.1", - "pestphp/pest-plugin-arch": "^2.0", - "pestphp/pest-plugin-laravel": "^2.0", + "orchestra/testbench": "^9.0|^10.0|^11.0", + "pestphp/pest": "^2.36|^4.4", + "pestphp/pest-plugin": "^2.1.1|^4.0", + "pestphp/pest-plugin-arch": "^2.0|^4.0", + "pestphp/pest-plugin-laravel": "^2.0|^4.1", "phpstan/extension-installer": "^1.1", - "phpstan/phpstan-deprecation-rules": "^1.0", - "phpstan/phpstan-phpunit": "^1.0" + "phpstan/phpstan-deprecation-rules": "^1.0|^2.0", + "phpstan/phpstan-phpunit": "^1.0|^2.0" }, "autoload": { "psr-4": { diff --git a/src/CalendarServiceProvider.php b/src/CalendarServiceProvider.php index 89ee108..bc68ab1 100644 --- a/src/CalendarServiceProvider.php +++ b/src/CalendarServiceProvider.php @@ -41,8 +41,8 @@ public function packageBooted(): void 'calendar-event', __DIR__ . '/../dist/js/calendar-event.js', ), - Css::make('calendar-styles', 'https://cdn.jsdelivr.net/npm/@event-calendar/build@4.5.0/dist/event-calendar.min.css'), - Js::make('calendar-script', 'https://cdn.jsdelivr.net/npm/@event-calendar/build@4.5.0/dist/event-calendar.min.js'), + Css::make('calendar-styles', 'https://cdn.jsdelivr.net/npm/@event-calendar/build@5.5.1/dist/event-calendar.min.css'), + Js::make('calendar-script', 'https://cdn.jsdelivr.net/npm/@event-calendar/build@5.5.1/dist/event-calendar.min.js'), ], package: 'guava/calendar' ); diff --git a/src/Concerns/HandlesEventResize.php b/src/Concerns/HandlesEventResize.php index f777b85..15494fb 100644 --- a/src/Concerns/HandlesEventResize.php +++ b/src/Concerns/HandlesEventResize.php @@ -16,7 +16,7 @@ trait HandlesEventResize // TODO: -> getEndAttribute() // TODO: where the user needs to define which attributes is the start/end date // TODO: Then we can handle the update outselves by default - public function onEventResize(EventResizeInfo $info, Model $event): bool + protected function onEventResize(EventResizeInfo $info, Model $event): bool { return true; } diff --git a/src/ValueObjects/CalendarResource.php b/src/ValueObjects/CalendarResource.php index d889a3e..eff7805 100644 --- a/src/ValueObjects/CalendarResource.php +++ b/src/ValueObjects/CalendarResource.php @@ -2,13 +2,14 @@ namespace Guava\Calendar\ValueObjects; +use Illuminate\Contracts\Support\Htmlable; use Illuminate\Database\Eloquent\Model; class CalendarResource { protected int | string $id; - protected string $title; + protected string | Htmlable $title; protected ?string $eventBackgroundColor = null; @@ -32,7 +33,7 @@ public function getId(): int | string return $this->id; } - public function title(string $title): static + public function title(string | Htmlable $title): static { $this->title = $title; @@ -121,11 +122,32 @@ public function toCalendarObject(): array { return [ 'id' => $this->id, - 'title' => $this->getTitle(), + 'title' => $this->getTitle() instanceof Htmlable ? ['html' => $this->getTitle()->toHtml()] : $this->getTitle(), 'eventBackgroundColor' => $this->getEventBackgroundColor(), 'eventTextColor' => $this->getEventTextColor(), 'children' => collect($this->getChildren())->toArray(), 'extendedProps' => $this->getExtendedProps(), ]; } + + public static function fromCalendarObject(array $data): CalendarResource + { + $resource = CalendarResource::make(data_get($data, 'id')); + + $resource->title(data_get($data, 'title')); + + if ($eventBackgroundColor = data_get($data, 'eventBackgroundColor')) { + $resource->eventBackgroundColor($eventBackgroundColor); + } + + if ($eventTextColor = data_get($data, 'eventTextColor')) { + $resource->eventTextColor($eventTextColor); + } + + if ($extendedProps = data_get($data, 'extendedProps')) { + $resource->extendedProps($extendedProps); + } + + return $resource; + } } diff --git a/src/ValueObjects/DateClickInfo.php b/src/ValueObjects/DateClickInfo.php index d124400..56a6ad9 100644 --- a/src/ValueObjects/DateClickInfo.php +++ b/src/ValueObjects/DateClickInfo.php @@ -16,6 +16,8 @@ public CalendarView $view; + public ?CalendarResource $resource; + protected array $originalData; public function __construct(array $data, bool $useFilamentTimezone) @@ -35,6 +37,12 @@ public function __construct(array $data, bool $useFilamentTimezone) data_get($data, 'tzOffset'), $useFilamentTimezone ); + + if ($resource = data_get($data, 'resource')) { + $this->resource = CalendarResource::fromCalendarObject($resource); + } else { + $this->resource = null; + } } public function getContext(): Context diff --git a/src/ValueObjects/DateSelectInfo.php b/src/ValueObjects/DateSelectInfo.php index da6bbbe..c176e34 100644 --- a/src/ValueObjects/DateSelectInfo.php +++ b/src/ValueObjects/DateSelectInfo.php @@ -18,6 +18,8 @@ public CalendarView $view; + public ?CalendarResource $resource; + protected array $originalData; public function __construct(array $data, bool $useFilamentTimezone) @@ -43,6 +45,12 @@ public function __construct(array $data, bool $useFilamentTimezone) data_get($data, 'tzOffset'), $useFilamentTimezone ); + + if ($resource = data_get($data, 'resource')) { + $this->resource = CalendarResource::fromCalendarObject($resource); + } else { + $this->resource = null; + } } public function getContext(): Context