From 3f01ea3f4c1353e54999d9d942a205f4c9906bb8 Mon Sep 17 00:00:00 2001 From: Manuk Date: Sat, 14 Nov 2026 02:56:29 +0400 Subject: [PATCH 01/34] feat(columns): collapse chosen columns or every column --- docs/content/2.essentials/2.customization.md | 18 ++++++ docs/content/2.essentials/4.api-reference.md | 4 ++ .../views/modern/livewire/column.blade.php | 2 +- src/Board.php | 13 ++++- src/Concerns/HasColumnControls.php | 55 +++++++++++++++++++ tests/Fixtures/Modern/TestBoard.php | 6 ++ tests/Modern/Feature/CollapsedColumnsTest.php | 49 +++++++++++++++++ 7 files changed, 145 insertions(+), 2 deletions(-) create mode 100644 src/Concerns/HasColumnControls.php create mode 100644 tests/Modern/Feature/CollapsedColumnsTest.php diff --git a/docs/content/2.essentials/2.customization.md b/docs/content/2.essentials/2.customization.md index 26aa76c04..aba7e7a1e 100644 --- a/docs/content/2.essentials/2.customization.md +++ b/docs/content/2.essentials/2.customization.md @@ -290,6 +290,24 @@ Style the rail with the `.flowforge-column-collapsed` class. On a Modern board the rail also keeps the header `+` from `createCardAction()`, shows no column summary and no add row, and carries `data-collapsed` on `.ff-column`. With a grouping active, every column keeps its width so every lane cell stays a drop target. +## Collapse Chosen Columns + +Collapse columns by id, or all of them, when your app owns the state. Both options take a +value or a closure, so a host can read them from a user preference: + +```php +public function board(Board $board): Board +{ + return $board + ->collapsedColumns(fn (): array => $this->collapsedStages) + ->collapseAllColumns(fn (): bool => $this->collapseEverything); +} +``` + +Ids that match no column, or a hidden column, are ignored. A collapsed column renders the +same rail as an empty one and stays a full drop target. The empty-column rule from +`collapseEmptyColumns()` keeps working beside these options. + ## Search and Filtering Enable powerful search and filtering capabilities: diff --git a/docs/content/2.essentials/4.api-reference.md b/docs/content/2.essentials/4.api-reference.md index aaa381009..aee46e435 100644 --- a/docs/content/2.essentials/4.api-reference.md +++ b/docs/content/2.essentials/4.api-reference.md @@ -28,6 +28,8 @@ navigation: | `filtersLayout(FiltersLayout)` | Filter display layout (Dropdown, AboveContent, etc.) | | | `headerToolbar(bool)` | Render filters/search inline with page title | | | `collapseEmptyColumns(bool)` | Collapse columns holding no cards into a rail | | +| `collapsedColumns(array\|Closure)` | Collapse the listed column ids into a rail. Unknown and hidden ids are ignored | | +| `collapseAllColumns(bool\|Closure)` | Collapse every visible column into a rail | | ## Board Methods @@ -138,6 +140,8 @@ use Filament\Support\Enums\Width; ->filtersFormColumns(3) // Columns in filter form ->headerToolbar() // Inline filters/search in page header ->collapseEmptyColumns() // Collapse columns holding no cards +->collapsedColumns(['won', 'lost']) // Collapse the listed columns +->collapseAllColumns() // Collapse every column ``` ### Modern board additions diff --git a/resources/views/modern/livewire/column.blade.php b/resources/views/modern/livewire/column.blade.php index 608dfedd3..e944df756 100644 --- a/resources/views/modern/livewire/column.blade.php +++ b/resources/views/modern/livewire/column.blade.php @@ -2,7 +2,7 @@ @php $total = $column['total'] ?? (isset($column['items']) ? count($column['items']) : 0); - $isCollapsed = ($config['collapseEmptyColumns'] ?? false) && $total === 0; + $isCollapsed = (bool) ($column['isCollapsed'] ?? false); $plainLabel = strip_tags((string) $column['label']); $trayLabel = __('flowforge::flowforge.column_label', [ 'column' => $plainLabel, diff --git a/src/Board.php b/src/Board.php index 25526d7c1..12e22e182 100644 --- a/src/Board.php +++ b/src/Board.php @@ -14,6 +14,7 @@ use Relaticle\Flowforge\Concerns\HasBoardRecords; use Relaticle\Flowforge\Concerns\HasCardLabels; use Relaticle\Flowforge\Concerns\HasCardSchema; +use Relaticle\Flowforge\Concerns\HasColumnControls; use Relaticle\Flowforge\Concerns\HasColumnSummaries; use Relaticle\Flowforge\Concerns\InteractsWithKanbanQuery; use Relaticle\Flowforge\Contracts\HasBoard; @@ -29,6 +30,7 @@ class Board extends ViewComponent use HasBoardRecords; use HasCardLabels; use HasCardSchema; + use HasColumnControls; use HasColumnSummaries; use InteractsWithKanbanQuery; @@ -140,11 +142,17 @@ protected function getColumnViewData(bool $withItems): array ? $this->getBoardRecordsForColumns(array_map(fn (Column $column): string => $column->getName(), $this->getColumns())) : []; $columns = []; + $collapsedIds = $this->getCollapsedColumns(); + $collapseAll = $this->collapsesAllColumns(); + $collapseEmpty = $this->collapsesEmptyColumns() + && $this->getActiveGrouping() === null + && array_sum(array_map(fn (Column $column): int => $allCounts[$column->getName()] ?? 0, $this->getColumns())) > 0; foreach ($this->getColumns() as $column) { $columnId = $column->getName(); $limit = $column->getLimit(); $limitTotal = $limit === null ? null : $this->getUnfilteredColumnRecordCount($columnId); + $total = $allCounts[$columnId] ?? 0; $columns[$columnId] = [ 'id' => $columnId, @@ -154,7 +162,10 @@ protected function getColumnViewData(bool $withItems): array 'items' => isset($recordsByColumn[$columnId]) ? $recordsByColumn[$columnId]->map(fn ($record) => $this->formatBoardRecord($record))->toArray() : [], - 'total' => $allCounts[$columnId] ?? 0, + 'total' => $total, + 'isCollapsed' => $collapseAll + || in_array($columnId, $collapsedIds, true) + || ($collapseEmpty && $total === 0), 'summary' => $this->getColumnSummary($column), 'limit' => $limit, 'limitTotal' => $limitTotal, diff --git a/src/Concerns/HasColumnControls.php b/src/Concerns/HasColumnControls.php new file mode 100644 index 000000000..b2609d9bd --- /dev/null +++ b/src/Concerns/HasColumnControls.php @@ -0,0 +1,55 @@ +|Closure */ + protected array | Closure $collapsedColumns = []; + + protected bool | Closure $collapseAllColumns = false; + + /** + * Collapse the listed columns into a rail. The host owns the list. + * + * @param array|Closure $columnIds + */ + public function collapsedColumns(array | Closure $columnIds): static + { + $this->collapsedColumns = $columnIds; + + return $this; + } + + /** + * @return list + */ + public function getCollapsedColumns(): array + { + $requested = array_map( + fn (mixed $columnId): string => (string) $columnId, + (array) $this->evaluate($this->collapsedColumns), + ); + + $visible = array_map(fn (Column $column): string => $column->getName(), $this->getColumns()); + + return array_values(array_intersect($visible, $requested)); + } + + public function collapseAllColumns(bool | Closure $condition = true): static + { + $this->collapseAllColumns = $condition; + + return $this; + } + + public function collapsesAllColumns(): bool + { + return (bool) $this->evaluate($this->collapseAllColumns); + } +} diff --git a/tests/Fixtures/Modern/TestBoard.php b/tests/Fixtures/Modern/TestBoard.php index 5f07af9a6..94c6e4a38 100644 --- a/tests/Fixtures/Modern/TestBoard.php +++ b/tests/Fixtures/Modern/TestBoard.php @@ -24,6 +24,10 @@ class TestBoard extends BoardPage public bool $collapseEmpty = false; + public array $collapsedIds = []; + + public bool $collapseAll = false; + public bool $withHeaderToolbar = false; public bool $withCreateAction = false; @@ -67,6 +71,8 @@ public function board(Board $board): Board { return $board ->collapseEmptyColumns($this->collapseEmpty) + ->collapsedColumns($this->collapsedIds) + ->collapseAllColumns($this->collapseAll) ->headerToolbar($this->withHeaderToolbar) ->query($this->getEloquentQuery()) ->recordTitleAttribute('title') diff --git a/tests/Modern/Feature/CollapsedColumnsTest.php b/tests/Modern/Feature/CollapsedColumnsTest.php new file mode 100644 index 000000000..5f6069e04 --- /dev/null +++ b/tests/Modern/Feature/CollapsedColumnsTest.php @@ -0,0 +1,49 @@ + ['in_progress']]) + ->assertStatus(200) + ->html(); + + expect(substr_count($html, 'data-collapsed'))->toBe(1) + ->and($html)->toMatch('/]*data-column-root="in_progress"[^>]*data-collapsed/'); + }); + + test('collapses every column when collapse all is on', function () { + Task::factory()->todo()->create(['title' => 'Only Task']); + + $html = Livewire::test(TestBoard::class, ['collapseAll' => true]) + ->assertStatus(200) + ->html(); + + expect(substr_count($html, 'data-collapsed'))->toBe(3); + }); + + test('ignores collapsed ids for missing and hidden columns', function () { + Livewire::test(TestBoard::class, ['collapsedIds' => ['nope', 'archived']]) + ->assertStatus(200) + ->assertDontSeeHtml('data-collapsed'); + }); + + test('a collapsed column keeps its drop binding', function () { + $html = Livewire::test(TestBoard::class, ['collapsedIds' => ['todo']])->html(); + + expect($html)->toMatch('/]*data-column-root="todo"[^>]*data-collapsed[^>]*x-bind:data-drop="columnDrop\(\'todo\'\)"/'); + }); + + test('keeps the empty column rule beside listed ids', function () { + Task::factory()->todo()->create(['title' => 'Only Task']); + + $html = Livewire::test(TestBoard::class, ['collapseEmpty' => true, 'collapsedIds' => ['todo']])->html(); + + expect(substr_count($html, 'data-collapsed'))->toBe(3) + ->and($html)->toMatch('/]*data-column-root="todo"[^>]*data-collapsed/'); + }); +}); From 19f91bd589536d57be8ce4286d2994167552a26a Mon Sep 17 00:00:00 2001 From: Manuk Date: Sat, 14 Nov 2026 03:00:30 +0400 Subject: [PATCH 02/34] fix(columns): hide cards in a collapsed column and accept any id list --- .../views/modern/livewire/column.blade.php | 4 +-- src/Board.php | 18 +++++++---- src/Concerns/HasColumnControls.php | 12 ++++--- tests/Fixtures/Modern/TestBoard.php | 8 ++++- tests/Modern/Feature/CollapsedColumnsTest.php | 32 +++++++++++++++++++ 5 files changed, 60 insertions(+), 14 deletions(-) diff --git a/resources/views/modern/livewire/column.blade.php b/resources/views/modern/livewire/column.blade.php index e944df756..993c9f8a5 100644 --- a/resources/views/modern/livewire/column.blade.php +++ b/resources/views/modern/livewire/column.blade.php @@ -47,7 +47,7 @@ class="ff-cards" @end.stop="handleSortableEnd($event)" x-init="$nextTick(() => configureSortable($el))" @endif - @if(isset($column['total']) && $column['total'] > count($column['items'])) + @if(! $isCollapsed && isset($column['total']) && $column['total'] > count($column['items'])) @scroll.throttle.100ms="handleColumnScroll($event, '{{ $columnId }}')" @endif > @@ -59,7 +59,7 @@ class="ff-cards" /> @endforeach - @if(isset($column['total']) && $column['total'] > count($column['items'] ?? [])) + @if(! $isCollapsed && isset($column['total']) && $column['total'] > count($column['items'] ?? []))
getBatchedBoardRecordCounts(); - $recordsByColumn = $withItems - ? $this->getBoardRecordsForColumns(array_map(fn (Column $column): string => $column->getName(), $this->getColumns())) - : []; - $columns = []; $collapsedIds = $this->getCollapsedColumns(); $collapseAll = $this->collapsesAllColumns(); $collapseEmpty = $this->collapsesEmptyColumns() && $this->getActiveGrouping() === null && array_sum(array_map(fn (Column $column): int => $allCounts[$column->getName()] ?? 0, $this->getColumns())) > 0; + $isCollapsed = fn (string $columnId): bool => $collapseAll + || in_array($columnId, $collapsedIds, true) + || ($collapseEmpty && ($allCounts[$columnId] ?? 0) === 0); + $recordsByColumn = $withItems + ? $this->getBoardRecordsForColumns(array_values(array_filter( + array_map(fn (Column $column): string => $column->getName(), $this->getColumns()), + fn (string $columnId): bool => ! $isCollapsed($columnId), + ))) + : []; + $columns = []; foreach ($this->getColumns() as $column) { $columnId = $column->getName(); @@ -163,9 +169,7 @@ protected function getColumnViewData(bool $withItems): array ? $recordsByColumn[$columnId]->map(fn ($record) => $this->formatBoardRecord($record))->toArray() : [], 'total' => $total, - 'isCollapsed' => $collapseAll - || in_array($columnId, $collapsedIds, true) - || ($collapseEmpty && $total === 0), + 'isCollapsed' => $isCollapsed($columnId), 'summary' => $this->getColumnSummary($column), 'limit' => $limit, 'limitTotal' => $limitTotal, diff --git a/src/Concerns/HasColumnControls.php b/src/Concerns/HasColumnControls.php index b2609d9bd..a0eb9a08c 100644 --- a/src/Concerns/HasColumnControls.php +++ b/src/Concerns/HasColumnControls.php @@ -4,7 +4,9 @@ namespace Relaticle\Flowforge\Concerns; +use BackedEnum; use Closure; +use Illuminate\Contracts\Support\Arrayable; use Relaticle\Flowforge\Column; trait HasColumnControls @@ -15,8 +17,6 @@ trait HasColumnControls protected bool | Closure $collapseAllColumns = false; /** - * Collapse the listed columns into a rail. The host owns the list. - * * @param array|Closure $columnIds */ public function collapsedColumns(array | Closure $columnIds): static @@ -31,9 +31,13 @@ public function collapsedColumns(array | Closure $columnIds): static */ public function getCollapsedColumns(): array { + $evaluated = $this->evaluate($this->collapsedColumns); $requested = array_map( - fn (mixed $columnId): string => (string) $columnId, - (array) $this->evaluate($this->collapsedColumns), + fn (mixed $columnId): string => (string) ($columnId instanceof BackedEnum ? $columnId->value : $columnId), + array_filter( + $evaluated instanceof Arrayable ? $evaluated->toArray() : (array) $evaluated, + fn (mixed $columnId): bool => is_scalar($columnId) || $columnId instanceof BackedEnum, + ), ); $visible = array_map(fn (Column $column): string => $column->getName(), $this->getColumns()); diff --git a/tests/Fixtures/Modern/TestBoard.php b/tests/Fixtures/Modern/TestBoard.php index 94c6e4a38..08e7cbcbb 100644 --- a/tests/Fixtures/Modern/TestBoard.php +++ b/tests/Fixtures/Modern/TestBoard.php @@ -28,6 +28,8 @@ class TestBoard extends BoardPage public bool $collapseAll = false; + public ?string $collapsedIdsAs = null; + public bool $withHeaderToolbar = false; public bool $withCreateAction = false; @@ -71,7 +73,11 @@ public function board(Board $board): Board { return $board ->collapseEmptyColumns($this->collapseEmpty) - ->collapsedColumns($this->collapsedIds) + ->collapsedColumns(match ($this->collapsedIdsAs) { + 'collection' => fn () => collect($this->collapsedIds), + 'enum' => fn (): array => [StatusEnum::Active, ...$this->collapsedIds], + default => $this->collapsedIds, + }) ->collapseAllColumns($this->collapseAll) ->headerToolbar($this->withHeaderToolbar) ->query($this->getEloquentQuery()) diff --git a/tests/Modern/Feature/CollapsedColumnsTest.php b/tests/Modern/Feature/CollapsedColumnsTest.php index 5f6069e04..9234411fd 100644 --- a/tests/Modern/Feature/CollapsedColumnsTest.php +++ b/tests/Modern/Feature/CollapsedColumnsTest.php @@ -46,4 +46,36 @@ expect(substr_count($html, 'data-collapsed'))->toBe(3) ->and($html)->toMatch('/]*data-column-root="todo"[^>]*data-collapsed/'); }); + + test('a collapsed column renders no cards', function () { + Task::factory()->todo()->create(['title' => 'Hidden Card']); + + Livewire::test(TestBoard::class, ['collapsedIds' => ['todo']]) + ->assertDontSee('Hidden Card') + ->assertDontSeeHtml('ff-cards-more') + ->assertSeeHtml('data-column-total="1"'); + }); + + test('moving a card into a collapsed column persists it there', function () { + $card = Task::factory()->todo()->create(['title' => 'Mover']); + Task::factory()->create(['status' => 'in_progress', 'title' => 'Resident']); + + Livewire::test(TestBoard::class, ['collapsedIds' => ['in_progress']]) + ->call('moveCard', (string) $card->id, 'in_progress') + ->assertDontSee('Mover'); + + expect($card->refresh()->status)->toBe('in_progress'); + }); + + test('accepts a collection of ids', function () { + $html = Livewire::test(TestBoard::class, ['collapsedIdsAs' => 'collection', 'collapsedIds' => ['todo']])->html(); + + expect(substr_count($html, 'data-collapsed'))->toBe(1); + }); + + test('accepts backed enum ids and ignores values that are not ids', function () { + $html = Livewire::test(TestBoard::class, ['collapsedIdsAs' => 'enum', 'collapsedIds' => ['todo', ['x'], null]])->html(); + + expect(substr_count($html, 'data-collapsed'))->toBe(1); + }); }); From 7ed09755c3179c1c5a5b058d1d660e835d26f015 Mon Sep 17 00:00:00 2001 From: Manuk Date: Sat, 14 Nov 2026 03:05:10 +0400 Subject: [PATCH 03/34] feat(columns): toggle collapse from the header and the rail --- docs/content/2.essentials/2.customization.md | 18 ++++++ docs/content/2.essentials/4.api-reference.md | 2 + .../modern/livewire/column-header.blade.php | 7 ++- .../views/modern/livewire/column.blade.php | 3 + src/Board.php | 25 ++++++-- src/Concerns/HasColumnControls.php | 26 +++++++++ src/Modern/Concerns/InteractsWithBoard.php | 5 ++ tests/Browser/ModernBoardTest.php | 46 +++++++++++++++ tests/Browser/Support/Pointer.php | 9 +++ tests/Fixtures/Modern/ModernPanelProvider.php | 1 + tests/Fixtures/Modern/TestBoard.php | 14 ++++- .../Fixtures/Modern/TestCollapsibleBoard.php | 14 +++++ tests/Modern/Feature/CollapsedColumnsTest.php | 57 +++++++++++++++++++ 13 files changed, 221 insertions(+), 6 deletions(-) create mode 100644 tests/Fixtures/Modern/TestCollapsibleBoard.php diff --git a/docs/content/2.essentials/2.customization.md b/docs/content/2.essentials/2.customization.md index aba7e7a1e..c1eabd083 100644 --- a/docs/content/2.essentials/2.customization.md +++ b/docs/content/2.essentials/2.customization.md @@ -308,6 +308,24 @@ Ids that match no column, or a hidden column, are ignored. A collapsed column re same rail as an empty one and stays a full drop target. The empty-column rule from `collapseEmptyColumns()` keeps working beside these options. +### Let users toggle columns + +`collapsibleColumns()` turns on double-click on a column header and a click on a collapsed rail. +Flowforge keeps no state. It calls your closure with the column id and the new state, and you +store it where `collapsedColumns()` reads it: + +```php +->collapsedColumns(fn (): array => $this->collapsedStages) +->collapsibleColumns(function (string $columnId, bool $collapsed): void { + $this->collapsedStages = $collapsed + ? [...$this->collapsedStages, $columnId] + : array_values(array_diff($this->collapsedStages, [$columnId])); +}) +``` + +The closure never runs for an unknown or hidden column id. A double-click on the header's action +buttons does not toggle the column. + ## Search and Filtering Enable powerful search and filtering capabilities: diff --git a/docs/content/2.essentials/4.api-reference.md b/docs/content/2.essentials/4.api-reference.md index aee46e435..4e4c5f545 100644 --- a/docs/content/2.essentials/4.api-reference.md +++ b/docs/content/2.essentials/4.api-reference.md @@ -30,6 +30,7 @@ navigation: | `collapseEmptyColumns(bool)` | Collapse columns holding no cards into a rail | | | `collapsedColumns(array\|Closure)` | Collapse the listed column ids into a rail. Unknown and hidden ids are ignored | | | `collapseAllColumns(bool\|Closure)` | Collapse every visible column into a rail | | +| `collapsibleColumns(?Closure)` | Let users toggle a column by double-clicking its header or clicking its rail. The closure receives `string $columnId` and `bool $collapsed` (the new state) | | ## Board Methods @@ -142,6 +143,7 @@ use Filament\Support\Enums\Width; ->collapseEmptyColumns() // Collapse columns holding no cards ->collapsedColumns(['won', 'lost']) // Collapse the listed columns ->collapseAllColumns() // Collapse every column +->collapsibleColumns(fn (string $columnId, bool $collapsed) => ...) // Toggle from the header and the rail ``` ### Modern board additions diff --git a/resources/views/modern/livewire/column-header.blade.php b/resources/views/modern/livewire/column-header.blade.php index 566b25f18..0b6c86604 100644 --- a/resources/views/modern/livewire/column-header.blade.php +++ b/resources/views/modern/livewire/column-header.blade.php @@ -23,7 +23,12 @@ $createAction = $createAction?->isVisible() ? $createAction : null; @endphp -
+
getBoard()->isColumnCollapsible() && ! $isCollapsed) + x-on:dblclick="if (! $event.target.closest('.ff-column-actions')) $wire.toggleBoardColumnCollapse(@js($columnId))" + @endif +>
@if ($dotColor) diff --git a/src/Board.php b/src/Board.php index c35149659..89228213a 100644 --- a/src/Board.php +++ b/src/Board.php @@ -4,6 +4,7 @@ namespace Relaticle\Flowforge; +use Closure; use Filament\Support\Components\ViewComponent; use Relaticle\Flowforge\Concerns\BelongsToLivewire; use Relaticle\Flowforge\Concerns\CanSearchBoardRecords; @@ -123,6 +124,7 @@ public function getViewData(): array 'cardLabel' => $this->getCardLabel(), 'pluralCardLabel' => $this->getPluralCardLabel(), 'headerToolbar' => $this->hasHeaderToolbar(), + 'collapsible' => $this->isColumnCollapsible(), 'collapseEmptyColumns' => $grouping === null && $this->collapsesEmptyColumns() && array_sum(array_column($columns, 'total')) > 0, @@ -132,20 +134,35 @@ public function getViewData(): array ]; } + public function isColumnCollapsed(string $columnId): bool + { + return $this->makeCollapseResolver($this->getBatchedBoardRecordCounts())($columnId); + } + /** - * @return array> + * @param array $allCounts + * @return Closure(string): bool */ - protected function getColumnViewData(bool $withItems): array + protected function makeCollapseResolver(array $allCounts): Closure { - $allCounts = $this->getBatchedBoardRecordCounts(); $collapsedIds = $this->getCollapsedColumns(); $collapseAll = $this->collapsesAllColumns(); $collapseEmpty = $this->collapsesEmptyColumns() && $this->getActiveGrouping() === null && array_sum(array_map(fn (Column $column): int => $allCounts[$column->getName()] ?? 0, $this->getColumns())) > 0; - $isCollapsed = fn (string $columnId): bool => $collapseAll + + return fn (string $columnId): bool => $collapseAll || in_array($columnId, $collapsedIds, true) || ($collapseEmpty && ($allCounts[$columnId] ?? 0) === 0); + } + + /** + * @return array> + */ + protected function getColumnViewData(bool $withItems): array + { + $allCounts = $this->getBatchedBoardRecordCounts(); + $isCollapsed = $this->makeCollapseResolver($allCounts); $recordsByColumn = $withItems ? $this->getBoardRecordsForColumns(array_values(array_filter( array_map(fn (Column $column): string => $column->getName(), $this->getColumns()), diff --git a/src/Concerns/HasColumnControls.php b/src/Concerns/HasColumnControls.php index a0eb9a08c..23cdd523e 100644 --- a/src/Concerns/HasColumnControls.php +++ b/src/Concerns/HasColumnControls.php @@ -16,6 +16,8 @@ trait HasColumnControls protected bool | Closure $collapseAllColumns = false; + protected ?Closure $toggleColumnCollapse = null; + /** * @param array|Closure $columnIds */ @@ -56,4 +58,28 @@ public function collapsesAllColumns(): bool { return (bool) $this->evaluate($this->collapseAllColumns); } + + public function collapsibleColumns(?Closure $using): static + { + $this->toggleColumnCollapse = $using; + + return $this; + } + + public function isColumnCollapsible(): bool + { + return $this->toggleColumnCollapse instanceof Closure; + } + + public function toggleColumnCollapse(string $columnId): void + { + if (! $this->isColumnCollapsible() || ! in_array($columnId, $this->getColumnIdentifiers(), true)) { + return; + } + + $this->evaluate($this->toggleColumnCollapse, [ + 'columnId' => $columnId, + 'collapsed' => ! $this->isColumnCollapsed($columnId), + ]); + } } diff --git a/src/Modern/Concerns/InteractsWithBoard.php b/src/Modern/Concerns/InteractsWithBoard.php index 36de393eb..4aa2a1c97 100644 --- a/src/Modern/Concerns/InteractsWithBoard.php +++ b/src/Modern/Concerns/InteractsWithBoard.php @@ -120,6 +120,11 @@ public function getBoardCreateCardAction(string $columnId): ?Action return $action ? $action(['column' => $columnId])->livewire($this) : null; } + public function toggleBoardColumnCollapse(string $columnId): void + { + $this->getBoard()->toggleColumnCollapse($columnId); + } + protected function canCreateCardIn(mixed $columnId): bool { if (! is_string($columnId)) { diff --git a/tests/Browser/ModernBoardTest.php b/tests/Browser/ModernBoardTest.php index 5dd0618b8..783cd7e57 100644 --- a/tests/Browser/ModernBoardTest.php +++ b/tests/Browser/ModernBoardTest.php @@ -782,3 +782,49 @@ function boardTraySampler(int $budgetMilliseconds): string expect(boardStored('todo'))->toBe([$a->id, $b->id, $c->id]); }); + +test('double clicking a header collapses its column and clicking the rail expands it', function () { + boardSeed(); + $page = boardPage('/modern/test-collapsible-board'); + $pointer = Pointer::on($page); + $root = '[data-column-root="in_progress"]'; + + $pointer->doubleClick("{$root} .ff-column-title"); + $pointer->untilScript("document.querySelector('{$root}').hasAttribute('data-collapsed')"); + + expect(boardStyle($page, $root, 'width'))->toBe('48px'); + + $pointer->click($root); + $pointer->untilScript("! document.querySelector('{$root}').hasAttribute('data-collapsed')"); + + expect(boardStyle($page, $root, 'width'))->toBe('300px'); +}); + +test('double clicking the add card button leaves the column expanded', function () { + boardSeed(); + $page = boardPage('/modern/test-collapsible-board'); + $pointer = Pointer::on($page); + $root = '[data-column-root="todo"]'; + + $page->script("document.querySelector('{$root} .ff-column-actions button').dispatchEvent(new MouseEvent('dblclick', { bubbles: true }))"); + $pointer->wait(600); + + expect($page->script("document.querySelector('{$root}').hasAttribute('data-collapsed')"))->toBeFalse(); +}); + +test('a collapsed column widens while a card hovers it and accepts the drop', function () { + [$a] = boardSeed(); + $page = boardPage('/modern/test-collapsible-board'); + $pointer = Pointer::on($page); + $root = '[data-column-root="completed"]'; + + expect(boardStyle($page, $root, 'width'))->toBe('48px'); + + $pointer->press(boardCard($a))->glideTo($root); + + expect(boardStyle($page, $root, 'width'))->toBe('300px'); + + $pointer->release(); + $pointer->untilEquals(fn () => Task::query()->find($a->id)->status, 'completed', 'the moved card status'); + $pointer->untilEquals(fn () => boardStyle($page, $root, 'width'), '48px', 'the rail width after the drop'); +}); diff --git a/tests/Browser/Support/Pointer.php b/tests/Browser/Support/Pointer.php index f3586ac66..606f8e9a9 100644 --- a/tests/Browser/Support/Pointer.php +++ b/tests/Browser/Support/Pointer.php @@ -103,6 +103,15 @@ public function click(string $selector): self return $this->press($selector)->release(); } + public function doubleClick(string $selector): self + { + $this->click($selector); + $this->send('mouseDown', ['button' => 'left', 'clickCount' => 2]); + $this->send('mouseUp', ['button' => 'left', 'clickCount' => 2]); + + return $this; + } + public function drag(string $from, string $to, float $yFraction = 0.5): self { return $this->press($from)->glideTo($to, yFraction: $yFraction)->release(); diff --git a/tests/Fixtures/Modern/ModernPanelProvider.php b/tests/Fixtures/Modern/ModernPanelProvider.php index 688742ac3..bec9ddc43 100644 --- a/tests/Fixtures/Modern/ModernPanelProvider.php +++ b/tests/Fixtures/Modern/ModernPanelProvider.php @@ -30,6 +30,7 @@ public function panel(Panel $panel): Panel TestBoard::class, TestBrowserBoard::class, TestClassicBoard::class, + TestCollapsibleBoard::class, TestContractBoard::class, TestGroupedBoard::class, TestCardActionBoard::class, diff --git a/tests/Fixtures/Modern/TestBoard.php b/tests/Fixtures/Modern/TestBoard.php index 08e7cbcbb..c8e983d00 100644 --- a/tests/Fixtures/Modern/TestBoard.php +++ b/tests/Fixtures/Modern/TestBoard.php @@ -30,6 +30,10 @@ class TestBoard extends BoardPage public ?string $collapsedIdsAs = null; + public bool $collapsible = false; + + public array $toggled = []; + public bool $withHeaderToolbar = false; public bool $withCreateAction = false; @@ -76,9 +80,17 @@ public function board(Board $board): Board ->collapsedColumns(match ($this->collapsedIdsAs) { 'collection' => fn () => collect($this->collapsedIds), 'enum' => fn (): array => [StatusEnum::Active, ...$this->collapsedIds], - default => $this->collapsedIds, + default => fn (): array => $this->collapsedIds, }) ->collapseAllColumns($this->collapseAll) + ->collapsibleColumns($this->collapsible + ? function (string $columnId, bool $collapsed): void { + $this->toggled[] = [$columnId, $collapsed]; + $this->collapsedIds = $collapsed + ? [...$this->collapsedIds, $columnId] + : array_values(array_diff($this->collapsedIds, [$columnId])); + } + : null) ->headerToolbar($this->withHeaderToolbar) ->query($this->getEloquentQuery()) ->recordTitleAttribute('title') diff --git a/tests/Fixtures/Modern/TestCollapsibleBoard.php b/tests/Fixtures/Modern/TestCollapsibleBoard.php new file mode 100644 index 000000000..b68be9dda --- /dev/null +++ b/tests/Fixtures/Modern/TestCollapsibleBoard.php @@ -0,0 +1,14 @@ +toBe(1); }); }); + +describe('toggling collapse', function () { + test('toggling an expanded column asks the host to collapse it', function () { + $component = Livewire::test(TestBoard::class, ['collapsible' => true]) + ->call('toggleBoardColumnCollapse', 'todo'); + + expect($component->get('toggled'))->toBe([['todo', true]]) + ->and($component->html())->toMatch('/]*data-column-root="todo"[^>]*data-collapsed/'); + }); + + test('toggling a collapsed column asks the host to expand it', function () { + $component = Livewire::test(TestBoard::class, ['collapsible' => true, 'collapsedIds' => ['todo']]) + ->call('toggleBoardColumnCollapse', 'todo'); + + expect($component->get('toggled'))->toBe([['todo', false]]) + ->and($component->html())->not->toContain('data-collapsed'); + }); + + test('toggling an empty column that collapses by rule asks the host to expand it', function () { + Task::factory()->todo()->create(['title' => 'Only Task']); + + $component = Livewire::test(TestBoard::class, ['collapsible' => true, 'collapseEmpty' => true]) + ->call('toggleBoardColumnCollapse', 'in_progress'); + + expect($component->get('toggled'))->toBe([['in_progress', false]]); + }); + + test('toggle ignores unknown and hidden columns', function () { + $component = Livewire::test(TestBoard::class, ['collapsible' => true]) + ->call('toggleBoardColumnCollapse', 'nope') + ->call('toggleBoardColumnCollapse', 'archived'); + + expect($component->get('toggled'))->toBe([]); + }); + + test('toggle does nothing when the board is not collapsible', function () { + $component = Livewire::test(TestBoard::class) + ->call('toggleBoardColumnCollapse', 'todo'); + + expect($component->get('toggled'))->toBe([]); + }); + + test('a collapsible header binds the double click and the rail binds the click', function () { + $html = Livewire::test(TestBoard::class, ['collapsible' => true, 'collapsedIds' => ['in_progress']])->html(); + + expect($html)->toMatch('/]*class="ff-column-header"[^>]*x-on:dblclick/') + ->and($html)->toMatch('/]*data-column-root="in_progress"[^>]*x-on:click/') + ->and($html)->not->toMatch('/]*data-column-root="todo"[^>]*x-on:click/'); + }); + + test('neither binding renders when the board is not collapsible', function () { + $html = Livewire::test(TestBoard::class, ['collapsedIds' => ['in_progress']])->html(); + + expect($html)->not->toContain('x-on:dblclick') + ->and($html)->not->toMatch('/]*data-column-root="in_progress"[^>]*x-on:click/'); + }); +}); From 820399ac884f06a3287298864957a78f3c199216 Mon Sep 17 00:00:00 2001 From: Manuk Date: Sat, 14 Nov 2026 03:13:30 +0400 Subject: [PATCH 04/34] fix(columns): expand a rail on double click and rebuild after a toggle --- docs/content/2.essentials/2.customization.md | 5 +++ docs/content/2.essentials/4.api-reference.md | 2 +- resources/dist/flowforge-modern.js | 2 +- resources/js/flowforge-modern.js | 25 +++++++++++++ .../modern/livewire/column-header.blade.php | 5 ++- .../views/modern/livewire/column.blade.php | 5 ++- src/Board.php | 31 ++++++++++++---- src/Concerns/HasColumnControls.php | 6 ++- src/Modern/Concerns/InteractsWithBoard.php | 1 + tests/Browser/ModernBoardTest.php | 28 +++++++++++++- tests/Fixtures/Modern/TestBoard.php | 8 +++- .../Fixtures/Modern/TestCollapsibleBoard.php | 2 + tests/Modern/Feature/CollapsedColumnsTest.php | 37 ++++++++++++++++++- 13 files changed, 137 insertions(+), 20 deletions(-) diff --git a/docs/content/2.essentials/2.customization.md b/docs/content/2.essentials/2.customization.md index c1eabd083..fa7b7e7f3 100644 --- a/docs/content/2.essentials/2.customization.md +++ b/docs/content/2.essentials/2.customization.md @@ -326,6 +326,11 @@ store it where `collapsedColumns()` reads it: The closure never runs for an unknown or hidden column id. A double-click on the header's action buttons does not toggle the column. +Only a column listed in `collapsedColumns()` can be expanded from its rail. A column that +`collapseAllColumns()` or `collapseEmptyColumns()` collapses has no click binding, and a toggle +for it never reaches your closure. Flowforge rebuilds the board after your closure runs. Still, pass +a value your page changes during a request as a closure, as above, so every read sees the new state. + ## Search and Filtering Enable powerful search and filtering capabilities: diff --git a/docs/content/2.essentials/4.api-reference.md b/docs/content/2.essentials/4.api-reference.md index 4e4c5f545..a9b9e817d 100644 --- a/docs/content/2.essentials/4.api-reference.md +++ b/docs/content/2.essentials/4.api-reference.md @@ -30,7 +30,7 @@ navigation: | `collapseEmptyColumns(bool)` | Collapse columns holding no cards into a rail | | | `collapsedColumns(array\|Closure)` | Collapse the listed column ids into a rail. Unknown and hidden ids are ignored | | | `collapseAllColumns(bool\|Closure)` | Collapse every visible column into a rail | | -| `collapsibleColumns(?Closure)` | Let users toggle a column by double-clicking its header or clicking its rail. The closure receives `string $columnId` and `bool $collapsed` (the new state) | | +| `collapsibleColumns(?Closure)` | Let users toggle a column by double-clicking its header or clicking its rail. Only columns listed in `collapsedColumns()` expand from the rail. The closure receives `string $columnId` and `bool $collapsed` (the new state) | | ## Board Methods diff --git a/resources/dist/flowforge-modern.js b/resources/dist/flowforge-modern.js index a1739a248..43663a70f 100644 --- a/resources/dist/flowforge-modern.js +++ b/resources/dist/flowforge-modern.js @@ -1 +1 @@ -var C=["--ff-surface","--ff-surface-sunken","--ff-surface-raised","--ff-border","--ff-text","--ff-text-muted","--ff-accent","--ff-accent-tint","--ff-danger","--ff-warning","--ff-radius","--ff-gap","--ff-ease","--ff-duration","--ff-column-width","--ff-tray-bg","--ff-tray-radius","--ff-card-bg","--ff-card-ring","--ff-card-radius","--ff-card-shadow","--ff-card-padding","--ff-drag-tilt","--ff-drag-shadow","--ff-placeholder-border"],u=new WeakSet,g=()=>window.Sortable.active||window.Sortable.dragged;function S(){return{isLoading:{},fullyLoaded:{},dragOverColumn:null,dragOverLane:null,dragSource:null,pendingCounts:{},pendingMoves:0,collapsedLanes:{},placeholder:null,stopTrackingPointer:null,init(){this.$wire.$on("kanban-items-loaded",e=>{let{columnId:t,isFullyLoaded:r}=e;r&&(this.fullyLoaded[t]=!0)})},configureSortable(e){if(!e.sortable||e.sortable.options.forceFallback)return;if(g()){this.configureSortableAfterDrag(e);return}let t=window.matchMedia("(prefers-reduced-motion: reduce)").matches;e.sortable.destroy(),e.sortable=window.Sortable.create(e,{draggable:"[x-sortable-item]",handle:"[x-sortable-handle]",dataIdAttr:"x-sortable-item",forceFallback:!0,fallbackTolerance:5,fallbackOnBody:!0,fallbackClass:"",ghostClass:"",delay:150,delayOnTouchOnly:!0,animation:t?0:200,scrollSensitivity:100,scrollSpeed:15,forceAutoScrollFallback:!0,group:{name:e.getAttribute("x-sortable-group"),pull:!0,put:(r,o)=>this.canDrop(r.el,o.el)},onStart:r=>this.startDrag(r),onEnd(r){let{item:o,to:a,oldDraggableIndex:n,newDraggableIndex:i}=r;if(n===i)return;let l=a.querySelectorAll(`:scope > ${this.options.draggable}`)[i-1];l&&a.insertBefore(o,l.nextSibling)}})},configureSortableAfterDrag(e){if(u.has(e))return;u.add(e);let t=()=>{if(g()){requestAnimationFrame(t);return}u.delete(e),e.isConnected&&this.configureSortable(e)};requestAnimationFrame(t)},startDrag(e){this.stopTrackingPointer?.(),this.placeholder=e.item,this.placeholder.setAttribute("data-placeholder",""),this.markGhost(),window.getSelection()?.removeAllRanges(),document.documentElement.classList.add("ff-dragging"),this.dragSource={column:e.from.dataset.columnId,lane:e.from.dataset.laneId??null};let t=r=>this.trackPointer(r);document.addEventListener("pointermove",t,{passive:!0}),document.addEventListener("touchmove",t,{passive:!0}),this.stopTrackingPointer=()=>{document.removeEventListener("pointermove",t),document.removeEventListener("touchmove",t)}},trackPointer(e){if(!window.Sortable.active){this.endDrag();return}this.markGhost();let t=e.touches?.[0]??e,r=document.elementFromPoint(t.clientX,t.clientY),o=r?.closest("[data-column-id]"),a=r?.closest("[data-column-root]");this.dragOverColumn=o?.dataset.columnId??a?.dataset.columnRoot??null,this.dragOverLane=o?.dataset.laneId??null},markGhost(){let e=window.Sortable.ghost;if(!e||e.hasAttribute("data-dragging"))return;e.removeAttribute("data-placeholder"),e.setAttribute("data-dragging",""),e.style.opacity="1";let t=getComputedStyle(this.placeholder);for(let r of C){let o=t.getPropertyValue(r);o!==""&&e.style.setProperty(r,o)}},endDrag(){document.documentElement.classList.remove("ff-dragging"),this.placeholder?.removeAttribute("data-placeholder"),this.placeholder=null,this.stopTrackingPointer?.(),this.stopTrackingPointer=null,this.dragOverColumn=null,this.dragOverLane=null,this.dragSource=null},columnDrop(e){return this.dragOverColumn!==e?null:this.isColumnBlocked(e)?"blocked":"active"},cellDrop(e,t){return this.dragOverColumn!==e||this.dragOverLane!==t?null:this.isCellBlocked(e,t)?"blocked":"active"},canDrop(e,t){if(!this.$root.contains(e)||!this.$root.contains(t))return!1;let r=e.dataset.laneId??null,o=t.dataset.laneId??null;return r!==o&&this.$root.dataset.lanesWritable!=="true"?!1:!this.isColumnBlocked(e.dataset.columnId,t.dataset.columnId)},isColumnBlocked(e,t=this.dragSource?.column){if(!e||e===t)return!1;let r=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"]`),o=r?.dataset.columnLimit;return o===void 0||o===""?!1:Number(r.dataset.columnTotal)>=Number(o)},isCellBlocked(e,t){return this.dragSource?t!==this.dragSource.lane&&this.$root.dataset.lanesWritable!=="true"?!0:this.isColumnBlocked(e):!1},displayCount(e,t){let r=this.pendingCounts[e]??t,o=this.dragSource?.column,a=this.dragOverColumn;return!o||!a||o===a||this.isColumnBlocked(a)?r:e===a?r+1:e===o?r-1:r},holdMovedCounts(e,t){if(e===t)return()=>{};let r={[e]:-1,[t]:1},o=!1;for(let[a,n]of Object.entries(r))this.pendingCounts[a]=this.renderedCount(a)+n;return this.pendingMoves++,a=>{if(!o){if(o=!0,a)for(let[n,i]of Object.entries(r))this.pendingCounts[n]-=i;--this.pendingMoves===0&&(this.pendingCounts={})}}},renderedCount(e){let t=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"] .ff-count`);return this.pendingCounts[e]??Number(t?.dataset.total)},handleSortableEnd(e){this.endDrag();let t=e.item,r=e.to,o=e.newDraggableIndex??e.newIndex,a=":scope > [x-sortable-item], :scope > [data-card-id]",n=s=>s.getAttribute("x-sortable-item")||s.getAttribute("data-card-id");if(e.from===r&&e.oldDraggableIndex===e.newDraggableIndex)return;if(o===0){let s=r.querySelector(a);s&&s!==t&&r.insertBefore(t,s)}let i=n(t);if(!i){console.error("Flowforge: Could not determine card ID for move operation");return}let l=r.getAttribute("data-column-id");if(!l){console.error("Flowforge: Target column ID is missing");return}let h=e.from.dataset.laneId??null,m=r.dataset.laneId??null,c=r.querySelectorAll(a),d=Array.prototype.indexOf.call(c,t),p=d>0?n(c[d-1]):null,b=d>=0&&d{this.setCardState(t,!1),f(s===!1),s===!1&&this.revertCard(e)}).catch(()=>{this.setCardState(t,!1),f(!0),this.revertCard(e)})},revertCard({item:e,from:t,oldDraggableIndex:r}){e.remove();let o=t.querySelectorAll(":scope > [x-sortable-item]"),a=o[o.length-1],n=o[r]??(a?a.nextSibling:t.firstChild);t.insertBefore(e,n)},setCardState(e,t){e.toggleAttribute("data-pending",t)},isLaneCollapsed(e){return this.collapsedLanes[e]===!0},toggleLane(e){this.collapsedLanes[e]=!this.isLaneCollapsed(e)},isLoadingColumn(e){return this.isLoading[e]||!1},isColumnFullyLoaded(e){return this.fullyLoaded[e]||!1},handleSmoothScroll(e){this.isLoadingColumn(e)||this.isColumnFullyLoaded(e)||(this.isLoading[e]=!0,this.$wire.loadMoreItems(e).then(()=>setTimeout(()=>this.isLoading[e]=!1,100)).catch(()=>this.isLoading[e]=!1))},handleColumnScroll(e,t){if(this.isColumnFullyLoaded(t))return;let{scrollTop:r,scrollHeight:o,clientHeight:a}=e.target;(r+a)/o>=.8&&!this.isLoadingColumn(t)&&this.handleSmoothScroll(t)}}}export{S as default}; +var C=["--ff-surface","--ff-surface-sunken","--ff-surface-raised","--ff-border","--ff-text","--ff-text-muted","--ff-accent","--ff-accent-tint","--ff-danger","--ff-warning","--ff-radius","--ff-gap","--ff-ease","--ff-duration","--ff-column-width","--ff-tray-bg","--ff-tray-radius","--ff-card-bg","--ff-card-ring","--ff-card-radius","--ff-card-shadow","--ff-card-padding","--ff-drag-tilt","--ff-drag-shadow","--ff-placeholder-border"],u=new WeakSet,g=()=>window.Sortable.active||window.Sortable.dragged;function S(){return{isLoading:{},fullyLoaded:{},dragOverColumn:null,railToggledAt:0,dragOverLane:null,dragSource:null,pendingCounts:{},pendingMoves:0,collapsedLanes:{},placeholder:null,stopTrackingPointer:null,init(){this.$wire.$on("kanban-items-loaded",t=>{let{columnId:e,isFullyLoaded:r}=t;r&&(this.fullyLoaded[e]=!0)})},configureSortable(t){if(!t.sortable||t.sortable.options.forceFallback)return;if(g()){this.configureSortableAfterDrag(t);return}let e=window.matchMedia("(prefers-reduced-motion: reduce)").matches;t.sortable.destroy(),t.sortable=window.Sortable.create(t,{draggable:"[x-sortable-item]",handle:"[x-sortable-handle]",dataIdAttr:"x-sortable-item",forceFallback:!0,fallbackTolerance:5,fallbackOnBody:!0,fallbackClass:"",ghostClass:"",delay:150,delayOnTouchOnly:!0,animation:e?0:200,scrollSensitivity:100,scrollSpeed:15,forceAutoScrollFallback:!0,group:{name:t.getAttribute("x-sortable-group"),pull:!0,put:(r,o)=>this.canDrop(r.el,o.el)},onStart:r=>this.startDrag(r),onEnd(r){let{item:o,to:a,oldDraggableIndex:n,newDraggableIndex:i}=r;if(n===i)return;let l=a.querySelectorAll(`:scope > ${this.options.draggable}`)[i-1];l&&a.insertBefore(o,l.nextSibling)}})},configureSortableAfterDrag(t){if(u.has(t))return;u.add(t);let e=()=>{if(g()){requestAnimationFrame(e);return}u.delete(t),t.isConnected&&this.configureSortable(t)};requestAnimationFrame(e)},startDrag(t){this.stopTrackingPointer?.(),this.placeholder=t.item,this.placeholder.setAttribute("data-placeholder",""),this.markGhost(),window.getSelection()?.removeAllRanges(),document.documentElement.classList.add("ff-dragging"),this.dragSource={column:t.from.dataset.columnId,lane:t.from.dataset.laneId??null};let e=r=>this.trackPointer(r);document.addEventListener("pointermove",e,{passive:!0}),document.addEventListener("touchmove",e,{passive:!0}),this.stopTrackingPointer=()=>{document.removeEventListener("pointermove",e),document.removeEventListener("touchmove",e)}},trackPointer(t){if(!window.Sortable.active){this.endDrag();return}this.markGhost();let e=t.touches?.[0]??t,r=document.elementFromPoint(e.clientX,e.clientY),o=r?.closest("[data-column-id]"),a=r?.closest("[data-column-root]");this.dragOverColumn=o?.dataset.columnId??a?.dataset.columnRoot??null,this.dragOverLane=o?.dataset.laneId??null},markGhost(){let t=window.Sortable.ghost;if(!t||t.hasAttribute("data-dragging"))return;t.removeAttribute("data-placeholder"),t.setAttribute("data-dragging",""),t.style.opacity="1";let e=getComputedStyle(this.placeholder);for(let r of C){let o=e.getPropertyValue(r);o!==""&&t.style.setProperty(r,o)}},endDrag(){document.documentElement.classList.remove("ff-dragging"),this.placeholder?.removeAttribute("data-placeholder"),this.placeholder=null,this.stopTrackingPointer?.(),this.stopTrackingPointer=null,this.dragOverColumn=null,this.dragOverLane=null,this.dragSource=null},toggleColumnCollapse(t,e,r=!1){t.target.closest(".ff-column-actions")||r&&t.detail>1||Date.now()-this.railToggledAt<500||(r&&(this.railToggledAt=Date.now()),this.$wire.toggleBoardColumnCollapse(e))},suppressDoubleClickSelection(t){t.detail>1&&!t.target.closest(".ff-column-actions")&&t.preventDefault()},columnDrop(t){return this.dragOverColumn!==t?null:this.isColumnBlocked(t)?"blocked":"active"},cellDrop(t,e){return this.dragOverColumn!==t||this.dragOverLane!==e?null:this.isCellBlocked(t,e)?"blocked":"active"},canDrop(t,e){if(!this.$root.contains(t)||!this.$root.contains(e))return!1;let r=t.dataset.laneId??null,o=e.dataset.laneId??null;return r!==o&&this.$root.dataset.lanesWritable!=="true"?!1:!this.isColumnBlocked(t.dataset.columnId,e.dataset.columnId)},isColumnBlocked(t,e=this.dragSource?.column){if(!t||t===e)return!1;let r=this.$root.querySelector(`[data-column-root="${CSS.escape(t)}"]`),o=r?.dataset.columnLimit;return o===void 0||o===""?!1:Number(r.dataset.columnTotal)>=Number(o)},isCellBlocked(t,e){return this.dragSource?e!==this.dragSource.lane&&this.$root.dataset.lanesWritable!=="true"?!0:this.isColumnBlocked(t):!1},displayCount(t,e){let r=this.pendingCounts[t]??e,o=this.dragSource?.column,a=this.dragOverColumn;return!o||!a||o===a||this.isColumnBlocked(a)?r:t===a?r+1:t===o?r-1:r},holdMovedCounts(t,e){if(t===e)return()=>{};let r={[t]:-1,[e]:1},o=!1;for(let[a,n]of Object.entries(r))this.pendingCounts[a]=this.renderedCount(a)+n;return this.pendingMoves++,a=>{if(!o){if(o=!0,a)for(let[n,i]of Object.entries(r))this.pendingCounts[n]-=i;--this.pendingMoves===0&&(this.pendingCounts={})}}},renderedCount(t){let e=this.$root.querySelector(`[data-column-root="${CSS.escape(t)}"] .ff-count`);return this.pendingCounts[t]??Number(e?.dataset.total)},handleSortableEnd(t){this.endDrag();let e=t.item,r=t.to,o=t.newDraggableIndex??t.newIndex,a=":scope > [x-sortable-item], :scope > [data-card-id]",n=s=>s.getAttribute("x-sortable-item")||s.getAttribute("data-card-id");if(t.from===r&&t.oldDraggableIndex===t.newDraggableIndex)return;if(o===0){let s=r.querySelector(a);s&&s!==e&&r.insertBefore(e,s)}let i=n(e);if(!i){console.error("Flowforge: Could not determine card ID for move operation");return}let l=r.getAttribute("data-column-id");if(!l){console.error("Flowforge: Target column ID is missing");return}let h=t.from.dataset.laneId??null,m=r.dataset.laneId??null,c=r.querySelectorAll(a),d=Array.prototype.indexOf.call(c,e),p=d>0?n(c[d-1]):null,b=d>=0&&d{this.setCardState(e,!1),f(s===!1),s===!1&&this.revertCard(t)}).catch(()=>{this.setCardState(e,!1),f(!0),this.revertCard(t)})},revertCard({item:t,from:e,oldDraggableIndex:r}){t.remove();let o=e.querySelectorAll(":scope > [x-sortable-item]"),a=o[o.length-1],n=o[r]??(a?a.nextSibling:e.firstChild);e.insertBefore(t,n)},setCardState(t,e){t.toggleAttribute("data-pending",e)},isLaneCollapsed(t){return this.collapsedLanes[t]===!0},toggleLane(t){this.collapsedLanes[t]=!this.isLaneCollapsed(t)},isLoadingColumn(t){return this.isLoading[t]||!1},isColumnFullyLoaded(t){return this.fullyLoaded[t]||!1},handleSmoothScroll(t){this.isLoadingColumn(t)||this.isColumnFullyLoaded(t)||(this.isLoading[t]=!0,this.$wire.loadMoreItems(t).then(()=>setTimeout(()=>this.isLoading[t]=!1,100)).catch(()=>this.isLoading[t]=!1))},handleColumnScroll(t,e){if(this.isColumnFullyLoaded(e))return;let{scrollTop:r,scrollHeight:o,clientHeight:a}=t.target;(r+a)/o>=.8&&!this.isLoadingColumn(e)&&this.handleSmoothScroll(e)}}}export{S as default}; diff --git a/resources/js/flowforge-modern.js b/resources/js/flowforge-modern.js index 39ca1e824..c37d69d0f 100644 --- a/resources/js/flowforge-modern.js +++ b/resources/js/flowforge-modern.js @@ -35,6 +35,8 @@ export default function flowforgeModern() { isLoading: {}, fullyLoaded: {}, dragOverColumn: null, + + railToggledAt: 0, dragOverLane: null, dragSource: null, pendingCounts: {}, @@ -213,6 +215,29 @@ export default function flowforgeModern() { this.dragSource = null; }, + toggleColumnCollapse(event, columnId, fromRail = false) { + if (event.target.closest('.ff-column-actions') || (fromRail && event.detail > 1)) { + return; + } + + // The click that expands a rail must not let its double click collapse the header again. + if (Date.now() - this.railToggledAt < 500) { + return; + } + + if (fromRail) { + this.railToggledAt = Date.now(); + } + + this.$wire.toggleBoardColumnCollapse(columnId); + }, + + suppressDoubleClickSelection(event) { + if (event.detail > 1 && !event.target.closest('.ff-column-actions')) { + event.preventDefault(); + } + }, + columnDrop(columnId) { if (this.dragOverColumn !== columnId) { return null; diff --git a/resources/views/modern/livewire/column-header.blade.php b/resources/views/modern/livewire/column-header.blade.php index 0b6c86604..482fea9a5 100644 --- a/resources/views/modern/livewire/column-header.blade.php +++ b/resources/views/modern/livewire/column-header.blade.php @@ -25,8 +25,9 @@
getBoard()->isColumnCollapsible() && ! $isCollapsed) - x-on:dblclick="if (! $event.target.closest('.ff-column-actions')) $wire.toggleBoardColumnCollapse(@js($columnId))" + @if (($column['canToggleCollapse'] ?? false) && ! $isCollapsed) + x-on:dblclick="toggleColumnCollapse($event, @js($columnId))" + x-on:mousedown="suppressDoubleClickSelection($event)" @endif >
diff --git a/resources/views/modern/livewire/column.blade.php b/resources/views/modern/livewire/column.blade.php index 314e54941..fdf9fb033 100644 --- a/resources/views/modern/livewire/column.blade.php +++ b/resources/views/modern/livewire/column.blade.php @@ -21,8 +21,9 @@ class="ff-column" @if (($column['limit'] ?? null) !== null) data-column-limit="{{ $column['limit'] }}" @endif @if ($column['isFull'] ?? false) data-full @endif @if ($isCollapsed) data-collapsed title="{{ $plainLabel }}" @endif - @if ($isCollapsed && $config['collapsible']) - x-on:click="if (! $event.target.closest('.ff-column-actions')) $wire.toggleBoardColumnCollapse(@js((string) $columnId))" + @if ($isCollapsed && ($column['canToggleCollapse'] ?? false)) + x-on:click="toggleColumnCollapse($event, @js((string) $columnId), true)" + x-on:mousedown="suppressDoubleClickSelection($event)" @endif x-bind:data-drop="columnDrop(@js((string) $columnId))" > diff --git a/src/Board.php b/src/Board.php index 89228213a..0e77470ed 100644 --- a/src/Board.php +++ b/src/Board.php @@ -134,26 +134,39 @@ public function getViewData(): array ]; } - public function isColumnCollapsed(string $columnId): bool + /** + * @return array{collapsed: bool, toggleable: bool} + */ + public function getColumnCollapseState(string $columnId): array { return $this->makeCollapseResolver($this->getBatchedBoardRecordCounts())($columnId); } /** * @param array $allCounts - * @return Closure(string): bool + * @return Closure(string): array{collapsed: bool, toggleable: bool} */ protected function makeCollapseResolver(array $allCounts): Closure { - $collapsedIds = $this->getCollapsedColumns(); + $listed = $this->getCollapsedColumns(); + $visible = $this->getColumnIdentifiers(); $collapseAll = $this->collapsesAllColumns(); $collapseEmpty = $this->collapsesEmptyColumns() && $this->getActiveGrouping() === null && array_sum(array_map(fn (Column $column): int => $allCounts[$column->getName()] ?? 0, $this->getColumns())) > 0; - return fn (string $columnId): bool => $collapseAll - || in_array($columnId, $collapsedIds, true) - || ($collapseEmpty && ($allCounts[$columnId] ?? 0) === 0); + return function (string $columnId) use ($listed, $visible, $collapseAll, $collapseEmpty, $allCounts): array { + $byRule = $collapseAll || ($collapseEmpty && ($allCounts[$columnId] ?? 0) === 0); + $isListed = in_array($columnId, $listed, true); + $collapsed = $byRule || $isListed; + + return [ + 'collapsed' => $collapsed, + 'toggleable' => $this->isColumnCollapsible() + && in_array($columnId, $visible, true) + && (! $collapsed || ($isListed && ! $byRule)), + ]; + }; } /** @@ -166,7 +179,7 @@ protected function getColumnViewData(bool $withItems): array $recordsByColumn = $withItems ? $this->getBoardRecordsForColumns(array_values(array_filter( array_map(fn (Column $column): string => $column->getName(), $this->getColumns()), - fn (string $columnId): bool => ! $isCollapsed($columnId), + fn (string $columnId): bool => ! $isCollapsed($columnId)['collapsed'], ))) : []; $columns = []; @@ -176,6 +189,7 @@ protected function getColumnViewData(bool $withItems): array $limit = $column->getLimit(); $limitTotal = $limit === null ? null : $this->getUnfilteredColumnRecordCount($columnId); $total = $allCounts[$columnId] ?? 0; + $state = $isCollapsed($columnId); $columns[$columnId] = [ 'id' => $columnId, @@ -186,7 +200,8 @@ protected function getColumnViewData(bool $withItems): array ? $recordsByColumn[$columnId]->map(fn ($record) => $this->formatBoardRecord($record))->toArray() : [], 'total' => $total, - 'isCollapsed' => $isCollapsed($columnId), + 'isCollapsed' => $state['collapsed'], + 'canToggleCollapse' => $state['toggleable'], 'summary' => $this->getColumnSummary($column), 'limit' => $limit, 'limitTotal' => $limitTotal, diff --git a/src/Concerns/HasColumnControls.php b/src/Concerns/HasColumnControls.php index 23cdd523e..e8b6730d4 100644 --- a/src/Concerns/HasColumnControls.php +++ b/src/Concerns/HasColumnControls.php @@ -73,13 +73,15 @@ public function isColumnCollapsible(): bool public function toggleColumnCollapse(string $columnId): void { - if (! $this->isColumnCollapsible() || ! in_array($columnId, $this->getColumnIdentifiers(), true)) { + $state = $this->getColumnCollapseState($columnId); + + if (! $state['toggleable']) { return; } $this->evaluate($this->toggleColumnCollapse, [ 'columnId' => $columnId, - 'collapsed' => ! $this->isColumnCollapsed($columnId), + 'collapsed' => ! $state['collapsed'], ]); } } diff --git a/src/Modern/Concerns/InteractsWithBoard.php b/src/Modern/Concerns/InteractsWithBoard.php index 4aa2a1c97..8d15e5ea1 100644 --- a/src/Modern/Concerns/InteractsWithBoard.php +++ b/src/Modern/Concerns/InteractsWithBoard.php @@ -123,6 +123,7 @@ public function getBoardCreateCardAction(string $columnId): ?Action public function toggleBoardColumnCollapse(string $columnId): void { $this->getBoard()->toggleColumnCollapse($columnId); + $this->board = $this->board($this->makeBoard()); } protected function canCreateCardIn(mixed $columnId): bool diff --git a/tests/Browser/ModernBoardTest.php b/tests/Browser/ModernBoardTest.php index 783cd7e57..3dbca8c71 100644 --- a/tests/Browser/ModernBoardTest.php +++ b/tests/Browser/ModernBoardTest.php @@ -792,7 +792,8 @@ function boardTraySampler(int $budgetMilliseconds): string $pointer->doubleClick("{$root} .ff-column-title"); $pointer->untilScript("document.querySelector('{$root}').hasAttribute('data-collapsed')"); - expect(boardStyle($page, $root, 'width'))->toBe('48px'); + expect(boardStyle($page, $root, 'width'))->toBe('48px') + ->and($page->script('window.getSelection().toString()'))->toBe(''); $pointer->click($root); $pointer->untilScript("! document.querySelector('{$root}').hasAttribute('data-collapsed')"); @@ -828,3 +829,28 @@ function boardTraySampler(int $budgetMilliseconds): string $pointer->untilEquals(fn () => Task::query()->find($a->id)->status, 'completed', 'the moved card status'); $pointer->untilEquals(fn () => boardStyle($page, $root, 'width'), '48px', 'the rail width after the drop'); }); + +test('double clicking a collapsed rail expands it', function () { + boardSeed(); + $page = boardPage('/modern/test-collapsible-board'); + $pointer = Pointer::on($page); + $root = '[data-column-root="completed"]'; + + $pointer->doubleClick("{$root} .ff-column-title"); + $pointer->untilScript("! document.querySelector('{$root}').hasAttribute('data-collapsed')"); + $pointer->wait(600); + + expect($page->script("document.querySelector('{$root}').hasAttribute('data-collapsed')"))->toBeFalse(); +}); + +test('double clicking the column actions trigger leaves the column expanded', function () { + boardSeed(); + $page = boardPage('/modern/test-collapsible-board'); + $pointer = Pointer::on($page); + $root = '[data-column-root="todo"]'; + + $pointer->doubleClick("{$root} .ff-column-actions .fi-dropdown-trigger button"); + $pointer->wait(600); + + expect($page->script("document.querySelector('{$root}').hasAttribute('data-collapsed')"))->toBeFalse(); +}); diff --git a/tests/Fixtures/Modern/TestBoard.php b/tests/Fixtures/Modern/TestBoard.php index c8e983d00..1e6112f78 100644 --- a/tests/Fixtures/Modern/TestBoard.php +++ b/tests/Fixtures/Modern/TestBoard.php @@ -32,6 +32,8 @@ class TestBoard extends BoardPage public bool $collapsible = false; + public bool $withColumnActions = false; + public array $toggled = []; public bool $withHeaderToolbar = false; @@ -80,7 +82,8 @@ public function board(Board $board): Board ->collapsedColumns(match ($this->collapsedIdsAs) { 'collection' => fn () => collect($this->collapsedIds), 'enum' => fn (): array => [StatusEnum::Active, ...$this->collapsedIds], - default => fn (): array => $this->collapsedIds, + 'closure' => fn (): array => $this->collapsedIds, + default => $this->collapsedIds, }) ->collapseAllColumns($this->collapseAll) ->collapsibleColumns($this->collapsible @@ -92,6 +95,9 @@ public function board(Board $board): Board } : null) ->headerToolbar($this->withHeaderToolbar) + ->columnActions($this->withColumnActions + ? [Action::make('renameColumn')->action(function (): void {}), Action::make('clearColumn')->action(function (): void {})] + : []) ->query($this->getEloquentQuery()) ->recordTitleAttribute('title') ->searchable(['title']) diff --git a/tests/Fixtures/Modern/TestCollapsibleBoard.php b/tests/Fixtures/Modern/TestCollapsibleBoard.php index b68be9dda..b63aa41bc 100644 --- a/tests/Fixtures/Modern/TestCollapsibleBoard.php +++ b/tests/Fixtures/Modern/TestCollapsibleBoard.php @@ -10,5 +10,7 @@ class TestCollapsibleBoard extends TestBoard public bool $withCreateAction = true; + public bool $withColumnActions = true; + public array $collapsedIds = ['completed']; } diff --git a/tests/Modern/Feature/CollapsedColumnsTest.php b/tests/Modern/Feature/CollapsedColumnsTest.php index c65d600ee..63b416be4 100644 --- a/tests/Modern/Feature/CollapsedColumnsTest.php +++ b/tests/Modern/Feature/CollapsedColumnsTest.php @@ -97,13 +97,46 @@ ->and($component->html())->not->toContain('data-collapsed'); }); - test('toggling an empty column that collapses by rule asks the host to expand it', function () { + test('toggling a column that an empty rule collapses is ignored and it stays collapsed', function () { Task::factory()->todo()->create(['title' => 'Only Task']); $component = Livewire::test(TestBoard::class, ['collapsible' => true, 'collapseEmpty' => true]) ->call('toggleBoardColumnCollapse', 'in_progress'); - expect($component->get('toggled'))->toBe([['in_progress', false]]); + expect($component->get('toggled'))->toBe([]) + ->and($component->html())->toMatch('/]*data-column-root="in_progress"[^>]*data-collapsed/'); + }); + + test('toggling under collapse all is ignored and every column stays collapsed', function () { + $component = Livewire::test(TestBoard::class, ['collapsible' => true, 'collapseAll' => true, 'collapsedIds' => ['todo']]) + ->call('toggleBoardColumnCollapse', 'todo') + ->call('toggleBoardColumnCollapse', 'in_progress'); + + expect($component->get('toggled'))->toBe([]) + ->and(substr_count($component->html(), 'data-collapsed'))->toBe(3); + }); + + test('a rail collapsed only by a rule binds no click', function () { + Task::factory()->todo()->create(['title' => 'Only Task']); + + $empty = Livewire::test(TestBoard::class, ['collapsible' => true, 'collapseEmpty' => true])->html(); + $all = Livewire::test(TestBoard::class, ['collapsible' => true, 'collapseAll' => true, 'collapsedIds' => ['todo']])->html(); + + expect($empty)->toContain('data-collapsed') + ->and($empty)->not->toMatch('/]*data-column-root="in_progress"[^>]*x-on:click/') + ->and($all)->toContain('data-collapsed') + ->and($all)->not->toMatch('/]*data-column-root="[a-z_]+"[^>]*x-on:click/') + ->and($all)->not->toContain('x-on:dblclick'); + }); + + test('a toggle shows the new state in the same response for a plain array of ids', function () { + $component = Livewire::test(TestBoard::class, ['collapsible' => true, 'collapsedIds' => ['todo']]) + ->call('toggleBoardColumnCollapse', 'todo') + ->call('toggleBoardColumnCollapse', 'completed'); + + expect($component->get('toggled'))->toBe([['todo', false], ['completed', true]]) + ->and(substr_count($component->html(), 'data-collapsed'))->toBe(1) + ->and($component->html())->toMatch('/]*data-column-root="completed"[^>]*data-collapsed/'); }); test('toggle ignores unknown and hidden columns', function () { From 17542101262a512a1aa20fc7da53359625ec2bf4 Mon Sep 17 00:00:00 2001 From: Manuk Date: Sat, 14 Nov 2026 03:22:08 +0400 Subject: [PATCH 05/34] feat(columns): open a host menu from the column header --- docs/content/2.essentials/2.customization.md | 25 +++++++ docs/content/2.essentials/4.api-reference.md | 2 + resources/css/flowforge-modern.css | 18 +++++ resources/dist/flowforge-modern.js | 2 +- resources/js/flowforge-modern.js | 39 +++++++++- .../modern/livewire/column-header.blade.php | 58 +++++++------- .../modern/livewire/column-heading.blade.php | 30 ++++++++ src/Concerns/HasColumnControls.php | 27 +++++++ src/FlowforgeServiceProvider.php | 1 + tests/Browser/ModernBoardTest.php | 50 +++++++++++++ tests/Fixtures/Modern/ModernPanelProvider.php | 1 + tests/Fixtures/Modern/TestBoard.php | 17 ++++- tests/Fixtures/Modern/TestMenuBoard.php | 10 +++ tests/Modern/Feature/ColumnHeaderMenuTest.php | 75 +++++++++++++++++++ 14 files changed, 324 insertions(+), 31 deletions(-) create mode 100644 resources/views/modern/livewire/column-heading.blade.php create mode 100644 tests/Fixtures/Modern/TestMenuBoard.php create mode 100644 tests/Modern/Feature/ColumnHeaderMenuTest.php diff --git a/docs/content/2.essentials/2.customization.md b/docs/content/2.essentials/2.customization.md index fa7b7e7f3..0aca6fa7f 100644 --- a/docs/content/2.essentials/2.customization.md +++ b/docs/content/2.essentials/2.customization.md @@ -331,6 +331,31 @@ Only a column listed in `collapsedColumns()` can be expanded from its rail. A co for it never reaches your closure. Flowforge rebuilds the board after your closure runs. Still, pass a value your page changes during a request as a closure, as above, so every read sees the new state. +### Open a menu from the column header + +`columnHeaderMenu()` turns the column heading into a menu trigger. Your closure receives the column +as an array and returns the block the panel shows first. The panel then lists the column's visible +actions from `columnActions()`, so the separate actions button goes away. The add card button stays +in the header. + +```php +use Illuminate\Support\HtmlString; + +->columnHeaderMenu(fn (array $column): ?HtmlString => new HtmlString( + view('boards.stage-settings', ['stage' => $column['id']])->render(), +)) +``` + +A click opens the menu at once. A press that moves more than 4px before release is a header drag, +so it does not open the menu. With `collapsibleColumns()`, a double-click closes the menu and +collapses the column. Double-clicks inside the panel and on inputs, textareas, selects and editable +content never collapse it, so a word in your block's inputs can be selected. Return `null` for no +block. A column with no block and no visible actions renders a plain header, and a collapsed +column has no menu. + +The trigger is a `div` with `role="button"`, not a `button`, so a drag handle that filters out +buttons still grabs the header. + ## Search and Filtering Enable powerful search and filtering capabilities: diff --git a/docs/content/2.essentials/4.api-reference.md b/docs/content/2.essentials/4.api-reference.md index a9b9e817d..fe36a8708 100644 --- a/docs/content/2.essentials/4.api-reference.md +++ b/docs/content/2.essentials/4.api-reference.md @@ -31,6 +31,7 @@ navigation: | `collapsedColumns(array\|Closure)` | Collapse the listed column ids into a rail. Unknown and hidden ids are ignored | | | `collapseAllColumns(bool\|Closure)` | Collapse every visible column into a rail | | | `collapsibleColumns(?Closure)` | Let users toggle a column by double-clicking its header or clicking its rail. Only columns listed in `collapsedColumns()` expand from the rail. The closure receives `string $columnId` and `bool $collapsed` (the new state) | | +| `columnHeaderMenu(?Closure)` | Turn the column heading into a menu trigger. The closure receives `array $column` and returns an `Htmlable` block, or `null` for none. The panel holds the block, then the column actions as list items | | ## Board Methods @@ -144,6 +145,7 @@ use Filament\Support\Enums\Width; ->collapsedColumns(['won', 'lost']) // Collapse the listed columns ->collapseAllColumns() // Collapse every column ->collapsibleColumns(fn (string $columnId, bool $collapsed) => ...) // Toggle from the header and the rail +->columnHeaderMenu(fn (array $column) => new HtmlString('...')) // Open a host block and the column actions from the heading ``` ### Modern board additions diff --git a/resources/css/flowforge-modern.css b/resources/css/flowforge-modern.css index 0fb809661..cb611902f 100644 --- a/resources/css/flowforge-modern.css +++ b/resources/css/flowforge-modern.css @@ -266,6 +266,24 @@ white-space: nowrap; } + .ff-column-menu { + flex: 1 1 auto; + min-width: 0; + } + + .ff-column-menu > .fi-dropdown-trigger { + display: block; + min-width: 0; + } + + .ff-column-menu .ff-column-heading { + cursor: pointer; + } + + .ff-column-menu-block { + padding: 0.5rem 0.75rem; + } + .ff-column-actions { display: flex; flex-shrink: 0; diff --git a/resources/dist/flowforge-modern.js b/resources/dist/flowforge-modern.js index 43663a70f..e68f01635 100644 --- a/resources/dist/flowforge-modern.js +++ b/resources/dist/flowforge-modern.js @@ -1 +1 @@ -var C=["--ff-surface","--ff-surface-sunken","--ff-surface-raised","--ff-border","--ff-text","--ff-text-muted","--ff-accent","--ff-accent-tint","--ff-danger","--ff-warning","--ff-radius","--ff-gap","--ff-ease","--ff-duration","--ff-column-width","--ff-tray-bg","--ff-tray-radius","--ff-card-bg","--ff-card-ring","--ff-card-radius","--ff-card-shadow","--ff-card-padding","--ff-drag-tilt","--ff-drag-shadow","--ff-placeholder-border"],u=new WeakSet,g=()=>window.Sortable.active||window.Sortable.dragged;function S(){return{isLoading:{},fullyLoaded:{},dragOverColumn:null,railToggledAt:0,dragOverLane:null,dragSource:null,pendingCounts:{},pendingMoves:0,collapsedLanes:{},placeholder:null,stopTrackingPointer:null,init(){this.$wire.$on("kanban-items-loaded",t=>{let{columnId:e,isFullyLoaded:r}=t;r&&(this.fullyLoaded[e]=!0)})},configureSortable(t){if(!t.sortable||t.sortable.options.forceFallback)return;if(g()){this.configureSortableAfterDrag(t);return}let e=window.matchMedia("(prefers-reduced-motion: reduce)").matches;t.sortable.destroy(),t.sortable=window.Sortable.create(t,{draggable:"[x-sortable-item]",handle:"[x-sortable-handle]",dataIdAttr:"x-sortable-item",forceFallback:!0,fallbackTolerance:5,fallbackOnBody:!0,fallbackClass:"",ghostClass:"",delay:150,delayOnTouchOnly:!0,animation:e?0:200,scrollSensitivity:100,scrollSpeed:15,forceAutoScrollFallback:!0,group:{name:t.getAttribute("x-sortable-group"),pull:!0,put:(r,o)=>this.canDrop(r.el,o.el)},onStart:r=>this.startDrag(r),onEnd(r){let{item:o,to:a,oldDraggableIndex:n,newDraggableIndex:i}=r;if(n===i)return;let l=a.querySelectorAll(`:scope > ${this.options.draggable}`)[i-1];l&&a.insertBefore(o,l.nextSibling)}})},configureSortableAfterDrag(t){if(u.has(t))return;u.add(t);let e=()=>{if(g()){requestAnimationFrame(e);return}u.delete(t),t.isConnected&&this.configureSortable(t)};requestAnimationFrame(e)},startDrag(t){this.stopTrackingPointer?.(),this.placeholder=t.item,this.placeholder.setAttribute("data-placeholder",""),this.markGhost(),window.getSelection()?.removeAllRanges(),document.documentElement.classList.add("ff-dragging"),this.dragSource={column:t.from.dataset.columnId,lane:t.from.dataset.laneId??null};let e=r=>this.trackPointer(r);document.addEventListener("pointermove",e,{passive:!0}),document.addEventListener("touchmove",e,{passive:!0}),this.stopTrackingPointer=()=>{document.removeEventListener("pointermove",e),document.removeEventListener("touchmove",e)}},trackPointer(t){if(!window.Sortable.active){this.endDrag();return}this.markGhost();let e=t.touches?.[0]??t,r=document.elementFromPoint(e.clientX,e.clientY),o=r?.closest("[data-column-id]"),a=r?.closest("[data-column-root]");this.dragOverColumn=o?.dataset.columnId??a?.dataset.columnRoot??null,this.dragOverLane=o?.dataset.laneId??null},markGhost(){let t=window.Sortable.ghost;if(!t||t.hasAttribute("data-dragging"))return;t.removeAttribute("data-placeholder"),t.setAttribute("data-dragging",""),t.style.opacity="1";let e=getComputedStyle(this.placeholder);for(let r of C){let o=e.getPropertyValue(r);o!==""&&t.style.setProperty(r,o)}},endDrag(){document.documentElement.classList.remove("ff-dragging"),this.placeholder?.removeAttribute("data-placeholder"),this.placeholder=null,this.stopTrackingPointer?.(),this.stopTrackingPointer=null,this.dragOverColumn=null,this.dragOverLane=null,this.dragSource=null},toggleColumnCollapse(t,e,r=!1){t.target.closest(".ff-column-actions")||r&&t.detail>1||Date.now()-this.railToggledAt<500||(r&&(this.railToggledAt=Date.now()),this.$wire.toggleBoardColumnCollapse(e))},suppressDoubleClickSelection(t){t.detail>1&&!t.target.closest(".ff-column-actions")&&t.preventDefault()},columnDrop(t){return this.dragOverColumn!==t?null:this.isColumnBlocked(t)?"blocked":"active"},cellDrop(t,e){return this.dragOverColumn!==t||this.dragOverLane!==e?null:this.isCellBlocked(t,e)?"blocked":"active"},canDrop(t,e){if(!this.$root.contains(t)||!this.$root.contains(e))return!1;let r=t.dataset.laneId??null,o=e.dataset.laneId??null;return r!==o&&this.$root.dataset.lanesWritable!=="true"?!1:!this.isColumnBlocked(t.dataset.columnId,e.dataset.columnId)},isColumnBlocked(t,e=this.dragSource?.column){if(!t||t===e)return!1;let r=this.$root.querySelector(`[data-column-root="${CSS.escape(t)}"]`),o=r?.dataset.columnLimit;return o===void 0||o===""?!1:Number(r.dataset.columnTotal)>=Number(o)},isCellBlocked(t,e){return this.dragSource?e!==this.dragSource.lane&&this.$root.dataset.lanesWritable!=="true"?!0:this.isColumnBlocked(t):!1},displayCount(t,e){let r=this.pendingCounts[t]??e,o=this.dragSource?.column,a=this.dragOverColumn;return!o||!a||o===a||this.isColumnBlocked(a)?r:t===a?r+1:t===o?r-1:r},holdMovedCounts(t,e){if(t===e)return()=>{};let r={[t]:-1,[e]:1},o=!1;for(let[a,n]of Object.entries(r))this.pendingCounts[a]=this.renderedCount(a)+n;return this.pendingMoves++,a=>{if(!o){if(o=!0,a)for(let[n,i]of Object.entries(r))this.pendingCounts[n]-=i;--this.pendingMoves===0&&(this.pendingCounts={})}}},renderedCount(t){let e=this.$root.querySelector(`[data-column-root="${CSS.escape(t)}"] .ff-count`);return this.pendingCounts[t]??Number(e?.dataset.total)},handleSortableEnd(t){this.endDrag();let e=t.item,r=t.to,o=t.newDraggableIndex??t.newIndex,a=":scope > [x-sortable-item], :scope > [data-card-id]",n=s=>s.getAttribute("x-sortable-item")||s.getAttribute("data-card-id");if(t.from===r&&t.oldDraggableIndex===t.newDraggableIndex)return;if(o===0){let s=r.querySelector(a);s&&s!==e&&r.insertBefore(e,s)}let i=n(e);if(!i){console.error("Flowforge: Could not determine card ID for move operation");return}let l=r.getAttribute("data-column-id");if(!l){console.error("Flowforge: Target column ID is missing");return}let h=t.from.dataset.laneId??null,m=r.dataset.laneId??null,c=r.querySelectorAll(a),d=Array.prototype.indexOf.call(c,e),p=d>0?n(c[d-1]):null,b=d>=0&&d{this.setCardState(e,!1),f(s===!1),s===!1&&this.revertCard(t)}).catch(()=>{this.setCardState(e,!1),f(!0),this.revertCard(t)})},revertCard({item:t,from:e,oldDraggableIndex:r}){t.remove();let o=e.querySelectorAll(":scope > [x-sortable-item]"),a=o[o.length-1],n=o[r]??(a?a.nextSibling:e.firstChild);e.insertBefore(t,n)},setCardState(t,e){t.toggleAttribute("data-pending",e)},isLaneCollapsed(t){return this.collapsedLanes[t]===!0},toggleLane(t){this.collapsedLanes[t]=!this.isLaneCollapsed(t)},isLoadingColumn(t){return this.isLoading[t]||!1},isColumnFullyLoaded(t){return this.fullyLoaded[t]||!1},handleSmoothScroll(t){this.isLoadingColumn(t)||this.isColumnFullyLoaded(t)||(this.isLoading[t]=!0,this.$wire.loadMoreItems(t).then(()=>setTimeout(()=>this.isLoading[t]=!1,100)).catch(()=>this.isLoading[t]=!1))},handleColumnScroll(t,e){if(this.isColumnFullyLoaded(e))return;let{scrollTop:r,scrollHeight:o,clientHeight:a}=t.target;(r+a)/o>=.8&&!this.isLoadingColumn(e)&&this.handleSmoothScroll(e)}}}export{S as default}; +var S=["--ff-surface","--ff-surface-sunken","--ff-surface-raised","--ff-border","--ff-text","--ff-text-muted","--ff-accent","--ff-accent-tint","--ff-danger","--ff-warning","--ff-radius","--ff-gap","--ff-ease","--ff-duration","--ff-column-width","--ff-tray-bg","--ff-tray-radius","--ff-card-bg","--ff-card-ring","--ff-card-radius","--ff-card-shadow","--ff-card-padding","--ff-drag-tilt","--ff-drag-shadow","--ff-placeholder-border"],g='.ff-column-actions, .fi-dropdown-panel, input, textarea, select, [contenteditable]:not([contenteditable="false"])';var u=new WeakSet,h=()=>window.Sortable.active||window.Sortable.dragged;function w(){return{isLoading:{},fullyLoaded:{},dragOverColumn:null,railToggledAt:0,columnMenuPressAt:null,dragOverLane:null,dragSource:null,pendingCounts:{},pendingMoves:0,collapsedLanes:{},placeholder:null,stopTrackingPointer:null,init(){this.$wire.$on("kanban-items-loaded",e=>{let{columnId:t,isFullyLoaded:r}=e;r&&(this.fullyLoaded[t]=!0)})},configureSortable(e){if(!e.sortable||e.sortable.options.forceFallback)return;if(h()){this.configureSortableAfterDrag(e);return}let t=window.matchMedia("(prefers-reduced-motion: reduce)").matches;e.sortable.destroy(),e.sortable=window.Sortable.create(e,{draggable:"[x-sortable-item]",handle:"[x-sortable-handle]",dataIdAttr:"x-sortable-item",forceFallback:!0,fallbackTolerance:5,fallbackOnBody:!0,fallbackClass:"",ghostClass:"",delay:150,delayOnTouchOnly:!0,animation:t?0:200,scrollSensitivity:100,scrollSpeed:15,forceAutoScrollFallback:!0,group:{name:e.getAttribute("x-sortable-group"),pull:!0,put:(r,o)=>this.canDrop(r.el,o.el)},onStart:r=>this.startDrag(r),onEnd(r){let{item:o,to:n,oldDraggableIndex:a,newDraggableIndex:i}=r;if(a===i)return;let l=n.querySelectorAll(`:scope > ${this.options.draggable}`)[i-1];l&&n.insertBefore(o,l.nextSibling)}})},configureSortableAfterDrag(e){if(u.has(e))return;u.add(e);let t=()=>{if(h()){requestAnimationFrame(t);return}u.delete(e),e.isConnected&&this.configureSortable(e)};requestAnimationFrame(t)},startDrag(e){this.stopTrackingPointer?.(),this.placeholder=e.item,this.placeholder.setAttribute("data-placeholder",""),this.markGhost(),window.getSelection()?.removeAllRanges(),document.documentElement.classList.add("ff-dragging"),this.dragSource={column:e.from.dataset.columnId,lane:e.from.dataset.laneId??null};let t=r=>this.trackPointer(r);document.addEventListener("pointermove",t,{passive:!0}),document.addEventListener("touchmove",t,{passive:!0}),this.stopTrackingPointer=()=>{document.removeEventListener("pointermove",t),document.removeEventListener("touchmove",t)}},trackPointer(e){if(!window.Sortable.active){this.endDrag();return}this.markGhost();let t=e.touches?.[0]??e,r=document.elementFromPoint(t.clientX,t.clientY),o=r?.closest("[data-column-id]"),n=r?.closest("[data-column-root]");this.dragOverColumn=o?.dataset.columnId??n?.dataset.columnRoot??null,this.dragOverLane=o?.dataset.laneId??null},markGhost(){let e=window.Sortable.ghost;if(!e||e.hasAttribute("data-dragging"))return;e.removeAttribute("data-placeholder"),e.setAttribute("data-dragging",""),e.style.opacity="1";let t=getComputedStyle(this.placeholder);for(let r of S){let o=t.getPropertyValue(r);o!==""&&e.style.setProperty(r,o)}},endDrag(){document.documentElement.classList.remove("ff-dragging"),this.placeholder?.removeAttribute("data-placeholder"),this.placeholder=null,this.stopTrackingPointer?.(),this.stopTrackingPointer=null,this.dragOverColumn=null,this.dragOverLane=null,this.dragSource=null},toggleColumnCollapse(e,t,r=!1){e.target.closest(g)||r&&e.detail>1||Date.now()-this.railToggledAt<500||(r&&(this.railToggledAt=Date.now()),this.$wire.toggleBoardColumnCollapse(t))},suppressDoubleClickSelection(e){e.detail>1&&!e.target.closest(g)&&e.preventDefault()},initColumnMenu(e){let t=window.Alpine.$data(e.closest(".fi-dropdown"));if(t.ignoresMousedownToggle)return;let r=t.toggle.bind(t);t.ignoresMousedownToggle=!0,t.toggle=o=>o?.type==="mousedown"?void 0:r(o)},columnMenuPress(e){this.columnMenuPressAt={x:e.clientX,y:e.clientY}},columnMenuClick(e){let t=this.columnMenuPressAt;this.columnMenuPressAt=null,!(t&&Math.hypot(e.clientX-t.x,e.clientY-t.y)>4)&&window.Alpine.$data(e.currentTarget.closest(".fi-dropdown")).toggle(e)},columnDrop(e){return this.dragOverColumn!==e?null:this.isColumnBlocked(e)?"blocked":"active"},cellDrop(e,t){return this.dragOverColumn!==e||this.dragOverLane!==t?null:this.isCellBlocked(e,t)?"blocked":"active"},canDrop(e,t){if(!this.$root.contains(e)||!this.$root.contains(t))return!1;let r=e.dataset.laneId??null,o=t.dataset.laneId??null;return r!==o&&this.$root.dataset.lanesWritable!=="true"?!1:!this.isColumnBlocked(e.dataset.columnId,t.dataset.columnId)},isColumnBlocked(e,t=this.dragSource?.column){if(!e||e===t)return!1;let r=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"]`),o=r?.dataset.columnLimit;return o===void 0||o===""?!1:Number(r.dataset.columnTotal)>=Number(o)},isCellBlocked(e,t){return this.dragSource?t!==this.dragSource.lane&&this.$root.dataset.lanesWritable!=="true"?!0:this.isColumnBlocked(e):!1},displayCount(e,t){let r=this.pendingCounts[e]??t,o=this.dragSource?.column,n=this.dragOverColumn;return!o||!n||o===n||this.isColumnBlocked(n)?r:e===n?r+1:e===o?r-1:r},holdMovedCounts(e,t){if(e===t)return()=>{};let r={[e]:-1,[t]:1},o=!1;for(let[n,a]of Object.entries(r))this.pendingCounts[n]=this.renderedCount(n)+a;return this.pendingMoves++,n=>{if(!o){if(o=!0,n)for(let[a,i]of Object.entries(r))this.pendingCounts[a]-=i;--this.pendingMoves===0&&(this.pendingCounts={})}}},renderedCount(e){let t=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"] .ff-count`);return this.pendingCounts[e]??Number(t?.dataset.total)},handleSortableEnd(e){this.endDrag();let t=e.item,r=e.to,o=e.newDraggableIndex??e.newIndex,n=":scope > [x-sortable-item], :scope > [data-card-id]",a=s=>s.getAttribute("x-sortable-item")||s.getAttribute("data-card-id");if(e.from===r&&e.oldDraggableIndex===e.newDraggableIndex)return;if(o===0){let s=r.querySelector(n);s&&s!==t&&r.insertBefore(t,s)}let i=a(t);if(!i){console.error("Flowforge: Could not determine card ID for move operation");return}let l=r.getAttribute("data-column-id");if(!l){console.error("Flowforge: Target column ID is missing");return}let m=e.from.dataset.laneId??null,p=r.dataset.laneId??null,c=r.querySelectorAll(n),d=Array.prototype.indexOf.call(c,t),b=d>0?a(c[d-1]):null,C=d>=0&&d{this.setCardState(t,!1),f(s===!1),s===!1&&this.revertCard(e)}).catch(()=>{this.setCardState(t,!1),f(!0),this.revertCard(e)})},revertCard({item:e,from:t,oldDraggableIndex:r}){e.remove();let o=t.querySelectorAll(":scope > [x-sortable-item]"),n=o[o.length-1],a=o[r]??(n?n.nextSibling:t.firstChild);t.insertBefore(e,a)},setCardState(e,t){e.toggleAttribute("data-pending",t)},isLaneCollapsed(e){return this.collapsedLanes[e]===!0},toggleLane(e){this.collapsedLanes[e]=!this.isLaneCollapsed(e)},isLoadingColumn(e){return this.isLoading[e]||!1},isColumnFullyLoaded(e){return this.fullyLoaded[e]||!1},handleSmoothScroll(e){this.isLoadingColumn(e)||this.isColumnFullyLoaded(e)||(this.isLoading[e]=!0,this.$wire.loadMoreItems(e).then(()=>setTimeout(()=>this.isLoading[e]=!1,100)).catch(()=>this.isLoading[e]=!1))},handleColumnScroll(e,t){if(this.isColumnFullyLoaded(t))return;let{scrollTop:r,scrollHeight:o,clientHeight:n}=e.target;(r+n)/o>=.8&&!this.isLoadingColumn(t)&&this.handleSmoothScroll(t)}}}export{w as default}; diff --git a/resources/js/flowforge-modern.js b/resources/js/flowforge-modern.js index c37d69d0f..e2c61a67c 100644 --- a/resources/js/flowforge-modern.js +++ b/resources/js/flowforge-modern.js @@ -26,6 +26,10 @@ const FLOWFORGE_TOKENS = [ '--ff-placeholder-border', ]; +const HEADER_GESTURE_IGNORED = '.ff-column-actions, .fi-dropdown-panel, input, textarea, select, [contenteditable]:not([contenteditable="false"])'; + +const MENU_DRAG_THRESHOLD = 4; + const sortablesAwaitingDrag = new WeakSet(); const sortableIsBusy = () => window.Sortable.active || window.Sortable.dragged; @@ -37,6 +41,7 @@ export default function flowforgeModern() { dragOverColumn: null, railToggledAt: 0, + columnMenuPressAt: null, dragOverLane: null, dragSource: null, pendingCounts: {}, @@ -216,7 +221,7 @@ export default function flowforgeModern() { }, toggleColumnCollapse(event, columnId, fromRail = false) { - if (event.target.closest('.ff-column-actions') || (fromRail && event.detail > 1)) { + if (event.target.closest(HEADER_GESTURE_IGNORED) || (fromRail && event.detail > 1)) { return; } @@ -233,11 +238,41 @@ export default function flowforgeModern() { }, suppressDoubleClickSelection(event) { - if (event.detail > 1 && !event.target.closest('.ff-column-actions')) { + if (event.detail > 1 && !event.target.closest(HEADER_GESTURE_IGNORED)) { event.preventDefault(); } }, + // Filament opens a dropdown on mousedown, which would open the menu at the start of a header drag. + initColumnMenu(trigger) { + const dropdown = window.Alpine.$data(trigger.closest('.fi-dropdown')); + + if (dropdown.ignoresMousedownToggle) { + return; + } + + const toggle = dropdown.toggle.bind(dropdown); + + dropdown.ignoresMousedownToggle = true; + dropdown.toggle = (event) => (event?.type === 'mousedown' ? undefined : toggle(event)); + }, + + columnMenuPress(event) { + this.columnMenuPressAt = { x: event.clientX, y: event.clientY }; + }, + + columnMenuClick(event) { + const press = this.columnMenuPressAt; + + this.columnMenuPressAt = null; + + if (press && Math.hypot(event.clientX - press.x, event.clientY - press.y) > MENU_DRAG_THRESHOLD) { + return; + } + + window.Alpine.$data(event.currentTarget.closest('.fi-dropdown')).toggle(event); + }, + columnDrop(columnId) { if (this.dragOverColumn !== columnId) { return null; diff --git a/resources/views/modern/livewire/column-header.blade.php b/resources/views/modern/livewire/column-header.blade.php index 482fea9a5..84ccc519a 100644 --- a/resources/views/modern/livewire/column-header.blade.php +++ b/resources/views/modern/livewire/column-header.blade.php @@ -3,12 +3,11 @@ @php use Filament\Actions\Action; use Filament\Actions\ActionGroup; - use Filament\Support\Enums\IconSize; - use Relaticle\Flowforge\Support\ColorResolver; - use function Filament\Support\get_color_css_variables; $actions = array_values(array_filter($this->getBoardColumnActions($columnId), fn (Action | ActionGroup $action): bool => $action->isVisible())); - $dotColor = ColorResolver::resolve($column['color'] ?? null); + $menuBlock = $isCollapsed ? null : $this->getBoard()->getColumnHeaderMenuBlock($column); + $menuActions = $this->getBoard()->hasColumnHeaderMenu() && ! $isCollapsed ? $actions : []; + $hasMenu = $menuBlock || $menuActions; $createAction = $this->getBoardCreateCardAction($columnId) ?->getClone() ->iconButton() @@ -30,34 +29,43 @@ class="ff-column-header" x-on:mousedown="suppressDoubleClickSelection($event)" @endif > -
- @if ($dotColor) - - @endif + @if ($hasMenu) + + + + - @if ($column['icon'] ?? null) - - @endif - -

{{ $column['label'] }}

- - + @if ($menuBlock) +
{{ $menuBlock }}
+ @endif - @if (! $isCollapsed && filled($column['summary'] ?? null)) - {{ $column['summary'] }} - @endif -
+ @if ($menuActions) + + @foreach ($menuActions as $menuAction) + {{ $menuAction->grouped() }} + @endforeach + + @endif + + @else + + @endif - @if($createAction || count($actions) > 0) + @if ($createAction || (! $hasMenu && count($actions) > 0))
{{ $createAction }} - @if(count($actions) === 1) + @if (! $hasMenu && count($actions) === 1) {{ $actions[0] }} - @elseif(count($actions) > 1) + @elseif (! $hasMenu && count($actions) > 1) @endif
diff --git a/resources/views/modern/livewire/column-heading.blade.php b/resources/views/modern/livewire/column-heading.blade.php new file mode 100644 index 000000000..fd3e84234 --- /dev/null +++ b/resources/views/modern/livewire/column-heading.blade.php @@ -0,0 +1,30 @@ +@props(['columnId', 'column', 'isCollapsed' => false]) + +@php + use Filament\Support\Enums\IconSize; + use Relaticle\Flowforge\Support\ColorResolver; + use function Filament\Support\get_color_css_variables; + + $dotColor = ColorResolver::resolve($column['color'] ?? null); +@endphp + +
class(['ff-column-heading']) }}> + @if ($dotColor) + + @endif + + @if ($column['icon'] ?? null) + + @endif + +

{{ $column['label'] }}

+ + + + @if (! $isCollapsed && filled($column['summary'] ?? null)) + {{ $column['summary'] }} + @endif +
diff --git a/src/Concerns/HasColumnControls.php b/src/Concerns/HasColumnControls.php index e8b6730d4..b4def3eff 100644 --- a/src/Concerns/HasColumnControls.php +++ b/src/Concerns/HasColumnControls.php @@ -7,6 +7,7 @@ use BackedEnum; use Closure; use Illuminate\Contracts\Support\Arrayable; +use Illuminate\Contracts\Support\Htmlable; use Relaticle\Flowforge\Column; trait HasColumnControls @@ -18,6 +19,8 @@ trait HasColumnControls protected ?Closure $toggleColumnCollapse = null; + protected ?Closure $columnHeaderMenu = null; + /** * @param array|Closure $columnIds */ @@ -84,4 +87,28 @@ public function toggleColumnCollapse(string $columnId): void 'collapsed' => ! $state['collapsed'], ]); } + + public function columnHeaderMenu(?Closure $using): static + { + $this->columnHeaderMenu = $using; + + return $this; + } + + public function hasColumnHeaderMenu(): bool + { + return $this->columnHeaderMenu instanceof Closure; + } + + /** + * @param array $column + */ + public function getColumnHeaderMenuBlock(array $column): ?Htmlable + { + if (! $this->columnHeaderMenu instanceof Closure) { + return null; + } + + return $this->evaluate($this->columnHeaderMenu, ['column' => $column]); + } } diff --git a/src/FlowforgeServiceProvider.php b/src/FlowforgeServiceProvider.php index c577b7b06..22b56a8ac 100644 --- a/src/FlowforgeServiceProvider.php +++ b/src/FlowforgeServiceProvider.php @@ -127,6 +127,7 @@ private function registerBladeComponents(): void Blade::component('flowforge::modern.livewire.column', 'flowforge::modern.column'); Blade::component('flowforge::modern.livewire.column-header', 'flowforge::modern.column-header'); + Blade::component('flowforge::modern.livewire.column-heading', 'flowforge::modern.column-heading'); Blade::component('flowforge::modern.livewire.card', 'flowforge::modern.card'); Blade::component('flowforge::modern.livewire.column-count', 'flowforge::modern.column-count'); Blade::component('flowforge::modern.livewire.add-card-row', 'flowforge::modern.add-card-row'); diff --git a/tests/Browser/ModernBoardTest.php b/tests/Browser/ModernBoardTest.php index 3dbca8c71..7de204e29 100644 --- a/tests/Browser/ModernBoardTest.php +++ b/tests/Browser/ModernBoardTest.php @@ -854,3 +854,53 @@ function boardTraySampler(int $budgetMilliseconds): string expect($page->script("document.querySelector('{$root}').hasAttribute('data-collapsed')"))->toBeFalse(); }); + +test('clicking a header opens its menu at once', function () { + boardSeed(); + $page = boardPage('/modern/test-menu-board'); + $pointer = Pointer::on($page); + $root = '[data-column-root="todo"]'; + + $pointer->click("{$root} .ff-column-heading"); + $pointer->untilScript("document.querySelector('{$root} .fi-dropdown-panel').style.display === 'block'"); + + expect($page->script("document.querySelector('{$root} .fi-dropdown-panel').innerText"))->toContain('Block for To Do')->toContain('Archive column'); +}); + +test('double clicking a header with a menu closes the menu and collapses the column', function () { + boardSeed(); + $page = boardPage('/modern/test-menu-board'); + $pointer = Pointer::on($page); + $root = '[data-column-root="todo"]'; + + $pointer->doubleClick("{$root} .ff-column-heading"); + $pointer->untilScript("document.querySelector('{$root}').hasAttribute('data-collapsed')"); + + expect($page->script("document.querySelectorAll('.fi-dropdown-panel[style*=\"display: block\"]').length"))->toBe(0); +}); + +test('releasing a header drag does not open the menu', function () { + boardSeed(); + $page = boardPage('/modern/test-menu-board'); + $pointer = Pointer::on($page); + $root = '[data-column-root="todo"]'; + + $pointer->press("{$root} .ff-column-heading")->nudge(40, 0)->release()->wait(400); + + expect($page->script("document.querySelector('{$root} .fi-dropdown-panel').style.display"))->not->toBe('block'); +}); + +test('double clicking a word in the menu input selects it and leaves the column expanded', function () { + boardSeed(); + $page = boardPage('/modern/test-menu-board'); + $pointer = Pointer::on($page); + $root = '[data-column-root="todo"]'; + + $pointer->click("{$root} .ff-column-heading"); + $pointer->untilScript("document.querySelector('{$root} .fi-dropdown-panel').style.display === 'block'"); + $pointer->doubleClick("{$root} .ff-test-menu-input"); + $pointer->wait(600); + + expect($page->script('document.activeElement.value.substring(document.activeElement.selectionStart, document.activeElement.selectionEnd)'))->toBe('Backlog') + ->and($page->script("document.querySelector('{$root}').hasAttribute('data-collapsed')"))->toBeFalse(); +}); diff --git a/tests/Fixtures/Modern/ModernPanelProvider.php b/tests/Fixtures/Modern/ModernPanelProvider.php index bec9ddc43..306e0a6d2 100644 --- a/tests/Fixtures/Modern/ModernPanelProvider.php +++ b/tests/Fixtures/Modern/ModernPanelProvider.php @@ -31,6 +31,7 @@ public function panel(Panel $panel): Panel TestBrowserBoard::class, TestClassicBoard::class, TestCollapsibleBoard::class, + TestMenuBoard::class, TestContractBoard::class, TestGroupedBoard::class, TestCardActionBoard::class, diff --git a/tests/Fixtures/Modern/TestBoard.php b/tests/Fixtures/Modern/TestBoard.php index 1e6112f78..6ff433812 100644 --- a/tests/Fixtures/Modern/TestBoard.php +++ b/tests/Fixtures/Modern/TestBoard.php @@ -34,6 +34,10 @@ class TestBoard extends BoardPage public bool $withColumnActions = false; + public bool $withHeaderMenu = false; + + public bool $nullMenuBlock = false; + public array $toggled = []; public bool $withHeaderToolbar = false; @@ -95,9 +99,16 @@ public function board(Board $board): Board } : null) ->headerToolbar($this->withHeaderToolbar) - ->columnActions($this->withColumnActions - ? [Action::make('renameColumn')->action(function (): void {}), Action::make('clearColumn')->action(function (): void {})] - : []) + ->columnActions(match (true) { + $this->withHeaderMenu => [Action::make('archiveColumn')->label('Archive column')->action(function (): void {})], + $this->withColumnActions => [Action::make('renameColumn')->action(function (): void {}), Action::make('clearColumn')->action(function (): void {})], + default => [], + }) + ->columnHeaderMenu($this->withHeaderMenu + ? fn (array $column): ?HtmlString => $this->nullMenuBlock + ? null + : new HtmlString('
Block for ' . $column['label'] . '
') + : null) ->query($this->getEloquentQuery()) ->recordTitleAttribute('title') ->searchable(['title']) diff --git a/tests/Fixtures/Modern/TestMenuBoard.php b/tests/Fixtures/Modern/TestMenuBoard.php new file mode 100644 index 000000000..fd4465ca1 --- /dev/null +++ b/tests/Fixtures/Modern/TestMenuBoard.php @@ -0,0 +1,10 @@ +loadHTML('' . $html); + libxml_clear_errors(); + + return (new DOMXPath($document))->query($query); +} + +function menuHasClass(string $class): string +{ + return "contains(concat(' ', normalize-space(@class), ' '), ' {$class} ')"; +} + +describe('column header menu', function () { + test('renders the host block and the column actions in the same dropdown panel', function () { + $html = Livewire::test(TestBoard::class, ['withHeaderMenu' => true])->html(); + + $panels = menuXpath($html, '//div[' . menuHasClass('fi-dropdown-panel') . "][contains(., 'Block for To Do')][contains(., 'Archive column')]"); + + expect($panels)->toHaveCount(1) + ->and(menuXpath($html, '//div[' . menuHasClass('fi-dropdown-panel') . ']'))->toHaveCount(3); + }); + + test('puts the host block before the actions', function () { + $html = Livewire::test(TestBoard::class, ['withHeaderMenu' => true])->html(); + + expect(strpos($html, 'Block for To Do'))->toBeLessThan(strpos($html, 'Archive column')); + }); + + test('replaces the separate actions trigger and keeps the add card button', function () { + $html = Livewire::test(TestBoard::class, ['withHeaderMenu' => true, 'withCreateAction' => true])->html(); + + expect(menuXpath($html, '//div[' . menuHasClass('ff-column-actions') . ']//div[' . menuHasClass('fi-dropdown') . ']'))->toHaveCount(0) + ->and(menuXpath($html, '//div[' . menuHasClass('ff-column-actions') . ']//button'))->toHaveCount(3); + }); + + test('the trigger is a div with the button role so a header drag handle does not filter it out', function () { + $html = Livewire::test(TestBoard::class, ['withHeaderMenu' => true])->html(); + + $triggers = menuXpath($html, '//div[' . menuHasClass('fi-dropdown-trigger') . "]/div[@role='button'][@tabindex='0'][" . menuHasClass('ff-column-heading') . ']'); + + expect($triggers)->toHaveCount(3) + ->and(menuXpath($html, '//div[' . menuHasClass('fi-dropdown-trigger') . ']//button'))->toHaveCount(0); + }); + + test('passes the column to the closure and renders only actions when the block is null', function () { + $html = Livewire::test(TestBoard::class, ['withHeaderMenu' => true, 'nullMenuBlock' => true])->html(); + + expect($html)->not->toContain('ff-test-menu-block') + ->and(menuXpath($html, '//div[' . menuHasClass('fi-dropdown-panel') . "][contains(., 'Archive column')]"))->toHaveCount(3); + }); + + test('a collapsed column renders no menu', function () { + $html = Livewire::test(TestBoard::class, ['withHeaderMenu' => true, 'collapsedIds' => ['in_progress']])->html(); + + expect($html)->not->toContain('Block for In Progress') + ->and($html)->toContain('Block for To Do'); + }); + + test('without a header menu the header keeps the actions group', function () { + $html = Livewire::test(TestBoard::class, ['withColumnActions' => true])->html(); + + expect(menuXpath($html, '//div[' . menuHasClass('ff-column-actions') . ']//div[' . menuHasClass('fi-dropdown') . ']'))->toHaveCount(3) + ->and(menuXpath($html, "//div[@role='button'][" . menuHasClass('ff-column-heading') . ']'))->toHaveCount(0); + }); +}); From 201422f6f94b6c8e79302e992cbe1a916605de1d Mon Sep 17 00:00:00 2001 From: Manuk Date: Sat, 14 Nov 2026 03:40:16 +0400 Subject: [PATCH 06/34] fix(columns): open every column menu on click and keep it open across updates --- resources/dist/flowforge-modern.js | 2 +- resources/js/flowforge-modern.js | 9 ++- .../modern/livewire/column-header.blade.php | 2 +- tests/Browser/ModernBoardTest.php | 56 +++++++++++++++++-- tests/Browser/Support/Pointer.php | 4 +- tests/Fixtures/Modern/ModernPanelProvider.php | 1 + tests/Fixtures/Modern/TestMenuStaticBoard.php | 10 ++++ 7 files changed, 71 insertions(+), 13 deletions(-) create mode 100644 tests/Fixtures/Modern/TestMenuStaticBoard.php diff --git a/resources/dist/flowforge-modern.js b/resources/dist/flowforge-modern.js index e68f01635..e2cd6f2ff 100644 --- a/resources/dist/flowforge-modern.js +++ b/resources/dist/flowforge-modern.js @@ -1 +1 @@ -var S=["--ff-surface","--ff-surface-sunken","--ff-surface-raised","--ff-border","--ff-text","--ff-text-muted","--ff-accent","--ff-accent-tint","--ff-danger","--ff-warning","--ff-radius","--ff-gap","--ff-ease","--ff-duration","--ff-column-width","--ff-tray-bg","--ff-tray-radius","--ff-card-bg","--ff-card-ring","--ff-card-radius","--ff-card-shadow","--ff-card-padding","--ff-drag-tilt","--ff-drag-shadow","--ff-placeholder-border"],g='.ff-column-actions, .fi-dropdown-panel, input, textarea, select, [contenteditable]:not([contenteditable="false"])';var u=new WeakSet,h=()=>window.Sortable.active||window.Sortable.dragged;function w(){return{isLoading:{},fullyLoaded:{},dragOverColumn:null,railToggledAt:0,columnMenuPressAt:null,dragOverLane:null,dragSource:null,pendingCounts:{},pendingMoves:0,collapsedLanes:{},placeholder:null,stopTrackingPointer:null,init(){this.$wire.$on("kanban-items-loaded",e=>{let{columnId:t,isFullyLoaded:r}=e;r&&(this.fullyLoaded[t]=!0)})},configureSortable(e){if(!e.sortable||e.sortable.options.forceFallback)return;if(h()){this.configureSortableAfterDrag(e);return}let t=window.matchMedia("(prefers-reduced-motion: reduce)").matches;e.sortable.destroy(),e.sortable=window.Sortable.create(e,{draggable:"[x-sortable-item]",handle:"[x-sortable-handle]",dataIdAttr:"x-sortable-item",forceFallback:!0,fallbackTolerance:5,fallbackOnBody:!0,fallbackClass:"",ghostClass:"",delay:150,delayOnTouchOnly:!0,animation:t?0:200,scrollSensitivity:100,scrollSpeed:15,forceAutoScrollFallback:!0,group:{name:e.getAttribute("x-sortable-group"),pull:!0,put:(r,o)=>this.canDrop(r.el,o.el)},onStart:r=>this.startDrag(r),onEnd(r){let{item:o,to:n,oldDraggableIndex:a,newDraggableIndex:i}=r;if(a===i)return;let l=n.querySelectorAll(`:scope > ${this.options.draggable}`)[i-1];l&&n.insertBefore(o,l.nextSibling)}})},configureSortableAfterDrag(e){if(u.has(e))return;u.add(e);let t=()=>{if(h()){requestAnimationFrame(t);return}u.delete(e),e.isConnected&&this.configureSortable(e)};requestAnimationFrame(t)},startDrag(e){this.stopTrackingPointer?.(),this.placeholder=e.item,this.placeholder.setAttribute("data-placeholder",""),this.markGhost(),window.getSelection()?.removeAllRanges(),document.documentElement.classList.add("ff-dragging"),this.dragSource={column:e.from.dataset.columnId,lane:e.from.dataset.laneId??null};let t=r=>this.trackPointer(r);document.addEventListener("pointermove",t,{passive:!0}),document.addEventListener("touchmove",t,{passive:!0}),this.stopTrackingPointer=()=>{document.removeEventListener("pointermove",t),document.removeEventListener("touchmove",t)}},trackPointer(e){if(!window.Sortable.active){this.endDrag();return}this.markGhost();let t=e.touches?.[0]??e,r=document.elementFromPoint(t.clientX,t.clientY),o=r?.closest("[data-column-id]"),n=r?.closest("[data-column-root]");this.dragOverColumn=o?.dataset.columnId??n?.dataset.columnRoot??null,this.dragOverLane=o?.dataset.laneId??null},markGhost(){let e=window.Sortable.ghost;if(!e||e.hasAttribute("data-dragging"))return;e.removeAttribute("data-placeholder"),e.setAttribute("data-dragging",""),e.style.opacity="1";let t=getComputedStyle(this.placeholder);for(let r of S){let o=t.getPropertyValue(r);o!==""&&e.style.setProperty(r,o)}},endDrag(){document.documentElement.classList.remove("ff-dragging"),this.placeholder?.removeAttribute("data-placeholder"),this.placeholder=null,this.stopTrackingPointer?.(),this.stopTrackingPointer=null,this.dragOverColumn=null,this.dragOverLane=null,this.dragSource=null},toggleColumnCollapse(e,t,r=!1){e.target.closest(g)||r&&e.detail>1||Date.now()-this.railToggledAt<500||(r&&(this.railToggledAt=Date.now()),this.$wire.toggleBoardColumnCollapse(t))},suppressDoubleClickSelection(e){e.detail>1&&!e.target.closest(g)&&e.preventDefault()},initColumnMenu(e){let t=window.Alpine.$data(e.closest(".fi-dropdown"));if(t.ignoresMousedownToggle)return;let r=t.toggle.bind(t);t.ignoresMousedownToggle=!0,t.toggle=o=>o?.type==="mousedown"?void 0:r(o)},columnMenuPress(e){this.columnMenuPressAt={x:e.clientX,y:e.clientY}},columnMenuClick(e){let t=this.columnMenuPressAt;this.columnMenuPressAt=null,!(t&&Math.hypot(e.clientX-t.x,e.clientY-t.y)>4)&&window.Alpine.$data(e.currentTarget.closest(".fi-dropdown")).toggle(e)},columnDrop(e){return this.dragOverColumn!==e?null:this.isColumnBlocked(e)?"blocked":"active"},cellDrop(e,t){return this.dragOverColumn!==e||this.dragOverLane!==t?null:this.isCellBlocked(e,t)?"blocked":"active"},canDrop(e,t){if(!this.$root.contains(e)||!this.$root.contains(t))return!1;let r=e.dataset.laneId??null,o=t.dataset.laneId??null;return r!==o&&this.$root.dataset.lanesWritable!=="true"?!1:!this.isColumnBlocked(e.dataset.columnId,t.dataset.columnId)},isColumnBlocked(e,t=this.dragSource?.column){if(!e||e===t)return!1;let r=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"]`),o=r?.dataset.columnLimit;return o===void 0||o===""?!1:Number(r.dataset.columnTotal)>=Number(o)},isCellBlocked(e,t){return this.dragSource?t!==this.dragSource.lane&&this.$root.dataset.lanesWritable!=="true"?!0:this.isColumnBlocked(e):!1},displayCount(e,t){let r=this.pendingCounts[e]??t,o=this.dragSource?.column,n=this.dragOverColumn;return!o||!n||o===n||this.isColumnBlocked(n)?r:e===n?r+1:e===o?r-1:r},holdMovedCounts(e,t){if(e===t)return()=>{};let r={[e]:-1,[t]:1},o=!1;for(let[n,a]of Object.entries(r))this.pendingCounts[n]=this.renderedCount(n)+a;return this.pendingMoves++,n=>{if(!o){if(o=!0,n)for(let[a,i]of Object.entries(r))this.pendingCounts[a]-=i;--this.pendingMoves===0&&(this.pendingCounts={})}}},renderedCount(e){let t=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"] .ff-count`);return this.pendingCounts[e]??Number(t?.dataset.total)},handleSortableEnd(e){this.endDrag();let t=e.item,r=e.to,o=e.newDraggableIndex??e.newIndex,n=":scope > [x-sortable-item], :scope > [data-card-id]",a=s=>s.getAttribute("x-sortable-item")||s.getAttribute("data-card-id");if(e.from===r&&e.oldDraggableIndex===e.newDraggableIndex)return;if(o===0){let s=r.querySelector(n);s&&s!==t&&r.insertBefore(t,s)}let i=a(t);if(!i){console.error("Flowforge: Could not determine card ID for move operation");return}let l=r.getAttribute("data-column-id");if(!l){console.error("Flowforge: Target column ID is missing");return}let m=e.from.dataset.laneId??null,p=r.dataset.laneId??null,c=r.querySelectorAll(n),d=Array.prototype.indexOf.call(c,t),b=d>0?a(c[d-1]):null,C=d>=0&&d{this.setCardState(t,!1),f(s===!1),s===!1&&this.revertCard(e)}).catch(()=>{this.setCardState(t,!1),f(!0),this.revertCard(e)})},revertCard({item:e,from:t,oldDraggableIndex:r}){e.remove();let o=t.querySelectorAll(":scope > [x-sortable-item]"),n=o[o.length-1],a=o[r]??(n?n.nextSibling:t.firstChild);t.insertBefore(e,a)},setCardState(e,t){e.toggleAttribute("data-pending",t)},isLaneCollapsed(e){return this.collapsedLanes[e]===!0},toggleLane(e){this.collapsedLanes[e]=!this.isLaneCollapsed(e)},isLoadingColumn(e){return this.isLoading[e]||!1},isColumnFullyLoaded(e){return this.fullyLoaded[e]||!1},handleSmoothScroll(e){this.isLoadingColumn(e)||this.isColumnFullyLoaded(e)||(this.isLoading[e]=!0,this.$wire.loadMoreItems(e).then(()=>setTimeout(()=>this.isLoading[e]=!1,100)).catch(()=>this.isLoading[e]=!1))},handleColumnScroll(e,t){if(this.isColumnFullyLoaded(t))return;let{scrollTop:r,scrollHeight:o,clientHeight:n}=e.target;(r+n)/o>=.8&&!this.isLoadingColumn(t)&&this.handleSmoothScroll(t)}}}export{w as default}; +var w=["--ff-surface","--ff-surface-sunken","--ff-surface-raised","--ff-border","--ff-text","--ff-text-muted","--ff-accent","--ff-accent-tint","--ff-danger","--ff-warning","--ff-radius","--ff-gap","--ff-ease","--ff-duration","--ff-column-width","--ff-tray-bg","--ff-tray-radius","--ff-card-bg","--ff-card-ring","--ff-card-radius","--ff-card-shadow","--ff-card-padding","--ff-drag-tilt","--ff-drag-shadow","--ff-placeholder-border"],g='.ff-column-actions, .fi-dropdown-panel, input, textarea, select, [contenteditable]:not([contenteditable="false"])';var h=new WeakSet,u=new WeakSet,m=()=>window.Sortable.active||window.Sortable.dragged;function L(){return{isLoading:{},fullyLoaded:{},dragOverColumn:null,railToggledAt:0,columnMenuPressAt:null,dragOverLane:null,dragSource:null,pendingCounts:{},pendingMoves:0,collapsedLanes:{},placeholder:null,stopTrackingPointer:null,init(){this.$wire.$on("kanban-items-loaded",t=>{let{columnId:e,isFullyLoaded:r}=t;r&&(this.fullyLoaded[e]=!0)})},configureSortable(t){if(!t.sortable||t.sortable.options.forceFallback)return;if(m()){this.configureSortableAfterDrag(t);return}let e=window.matchMedia("(prefers-reduced-motion: reduce)").matches;t.sortable.destroy(),t.sortable=window.Sortable.create(t,{draggable:"[x-sortable-item]",handle:"[x-sortable-handle]",dataIdAttr:"x-sortable-item",forceFallback:!0,fallbackTolerance:5,fallbackOnBody:!0,fallbackClass:"",ghostClass:"",delay:150,delayOnTouchOnly:!0,animation:e?0:200,scrollSensitivity:100,scrollSpeed:15,forceAutoScrollFallback:!0,group:{name:t.getAttribute("x-sortable-group"),pull:!0,put:(r,o)=>this.canDrop(r.el,o.el)},onStart:r=>this.startDrag(r),onEnd(r){let{item:o,to:n,oldDraggableIndex:a,newDraggableIndex:i}=r;if(a===i)return;let l=n.querySelectorAll(`:scope > ${this.options.draggable}`)[i-1];l&&n.insertBefore(o,l.nextSibling)}})},configureSortableAfterDrag(t){if(u.has(t))return;u.add(t);let e=()=>{if(m()){requestAnimationFrame(e);return}u.delete(t),t.isConnected&&this.configureSortable(t)};requestAnimationFrame(e)},startDrag(t){this.stopTrackingPointer?.(),this.placeholder=t.item,this.placeholder.setAttribute("data-placeholder",""),this.markGhost(),window.getSelection()?.removeAllRanges(),document.documentElement.classList.add("ff-dragging"),this.dragSource={column:t.from.dataset.columnId,lane:t.from.dataset.laneId??null};let e=r=>this.trackPointer(r);document.addEventListener("pointermove",e,{passive:!0}),document.addEventListener("touchmove",e,{passive:!0}),this.stopTrackingPointer=()=>{document.removeEventListener("pointermove",e),document.removeEventListener("touchmove",e)}},trackPointer(t){if(!window.Sortable.active){this.endDrag();return}this.markGhost();let e=t.touches?.[0]??t,r=document.elementFromPoint(e.clientX,e.clientY),o=r?.closest("[data-column-id]"),n=r?.closest("[data-column-root]");this.dragOverColumn=o?.dataset.columnId??n?.dataset.columnRoot??null,this.dragOverLane=o?.dataset.laneId??null},markGhost(){let t=window.Sortable.ghost;if(!t||t.hasAttribute("data-dragging"))return;t.removeAttribute("data-placeholder"),t.setAttribute("data-dragging",""),t.style.opacity="1";let e=getComputedStyle(this.placeholder);for(let r of w){let o=e.getPropertyValue(r);o!==""&&t.style.setProperty(r,o)}},endDrag(){document.documentElement.classList.remove("ff-dragging"),this.placeholder?.removeAttribute("data-placeholder"),this.placeholder=null,this.stopTrackingPointer?.(),this.stopTrackingPointer=null,this.dragOverColumn=null,this.dragOverLane=null,this.dragSource=null},toggleColumnCollapse(t,e,r=!1){t.target.closest(g)||r&&t.detail>1||Date.now()-this.railToggledAt<500||(r&&(this.railToggledAt=Date.now()),this.$wire.toggleBoardColumnCollapse(e))},suppressDoubleClickSelection(t){t.detail>1&&!t.target.closest(g)&&t.preventDefault()},initColumnMenu(t){let e=t.closest(".fi-dropdown");if(h.has(e))return;let r=window.Alpine.$data(e),o=r.toggle.bind(r);h.add(e),r.toggle=n=>n?.type==="mousedown"?void 0:o(n)},columnMenuPress(t){this.columnMenuPressAt={x:t.clientX,y:t.clientY}},columnMenuClick(t){let e=this.columnMenuPressAt;this.columnMenuPressAt=null,!(e&&Math.hypot(t.clientX-e.x,t.clientY-e.y)>4)&&window.Alpine.$data(t.currentTarget.closest(".fi-dropdown")).toggle(t)},columnDrop(t){return this.dragOverColumn!==t?null:this.isColumnBlocked(t)?"blocked":"active"},cellDrop(t,e){return this.dragOverColumn!==t||this.dragOverLane!==e?null:this.isCellBlocked(t,e)?"blocked":"active"},canDrop(t,e){if(!this.$root.contains(t)||!this.$root.contains(e))return!1;let r=t.dataset.laneId??null,o=e.dataset.laneId??null;return r!==o&&this.$root.dataset.lanesWritable!=="true"?!1:!this.isColumnBlocked(t.dataset.columnId,e.dataset.columnId)},isColumnBlocked(t,e=this.dragSource?.column){if(!t||t===e)return!1;let r=this.$root.querySelector(`[data-column-root="${CSS.escape(t)}"]`),o=r?.dataset.columnLimit;return o===void 0||o===""?!1:Number(r.dataset.columnTotal)>=Number(o)},isCellBlocked(t,e){return this.dragSource?e!==this.dragSource.lane&&this.$root.dataset.lanesWritable!=="true"?!0:this.isColumnBlocked(t):!1},displayCount(t,e){let r=this.pendingCounts[t]??e,o=this.dragSource?.column,n=this.dragOverColumn;return!o||!n||o===n||this.isColumnBlocked(n)?r:t===n?r+1:t===o?r-1:r},holdMovedCounts(t,e){if(t===e)return()=>{};let r={[t]:-1,[e]:1},o=!1;for(let[n,a]of Object.entries(r))this.pendingCounts[n]=this.renderedCount(n)+a;return this.pendingMoves++,n=>{if(!o){if(o=!0,n)for(let[a,i]of Object.entries(r))this.pendingCounts[a]-=i;--this.pendingMoves===0&&(this.pendingCounts={})}}},renderedCount(t){let e=this.$root.querySelector(`[data-column-root="${CSS.escape(t)}"] .ff-count`);return this.pendingCounts[t]??Number(e?.dataset.total)},handleSortableEnd(t){this.endDrag();let e=t.item,r=t.to,o=t.newDraggableIndex??t.newIndex,n=":scope > [x-sortable-item], :scope > [data-card-id]",a=s=>s.getAttribute("x-sortable-item")||s.getAttribute("data-card-id");if(t.from===r&&t.oldDraggableIndex===t.newDraggableIndex)return;if(o===0){let s=r.querySelector(n);s&&s!==e&&r.insertBefore(e,s)}let i=a(e);if(!i){console.error("Flowforge: Could not determine card ID for move operation");return}let l=r.getAttribute("data-column-id");if(!l){console.error("Flowforge: Target column ID is missing");return}let p=t.from.dataset.laneId??null,b=r.dataset.laneId??null,c=r.querySelectorAll(n),d=Array.prototype.indexOf.call(c,e),C=d>0?a(c[d-1]):null,S=d>=0&&d{this.setCardState(e,!1),f(s===!1),s===!1&&this.revertCard(t)}).catch(()=>{this.setCardState(e,!1),f(!0),this.revertCard(t)})},revertCard({item:t,from:e,oldDraggableIndex:r}){t.remove();let o=e.querySelectorAll(":scope > [x-sortable-item]"),n=o[o.length-1],a=o[r]??(n?n.nextSibling:e.firstChild);e.insertBefore(t,a)},setCardState(t,e){t.toggleAttribute("data-pending",e)},isLaneCollapsed(t){return this.collapsedLanes[t]===!0},toggleLane(t){this.collapsedLanes[t]=!this.isLaneCollapsed(t)},isLoadingColumn(t){return this.isLoading[t]||!1},isColumnFullyLoaded(t){return this.fullyLoaded[t]||!1},handleSmoothScroll(t){this.isLoadingColumn(t)||this.isColumnFullyLoaded(t)||(this.isLoading[t]=!0,this.$wire.loadMoreItems(t).then(()=>setTimeout(()=>this.isLoading[t]=!1,100)).catch(()=>this.isLoading[t]=!1))},handleColumnScroll(t,e){if(this.isColumnFullyLoaded(e))return;let{scrollTop:r,scrollHeight:o,clientHeight:n}=t.target;(r+n)/o>=.8&&!this.isLoadingColumn(e)&&this.handleSmoothScroll(e)}}}export{L as default}; diff --git a/resources/js/flowforge-modern.js b/resources/js/flowforge-modern.js index e2c61a67c..4eba6c660 100644 --- a/resources/js/flowforge-modern.js +++ b/resources/js/flowforge-modern.js @@ -30,6 +30,8 @@ const HEADER_GESTURE_IGNORED = '.ff-column-actions, .fi-dropdown-panel, input, t const MENU_DRAG_THRESHOLD = 4; +const menusIgnoringMousedown = new WeakSet(); + const sortablesAwaitingDrag = new WeakSet(); const sortableIsBusy = () => window.Sortable.active || window.Sortable.dragged; @@ -245,15 +247,16 @@ export default function flowforgeModern() { // Filament opens a dropdown on mousedown, which would open the menu at the start of a header drag. initColumnMenu(trigger) { - const dropdown = window.Alpine.$data(trigger.closest('.fi-dropdown')); + const root = trigger.closest('.fi-dropdown'); - if (dropdown.ignoresMousedownToggle) { + if (menusIgnoringMousedown.has(root)) { return; } + const dropdown = window.Alpine.$data(root); const toggle = dropdown.toggle.bind(dropdown); - dropdown.ignoresMousedownToggle = true; + menusIgnoringMousedown.add(root); dropdown.toggle = (event) => (event?.type === 'mousedown' ? undefined : toggle(event)); }, diff --git a/resources/views/modern/livewire/column-header.blade.php b/resources/views/modern/livewire/column-header.blade.php index 84ccc519a..1f8340863 100644 --- a/resources/views/modern/livewire/column-header.blade.php +++ b/resources/views/modern/livewire/column-header.blade.php @@ -30,7 +30,7 @@ class="ff-column-header" @endif > @if ($hasMenu) - + script("document.querySelector('{$root}').hasAttribute('data-collapsed')"))->toBeFalse(); }); -test('clicking a header opens its menu at once', function () { +test('clicking a header opens its menu at once', function (string $column, string $label) { boardSeed(); $page = boardPage('/modern/test-menu-board'); $pointer = Pointer::on($page); - $root = '[data-column-root="todo"]'; + $root = "[data-column-root=\"{$column}\"]"; $pointer->click("{$root} .ff-column-heading"); $pointer->untilScript("document.querySelector('{$root} .fi-dropdown-panel').style.display === 'block'"); - expect($page->script("document.querySelector('{$root} .fi-dropdown-panel').innerText"))->toContain('Block for To Do')->toContain('Archive column'); -}); + expect($page->script("document.querySelector('{$root} .fi-dropdown-panel').innerText"))->toContain("Block for {$label}")->toContain('Archive column'); +})->with([['todo', 'To Do'], ['in_progress', 'In Progress']]); test('double clicking a header with a menu closes the menu and collapses the column', function () { boardSeed(); @@ -879,15 +879,59 @@ function boardTraySampler(int $budgetMilliseconds): string expect($page->script("document.querySelectorAll('.fi-dropdown-panel[style*=\"display: block\"]').length"))->toBe(0); }); -test('releasing a header drag does not open the menu', function () { +test('releasing a header drag does not open the menu', function (string $column) { boardSeed(); $page = boardPage('/modern/test-menu-board'); $pointer = Pointer::on($page); - $root = '[data-column-root="todo"]'; + $root = "[data-column-root=\"{$column}\"]"; + + $pointer->press("{$root} .ff-column-heading")->nudge(40, 0)->release()->wait(400); + + expect($page->script("document.querySelector('{$root} .fi-dropdown-panel').style.display"))->not->toBe('block'); +})->with(['todo', 'in_progress']); + +test('a column expanded from its rail opens its menu on click and not on a drag', function () { + boardSeed(); + $page = boardPage('/modern/test-menu-board'); + $pointer = Pointer::on($page); + $root = '[data-column-root="completed"]'; + + $pointer->click($root); + $pointer->untilScript("! document.querySelector('{$root}').hasAttribute('data-collapsed')"); + $pointer->untilScript("Boolean(document.querySelector('{$root} .fi-dropdown-panel'))"); $pointer->press("{$root} .ff-column-heading")->nudge(40, 0)->release()->wait(400); expect($page->script("document.querySelector('{$root} .fi-dropdown-panel').style.display"))->not->toBe('block'); + + $pointer->click("{$root} .ff-column-heading"); + $pointer->untilScript("document.querySelector('{$root} .fi-dropdown-panel').style.display === 'block'"); +}); + +test('a double click closes the menu it opened when nothing collapses', function () { + boardSeed(); + $page = boardPage('/modern/test-menu-static-board'); + $pointer = Pointer::on($page); + $root = '[data-column-root="todo"]'; + + $pointer->doubleClick("{$root} .ff-column-heading", 120)->wait(600); + + expect($page->script("document.querySelector('{$root} .fi-dropdown-panel').style.display"))->not->toBe('block') + ->and($page->script("document.querySelector('{$root}').hasAttribute('data-collapsed')"))->toBeFalse(); +}); + +test('a board update leaves an open menu open', function () { + boardSeed(); + $page = boardPage('/modern/test-menu-board'); + $pointer = Pointer::on($page); + $root = '[data-column-root="todo"]'; + + $pointer->click("{$root} .ff-column-heading"); + $pointer->untilScript("document.querySelector('{$root} .fi-dropdown-panel').style.display === 'block'"); + $page->script('Livewire.first().$refresh()'); + $pointer->wait(1000); + + expect($page->script("document.querySelector('{$root} .fi-dropdown-panel').style.display"))->toBe('block'); }); test('double clicking a word in the menu input selects it and leaves the column expanded', function () { diff --git a/tests/Browser/Support/Pointer.php b/tests/Browser/Support/Pointer.php index 606f8e9a9..4bdae8b92 100644 --- a/tests/Browser/Support/Pointer.php +++ b/tests/Browser/Support/Pointer.php @@ -103,9 +103,9 @@ public function click(string $selector): self return $this->press($selector)->release(); } - public function doubleClick(string $selector): self + public function doubleClick(string $selector, int $gapMilliseconds = 0): self { - $this->click($selector); + $this->click($selector)->wait($gapMilliseconds); $this->send('mouseDown', ['button' => 'left', 'clickCount' => 2]); $this->send('mouseUp', ['button' => 'left', 'clickCount' => 2]); diff --git a/tests/Fixtures/Modern/ModernPanelProvider.php b/tests/Fixtures/Modern/ModernPanelProvider.php index 306e0a6d2..4c923563b 100644 --- a/tests/Fixtures/Modern/ModernPanelProvider.php +++ b/tests/Fixtures/Modern/ModernPanelProvider.php @@ -32,6 +32,7 @@ public function panel(Panel $panel): Panel TestClassicBoard::class, TestCollapsibleBoard::class, TestMenuBoard::class, + TestMenuStaticBoard::class, TestContractBoard::class, TestGroupedBoard::class, TestCardActionBoard::class, diff --git a/tests/Fixtures/Modern/TestMenuStaticBoard.php b/tests/Fixtures/Modern/TestMenuStaticBoard.php new file mode 100644 index 000000000..095217ce2 --- /dev/null +++ b/tests/Fixtures/Modern/TestMenuStaticBoard.php @@ -0,0 +1,10 @@ + Date: Sat, 14 Nov 2026 03:49:27 +0400 Subject: [PATCH 07/34] feat(lanes): size lanes per column so collapsed columns hold --- docs/content/2.essentials/6.swimlanes.md | 5 +- docs/content/2.essentials/7.design-system.md | 2 +- resources/css/flowforge-modern.css | 44 ++++-- .../views/modern/livewire/lanes.blade.php | 29 +++- src/Board.php | 1 + src/Concerns/HasBoardGroupings.php | 27 +++- tests/Browser/ModernBoardTest.php | 42 ++++++ tests/Fixtures/Modern/ModernPanelProvider.php | 1 + .../Modern/TestCollapsibleGroupedBoard.php | 12 ++ tests/Fixtures/Modern/TestGroupedBoard.php | 18 +++ tests/Modern/Feature/GroupingViewTest.php | 140 ++++++++++++++++++ 11 files changed, 298 insertions(+), 23 deletions(-) create mode 100644 tests/Fixtures/Modern/TestCollapsibleGroupedBoard.php diff --git a/docs/content/2.essentials/6.swimlanes.md b/docs/content/2.essentials/6.swimlanes.md index 838f0f3b8..65d0bbc0e 100644 --- a/docs/content/2.essentials/6.swimlanes.md +++ b/docs/content/2.essentials/6.swimlanes.md @@ -91,4 +91,7 @@ While the board query carries an order, a card dragged within a cell is written ## Limits and collapsed columns - A column limit counts the whole column across every lane, and the header is shared. -- `collapseEmptyColumns()` applies to the plain board only. In lanes every column keeps its width, so every cell stays a drop target. +- `collapsedColumns()` and `collapseAllColumns()` apply in lanes. A collapsed column takes one narrow track in every lane. Its head shows as the same rail as on the plain board, and each cell under it shows its card count and no cards. Cells under a collapsed column load no cards. +- While a card is dragged, every collapsed track opens to full width, so each cell under it is a drop target. The tracks close again after the drop. +- With `collapsibleColumns()`, double-click a column head to collapse it and click its rail to open it again, as on the plain board. +- `collapseEmptyColumns()` applies to the plain board only. In lanes an empty column keeps its width, so every cell stays a drop target. diff --git a/docs/content/2.essentials/7.design-system.md b/docs/content/2.essentials/7.design-system.md index 208aaabc3..8e05f8299 100644 --- a/docs/content/2.essentials/7.design-system.md +++ b/docs/content/2.essentials/7.design-system.md @@ -110,7 +110,7 @@ Flowforge reports state through data attributes. SortableJS toggles classes only | `data-placeholder` | The drop gap | Where the card will land | | `data-drop="active"` or `data-drop="blocked"` | A column, or a lane cell | The hovered target accepts or refuses the card | | `data-full` | A column | The column is at its limit | -| `data-collapsed` | A column, or a lane header | The column shows as a collapsed rail, or the lane's cells are hidden | +| `data-collapsed` | A column, a lane header, or a lane cell | The column shows as a collapsed rail, the lane's cells are hidden, or the cell sits under a collapsed column and shows its count only | | `data-pending` | A card | Its move is saving | The dragged clone sits on `body`, outside `.ff-board`. A rule that must reach it starts at `.ff-card[data-dragging]`, and the visible card is its `.ff-card-body` child. diff --git a/resources/css/flowforge-modern.css b/resources/css/flowforge-modern.css index cb611902f..ffc0b092e 100644 --- a/resources/css/flowforge-modern.css +++ b/resources/css/flowforge-modern.css @@ -63,6 +63,7 @@ .ff-lanes-grid, .ff-lanes-heads { --_column-width: var(--ff-column-width, 300px); + --_collapsed-width: 3rem; } .ff-lanes-heads { @@ -187,9 +188,9 @@ max-height: 100%; } - .ff-column[data-collapsed]:not([data-drop]) { - width: 3rem; - min-width: 3rem; + .ff-column[data-collapsed]:not([data-drop], .ff-dragging .ff-lanes-heads .ff-column) { + width: var(--_collapsed-width); + min-width: var(--_collapsed-width); } .ff-column-header { @@ -200,7 +201,7 @@ padding: 0 0.25rem 0.5rem; } - .ff-column[data-collapsed]:not([data-drop]) .ff-column-header { + .ff-column[data-collapsed]:not([data-drop], .ff-dragging .ff-lanes-heads .ff-column) .ff-column-header { flex-direction: column; justify-content: normal; } @@ -212,7 +213,7 @@ min-width: 0; } - .ff-column[data-collapsed]:not([data-drop]) .ff-column-heading { + .ff-column[data-collapsed]:not([data-drop], .ff-dragging .ff-lanes-heads .ff-column) .ff-column-heading { display: contents; } @@ -240,7 +241,7 @@ white-space: nowrap; } - .ff-column[data-collapsed]:not([data-drop]) .ff-column-title { + .ff-column[data-collapsed]:not([data-drop], .ff-dragging .ff-lanes-heads .ff-column) .ff-column-title { max-height: 16rem; writing-mode: vertical-rl; } @@ -340,7 +341,7 @@ overscroll-behavior-y: contain; } - .ff-column[data-collapsed]:not([data-drop]) .ff-cards { + .ff-column[data-collapsed]:not([data-drop], .ff-dragging .ff-lanes-heads .ff-column) .ff-cards { padding: 0; } @@ -671,19 +672,29 @@ display: grid; width: max-content; min-width: 100%; - grid-template-columns: repeat(var(--_columns), var(--_column-width)); + grid-template-columns: var(--_tracks); column-gap: var(--_gap); row-gap: 0.5rem; padding-bottom: 1rem; } + .ff-dragging .ff-lanes-grid, + .ff-dragging .ff-lanes-heads { + grid-template-columns: var(--_tracks-open); + } + + .ff-lanes-heads .ff-column { + width: auto; + min-width: 0; + } + .ff-lanes-heads { position: sticky; top: 0; z-index: 10; display: grid; grid-column: 1 / -1; - grid-template-columns: repeat(var(--_columns), var(--_column-width)); + grid-template-columns: var(--_tracks); column-gap: var(--_gap); padding-top: 0.25rem; background-color: var(--_surface); @@ -773,6 +784,21 @@ min-height: 4rem; } + .ff-cell[data-collapsed] { + align-items: center; + padding-inline: 0; + } + + .ff-cell[data-collapsed] .ff-cell-cards { + width: 100%; + overflow: hidden; + } + + .ff-dragging .ff-cell[data-collapsed] { + align-items: stretch; + padding-inline: 0.5rem; + } + .ff-lanes-more { grid-column: 1 / -1; } diff --git a/resources/views/modern/livewire/lanes.blade.php b/resources/views/modern/livewire/lanes.blade.php index d7265cba2..dd597a648 100644 --- a/resources/views/modern/livewire/lanes.blade.php +++ b/resources/views/modern/livewire/lanes.blade.php @@ -6,22 +6,33 @@ use function Filament\Support\get_color_css_variables; $isSortable = $this->getBoard()->getPositionIdentifierAttribute() !== null; + $tracks = collect($columns) + ->map(fn (array $column): string => ($column['isCollapsed'] ?? false) ? 'var(--_collapsed-width)' : 'var(--_column-width)') + ->implode(' '); + $tracksStyle = '--_tracks: ' . $tracks . '; --_tracks-open: repeat(' . count($columns) . ', var(--_column-width))'; @endphp
-
-
+
+
@foreach ($columns as $columnId => $column) + @php $isCollapsed = (bool) ($column['isCollapsed'] ?? false); @endphp +
- +
@endforeach
@@ -62,14 +73,22 @@ class="ff-lane-toggle"
@foreach ($columns as $columnId => $column) - @php $cell = $lane['cells'][$columnId] ?? ['items' => [], 'total' => 0]; @endphp + @php + $cell = $lane['cells'][$columnId] ?? ['items' => [], 'total' => 0]; + $isCollapsed = (bool) ($column['isCollapsed'] ?? false); + @endphp
+ @if ($isCollapsed) + {{ $cell['total'] }} + @endif +
- @if ($cell['total'] > count($cell['items'])) + @if (! $isCollapsed && $cell['total'] > count($cell['items']))
@endif
diff --git a/resources/views/modern/livewire/add-column.blade.php b/resources/views/modern/livewire/add-column.blade.php new file mode 100644 index 000000000..572562c12 --- /dev/null +++ b/resources/views/modern/livewire/add-column.blade.php @@ -0,0 +1,39 @@ +@props(['label']) + +@php + use Filament\Support\Enums\IconSize; +@endphp + +
+ + +
+ + + @error('boardNewColumn') +

{{ $message }}

+ @enderror +
+
diff --git a/resources/views/modern/livewire/lanes.blade.php b/resources/views/modern/livewire/lanes.blade.php index dd597a648..3d1beac37 100644 --- a/resources/views/modern/livewire/lanes.blade.php +++ b/resources/views/modern/livewire/lanes.blade.php @@ -10,11 +10,15 @@ ->map(fn (array $column): string => ($column['isCollapsed'] ?? false) ? 'var(--_collapsed-width)' : 'var(--_column-width)') ->implode(' '); $tracksStyle = '--_tracks: ' . $tracks . '; --_tracks-open: repeat(' . count($columns) . ', var(--_column-width))'; + $canAddColumns = (bool) ($config['canAddColumns'] ?? false); + $headsStyle = $canAddColumns + ? '--_tracks: ' . $tracks . ' var(--_collapsed-width); --_tracks-open: repeat(' . count($columns) . ', var(--_column-width)) var(--_collapsed-width)' + : $tracksStyle; @endphp
-
+
@foreach ($columns as $columnId => $column) @php $isCollapsed = (bool) ($column['isCollapsed'] ?? false); @endphp @@ -35,6 +39,10 @@ class="ff-column"
@endforeach + + @if ($canAddColumns) + + @endif
@foreach ($lanes as $lane) diff --git a/src/Board.php b/src/Board.php index 7c45bddf1..a76b0f825 100644 --- a/src/Board.php +++ b/src/Board.php @@ -129,6 +129,8 @@ public function getViewData(): array 'pluralCardLabel' => $this->getPluralCardLabel(), 'headerToolbar' => $this->hasHeaderToolbar(), 'collapsible' => $this->isColumnCollapsible(), + 'canAddColumns' => $this->canAddColumns(), + 'addColumnLabel' => $this->getAddColumnLabel(), 'collapseEmptyColumns' => $grouping === null && $this->collapsesEmptyColumns() && array_sum(array_column($columns, 'total')) > 0, diff --git a/src/Concerns/HasColumnControls.php b/src/Concerns/HasColumnControls.php index b4def3eff..8506ade13 100644 --- a/src/Concerns/HasColumnControls.php +++ b/src/Concerns/HasColumnControls.php @@ -21,6 +21,10 @@ trait HasColumnControls protected ?Closure $columnHeaderMenu = null; + protected ?Closure $addColumn = null; + + protected string | Closure | null $addColumnLabel = null; + /** * @param array|Closure $columnIds */ @@ -111,4 +115,39 @@ public function getColumnHeaderMenuBlock(array $column): ?Htmlable return $this->evaluate($this->columnHeaderMenu, ['column' => $column]); } + + public function addColumnUsing(?Closure $using): static + { + $this->addColumn = $using; + + return $this; + } + + public function addColumnLabel(string | Closure | null $label): static + { + $this->addColumnLabel = $label; + + return $this; + } + + public function canAddColumns(): bool + { + return $this->addColumn instanceof Closure; + } + + public function getAddColumnLabel(): string + { + $label = $this->evaluate($this->addColumnLabel); + + return filled($label) ? (string) $label : __('flowforge::flowforge.add_column'); + } + + public function addColumn(string $name): void + { + if (! $this->addColumn instanceof Closure) { + return; + } + + $this->evaluate($this->addColumn, ['name' => $name]); + } } diff --git a/src/FlowforgeServiceProvider.php b/src/FlowforgeServiceProvider.php index 22b56a8ac..5bd6b75a1 100644 --- a/src/FlowforgeServiceProvider.php +++ b/src/FlowforgeServiceProvider.php @@ -131,6 +131,7 @@ private function registerBladeComponents(): void Blade::component('flowforge::modern.livewire.card', 'flowforge::modern.card'); Blade::component('flowforge::modern.livewire.column-count', 'flowforge::modern.column-count'); Blade::component('flowforge::modern.livewire.add-card-row', 'flowforge::modern.add-card-row'); + Blade::component('flowforge::modern.livewire.add-column', 'flowforge::modern.add-column'); Blade::component('flowforge::modern.livewire.lanes', 'flowforge::modern.lanes'); Blade::component('flowforge::modern.components.grouping-picker', 'flowforge::modern.grouping-picker'); } diff --git a/src/Modern/Concerns/InteractsWithBoard.php b/src/Modern/Concerns/InteractsWithBoard.php index 8d15e5ea1..3c8e49d86 100644 --- a/src/Modern/Concerns/InteractsWithBoard.php +++ b/src/Modern/Concerns/InteractsWithBoard.php @@ -15,6 +15,7 @@ use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; +use Illuminate\Validation\ValidationException; use InvalidArgumentException; use Livewire\Attributes\Locked; use Livewire\Attributes\Url; @@ -126,6 +127,28 @@ public function toggleBoardColumnCollapse(string $columnId): void $this->board = $this->board($this->makeBoard()); } + public function addBoardColumn(string $name): void + { + $name = trim($name); + + if ($name === '') { + $this->addError('boardNewColumn', __('flowforge::flowforge.column_name_required')); + + return; + } + + try { + $this->getBoard()->addColumn($name); + } catch (ValidationException $exception) { + $this->addError('boardNewColumn', (string) collect($exception->errors())->flatten()->first()); + + return; + } + + $this->resetErrorBag('boardNewColumn'); + $this->board = $this->board($this->makeBoard()); + } + protected function canCreateCardIn(mixed $columnId): bool { if (! is_string($columnId)) { diff --git a/tests/Browser/ModernBoardTest.php b/tests/Browser/ModernBoardTest.php index 037856f86..e79dd0bb4 100644 --- a/tests/Browser/ModernBoardTest.php +++ b/tests/Browser/ModernBoardTest.php @@ -1035,3 +1035,50 @@ function boardTraySampler(int $budgetMilliseconds): string expect($page->script("document.querySelector('{$heading}').innerText.trim()"))->toContain('13/20') ->and($page->script("document.querySelector('{$heading}').scrollWidth"))->toBeLessThanOrEqual(40); }); + +test('clicking the add column tile, typing a name and pressing enter adds the column', function () { + boardSeed(); + $page = boardPage('/modern/test-add-column-board'); + $pointer = Pointer::on($page); + $input = '.ff-add-column-input'; + + $pointer->click('.ff-add-column-button'); + $pointer->untilScript("document.activeElement === document.querySelector('{$input}')"); + $page->type($input, 'Won'); + $page->keys($input, 'Enter'); + $pointer->untilScript("document.querySelectorAll('[data-column-root=\"Won\"]').length === 1"); + + expect($page->script("document.querySelector('{$input}').offsetParent === null"))->toBeTrue() + ->and($page->script("document.querySelector('{$input}').value"))->toBe(''); +}); + +test('escape cancels the add column input without calling the host', function () { + boardSeed(); + $page = boardPage('/modern/test-add-column-board'); + $pointer = Pointer::on($page); + $input = '.ff-add-column-input'; + + $pointer->click('.ff-add-column-button'); + $pointer->untilScript("document.activeElement === document.querySelector('{$input}')"); + $page->type($input, 'Won'); + $page->keys($input, 'Escape'); + $pointer->untilScript("document.querySelector('{$input}').offsetParent === null"); + $pointer->wait(400); + + expect($page->script("document.querySelectorAll('[data-column-root]').length"))->toBe(3) + ->and($page->script("document.querySelector('{$input}').value"))->toBe(''); +}); + +test('a blank add column name shows its error under the input and keeps it open', function () { + boardSeed(); + $page = boardPage('/modern/test-add-column-board'); + $pointer = Pointer::on($page); + $input = '.ff-add-column-input'; + + $pointer->click('.ff-add-column-button'); + $pointer->untilScript("document.activeElement === document.querySelector('{$input}')"); + $page->keys($input, 'Enter'); + $pointer->untilScript("document.querySelector('.ff-add-column-error')?.offsetParent !== null && document.querySelector('.ff-add-column-error') !== null"); + + expect($page->script("document.querySelector('{$input}').offsetParent !== null"))->toBeTrue(); +}); diff --git a/tests/Fixtures/Modern/ModernPanelProvider.php b/tests/Fixtures/Modern/ModernPanelProvider.php index 6db723359..df257fb85 100644 --- a/tests/Fixtures/Modern/ModernPanelProvider.php +++ b/tests/Fixtures/Modern/ModernPanelProvider.php @@ -28,6 +28,7 @@ public function panel(Panel $panel): Panel ->spa() ->pages([ TestBoard::class, + TestAddColumnBoard::class, TestBrowserBoard::class, TestClassicBoard::class, TestCollapsibleBoard::class, diff --git a/tests/Fixtures/Modern/TestAddColumnBoard.php b/tests/Fixtures/Modern/TestAddColumnBoard.php new file mode 100644 index 000000000..5e4b9c535 --- /dev/null +++ b/tests/Fixtures/Modern/TestAddColumnBoard.php @@ -0,0 +1,10 @@ +collapsedIds, [$columnId])); } : null) + ->addColumnUsing($this->withAddColumn ? $this->addColumnClosure(...) : null) + ->addColumnLabel($this->addColumnTitle) ->headerToolbar($this->withHeaderToolbar) ->columnActions(match (true) { $this->withHeaderMenu => [Action::make('archiveColumn')->label('Archive column')->action(function (): void {})], @@ -139,9 +150,19 @@ public function board(Board $board): Board Column::make('archived')->label('Archived Column')->hidden(true), Column::make('in_progress')->label($this->htmlLabel ? new HtmlString('In Progress') : 'In Progress')->color('blue')->visible(fn () => ! $this->hideEverything), Column::make('completed')->label('Completed')->color('green')->visible(fn () => ! $this->hideEverything), + ...array_map(fn (string $name): Column => Column::make($name)->label($name), $this->addedColumns), ]); } + protected function addColumnClosure(string $name): void + { + if ($name === $this->rejectColumnName) { + throw ValidationException::withMessages(['name' => 'Taken']); + } + + $this->addedColumns[] = $name; + } + protected function authorizeCardMove(Model $card, string $targetColumnId, ?string $toLaneId = null): void { abort_if($card->getAttribute('title') === $this->denyMovesFor, 403); diff --git a/tests/Fixtures/Modern/TestGroupedBoard.php b/tests/Fixtures/Modern/TestGroupedBoard.php index 933544378..a6af1ff78 100644 --- a/tests/Fixtures/Modern/TestGroupedBoard.php +++ b/tests/Fixtures/Modern/TestGroupedBoard.php @@ -9,6 +9,7 @@ use Illuminate\Database\QueryException; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\DB; +use Illuminate\Validation\ValidationException; use PDOException; use Relaticle\Flowforge\Board; use Relaticle\Flowforge\Column; @@ -23,6 +24,12 @@ class TestGroupedBoard extends BoardPage public int $cardsPerCell = 20; + public bool $withAddColumn = false; + + public array $addedColumns = []; + + public ?string $rejectColumnName = null; + public bool $withHeaderToolbar = false; public bool $collapseEmpty = false; @@ -107,6 +114,7 @@ public function board(Board $board): Board ->positionIdentifier('order_position') ->cardsPerColumn($this->cardsPerCell) ->lanesPerPage($this->lanesPerPage) + ->addColumnUsing($this->withAddColumn ? $this->addColumnClosure(...) : null) ->headerToolbar($this->withHeaderToolbar) ->collapseEmptyColumns($this->collapseEmpty) ->collapsedColumns($this->collapsedIds) @@ -122,6 +130,7 @@ public function board(Board $board): Board ->columns([ Column::make('todo')->label('To Do'), Column::make('in_progress')->label('In Progress')->limit($this->inProgressLimit), + ...array_map(fn (string $name): Column => Column::make($name)->label($name), $this->addedColumns), ]) ->groupings([ Grouping::attribute('priority')->label('Priority'), @@ -173,6 +182,15 @@ protected function persistCardMove(Model $card, mixed $columnValue, string $posi } } + protected function addColumnClosure(string $name): void + { + if ($name === $this->rejectColumnName) { + throw ValidationException::withMessages(['name' => 'Taken']); + } + + $this->addedColumns[] = $name; + } + protected function assigneeGrouping(string $name = 'assignee'): Grouping { return Grouping::make($name) diff --git a/tests/Modern/Feature/AddColumnTest.php b/tests/Modern/Feature/AddColumnTest.php new file mode 100644 index 000000000..df5a4e267 --- /dev/null +++ b/tests/Modern/Feature/AddColumnTest.php @@ -0,0 +1,123 @@ +]*' . preg_quote($property, '/') . ':\s*([^;"]+)/', $html, $match); + + return trim($match[1] ?? ''); +} + +describe('add column tile', function () { + test('no tile renders unless the host adds columns', function () { + Livewire::test(TestBoard::class)->assertDontSeeHtml('ff-add-column'); + }); + + test('the tile renders when the host adds columns', function () { + Livewire::test(TestBoard::class, ['withAddColumn' => true])->assertSeeHtml('ff-add-column'); + }); + + test('the tile carries the default label as its tooltip', function () { + Livewire::test(TestBoard::class, ['withAddColumn' => true]) + ->assertSeeHtml('title="' . __('flowforge::flowforge.add_column') . '"'); + }); + + test('the tile carries the host label as its tooltip', function () { + Livewire::test(TestBoard::class, ['withAddColumn' => true, 'addColumnTitle' => 'Add stage']) + ->assertSeeHtml('title="Add stage"'); + }); + + test('adding a column passes the trimmed name to the host', function () { + Livewire::test(TestBoard::class, ['withAddColumn' => true]) + ->call('addBoardColumn', ' Won ') + ->assertHasNoErrors('boardNewColumn') + ->assertSet('addedColumns', ['Won']); + }); + + test('the board shows the new column in the same response', function () { + Livewire::test(TestBoard::class, ['withAddColumn' => true]) + ->call('addBoardColumn', 'Won') + ->assertSeeHtml('data-column-root="Won"'); + }); + + test('a blank name is refused before the host is called', function () { + Livewire::test(TestBoard::class, ['withAddColumn' => true]) + ->call('addBoardColumn', ' ') + ->assertHasErrors(['boardNewColumn']) + ->assertSet('addedColumns', []); + }); + + test('the host validation message reaches the tile', function () { + $component = Livewire::test(TestBoard::class, ['withAddColumn' => true, 'rejectColumnName' => 'Lost']) + ->call('addBoardColumn', 'Lost') + ->assertHasErrors(['boardNewColumn']) + ->assertSet('addedColumns', []); + + expect($component->errors()->get('boardNewColumn'))->toBe(['Taken']) + ->and($component->html())->toContain('Taken'); + }); + + test('a later success clears the error', function () { + Livewire::test(TestBoard::class, ['withAddColumn' => true, 'rejectColumnName' => 'Lost']) + ->call('addBoardColumn', 'Lost') + ->call('addBoardColumn', 'Won') + ->assertHasNoErrors('boardNewColumn') + ->assertSet('addedColumns', ['Won']); + }); + + test('a board without the host closure ignores the call', function () { + Livewire::test(TestBoard::class) + ->call('addBoardColumn', 'Won') + ->assertSet('addedColumns', []) + ->assertHasNoErrors('boardNewColumn'); + }); + + test('in lanes the tile is an extra head track and every lane stays aligned', function () { + Task::create(['title' => 'Low card', 'status' => 'todo', 'priority' => 'low', 'order_position' => '65535.0000000000']); + Task::create(['title' => 'High card', 'status' => 'in_progress', 'priority' => 'high', 'order_position' => '65535.0000000000']); + + $html = Livewire::test(TestGroupedBoard::class, ['groupBy' => 'priority', 'withAddColumn' => true])->html(); + + expect(headTracks($html, '--_tracks'))->toBe('var(--_column-width) var(--_column-width) var(--_collapsed-width)') + ->and(headTracks($html, '--_tracks-open'))->toBe('repeat(2, var(--_column-width)) var(--_collapsed-width)') + ->and(laneCellColumnOrder($html, 'low'))->toBe(['todo', 'in_progress']) + ->and(laneCellColumnOrder($html, 'high'))->toBe(['todo', 'in_progress']) + ->and($html)->toContain('ff-add-column'); + }); + + test('in lanes the grid keeps one track per column', function () { + $html = Livewire::test(TestGroupedBoard::class, ['groupBy' => 'priority', 'withAddColumn' => true])->html(); + + preg_match('/class="ff-lanes-grid"[^>]*--_tracks:\s*([^;"]+)/', $html, $match); + + expect(trim($match[1]))->toBe('var(--_column-width) var(--_column-width)'); + }); + + test('in lanes the new column appears in the same response', function () { + Task::create(['title' => 'Low card', 'status' => 'todo', 'priority' => 'low', 'order_position' => '65535.0000000000']); + + $html = Livewire::test(TestGroupedBoard::class, ['groupBy' => 'priority', 'withAddColumn' => true]) + ->call('addBoardColumn', 'Won') + ->html(); + + expect(laneCellColumnOrder($html, 'low'))->toBe(['todo', 'in_progress', 'Won']) + ->and(headTracks($html, '--_tracks'))->toBe('var(--_column-width) var(--_column-width) var(--_column-width) var(--_collapsed-width)'); + }); +}); From bbe426e4035dcd7911575c240ce8d105f3da75b4 Mon Sep 17 00:00:00 2001 From: Manuk Date: Sat, 14 Nov 2026 04:26:06 +0400 Subject: [PATCH 11/34] fix(columns): keep the add tile at head height and submit a name once --- docs/content/2.essentials/6.swimlanes.md | 1 + docs/content/2.essentials/7.design-system.md | 2 +- resources/css/flowforge-modern.css | 3 + resources/dist/flowforge-modern.js | 2 +- resources/js/flowforge-modern.js | 17 ++- tests/Browser/ModernBoardTest.php | 108 ++++++++++++++++++ tests/Fixtures/Modern/ModernPanelProvider.php | 1 + tests/Fixtures/Modern/TestAddColumnBoard.php | 2 + .../Modern/TestAddColumnGroupedBoard.php | 10 ++ 9 files changed, 142 insertions(+), 4 deletions(-) create mode 100644 tests/Fixtures/Modern/TestAddColumnGroupedBoard.php diff --git a/docs/content/2.essentials/6.swimlanes.md b/docs/content/2.essentials/6.swimlanes.md index f011ce7cd..47c172bc6 100644 --- a/docs/content/2.essentials/6.swimlanes.md +++ b/docs/content/2.essentials/6.swimlanes.md @@ -92,6 +92,7 @@ While the board query carries an order, a card dragged within a cell is written - A column limit counts the whole column across every lane, and the header is shared. - `collapsedColumns()` and `collapseAllColumns()` apply in lanes. A collapsed column takes one narrow track in every lane. Its head shows a color dot and the count at the normal head height, with the name as a tooltip, and each cell under it shows its card count and no cards. Each cell under a collapsed column loads one record for its count and shows no cards. +- With `addColumnUsing()` set, the add column tile is one extra track at the end of the header row, at head height. The lane headers and cells do not get that track, so every cell keeps its column. - While a card is dragged, every collapsed track opens to full width, so each cell under it is a drop target. The tracks close again after the drop. - With `collapsibleColumns()`, double-click a column head to collapse it and click its rail to open it again, as on the plain board. - `collapseEmptyColumns()` applies to the plain board only. In lanes an empty column keeps its width, so every cell stays a drop target. diff --git a/docs/content/2.essentials/7.design-system.md b/docs/content/2.essentials/7.design-system.md index 8e05f8299..2c30d6627 100644 --- a/docs/content/2.essentials/7.design-system.md +++ b/docs/content/2.essentials/7.design-system.md @@ -42,7 +42,7 @@ The dark column shows where the default changes under Filament's `.dark` class. | `--ff-surface` | semantic | `var(--gray-50)` / `var(--gray-950)` | 4.2.0 | Background of the sticky column-header strip in the lane view. Set it to the page background. | | `--ff-surface-sunken` | semantic | `var(--gray-100)` / `color-mix(in oklab, #fff 5%, transparent)` | 4.2.0 | Background of a column tray and of a lane cell. `--ff-tray-bg` overrides it. | | `--ff-surface-raised` | semantic | `#fff` / `var(--gray-900)` | 4.2.0 | Background of a card and of the filters panel. `--ff-card-bg` overrides it for cards. | -| `--ff-border` | semantic | `color-mix(in oklab, var(--gray-950) 5%, transparent)` / `color-mix(in oklab, #fff 10%, transparent)` | 4.2.0 | Ring around a card and around the filters panel. `--ff-card-ring` overrides it for cards. | +| `--ff-border` | semantic | `color-mix(in oklab, var(--gray-950) 5%, transparent)` / `color-mix(in oklab, #fff 10%, transparent)` | 4.2.0 | Ring around a card and around the filters panel, and the dashed border of the add column tile. `--ff-card-ring` overrides it for cards. | | `--ff-text` | semantic | `var(--gray-950)` / `#fff` | 4.2.0 | Column titles, lane titles, card titles and the add row on hover. | | `--ff-text-muted` | semantic | `var(--gray-500)` / `var(--gray-400)` | 4.2.0 | Secondary text and icons: the group-by label, column icons, counts, summaries, tags, card meta, the add row, the avatar overflow, lane counts and icons, and the header subheading. | | `--ff-accent` | semantic | `var(--primary-500)` | 4.2.0 | Outline of an accepting drop target, the drop gap border and the loading text. | diff --git a/resources/css/flowforge-modern.css b/resources/css/flowforge-modern.css index 487b0e597..086900b81 100644 --- a/resources/css/flowforge-modern.css +++ b/resources/css/flowforge-modern.css @@ -669,6 +669,9 @@ flex-shrink: 0; align-self: stretch; width: var(--_collapsed-width); + } + + .ff-columns > .ff-add-column { min-height: 3rem; } diff --git a/resources/dist/flowforge-modern.js b/resources/dist/flowforge-modern.js index 4b8914d01..2abce155f 100644 --- a/resources/dist/flowforge-modern.js +++ b/resources/dist/flowforge-modern.js @@ -1 +1 @@ -var S=["--ff-surface","--ff-surface-sunken","--ff-surface-raised","--ff-border","--ff-text","--ff-text-muted","--ff-accent","--ff-accent-tint","--ff-danger","--ff-warning","--ff-radius","--ff-gap","--ff-ease","--ff-duration","--ff-column-width","--ff-tray-bg","--ff-tray-radius","--ff-card-bg","--ff-card-ring","--ff-card-radius","--ff-card-shadow","--ff-card-padding","--ff-drag-tilt","--ff-drag-shadow","--ff-placeholder-border"],g='.ff-column-actions, .fi-dropdown-panel, input, textarea, select, [contenteditable]:not([contenteditable="false"])';var h=new WeakSet,c=new WeakSet,m=()=>window.Sortable.active||window.Sortable.dragged;function L(){return{isLoading:{},fullyLoaded:{},dragOverColumn:null,railToggledAt:0,columnMenuPressAt:null,dragOverLane:null,dragSource:null,pendingCounts:{},pendingMoves:0,collapsedLanes:{},addingColumn:!1,newColumnName:"",newColumnTouched:!1,placeholder:null,stopTrackingPointer:null,init(){this.$wire.$on("kanban-items-loaded",e=>{let{columnId:t,isFullyLoaded:o}=e;o&&(this.fullyLoaded[t]=!0)})},configureSortable(e){if(!e.sortable||e.sortable.options.forceFallback)return;if(m()){this.configureSortableAfterDrag(e);return}let t=window.matchMedia("(prefers-reduced-motion: reduce)").matches;e.sortable.destroy(),e.sortable=window.Sortable.create(e,{draggable:"[x-sortable-item]",handle:"[x-sortable-handle]",dataIdAttr:"x-sortable-item",forceFallback:!0,fallbackTolerance:5,fallbackOnBody:!0,fallbackClass:"",ghostClass:"",delay:150,delayOnTouchOnly:!0,animation:t?0:200,scrollSensitivity:100,scrollSpeed:15,forceAutoScrollFallback:!0,group:{name:e.getAttribute("x-sortable-group"),pull:!0,put:(o,r)=>this.canDrop(o.el,r.el)},onStart:o=>this.startDrag(o),onEnd(o){let{item:r,to:n,oldDraggableIndex:a,newDraggableIndex:l}=o;if(a===l)return;let i=n.querySelectorAll(`:scope > ${this.options.draggable}`)[l-1];i&&n.insertBefore(r,i.nextSibling)}})},configureSortableAfterDrag(e){if(c.has(e))return;c.add(e);let t=()=>{if(m()){requestAnimationFrame(t);return}c.delete(e),e.isConnected&&this.configureSortable(e)};requestAnimationFrame(t)},startDrag(e){this.stopTrackingPointer?.(),this.placeholder=e.item,this.placeholder.setAttribute("data-placeholder",""),this.markGhost(),window.getSelection()?.removeAllRanges(),document.documentElement.classList.add("ff-dragging"),this.dragSource={column:e.from.dataset.columnId,lane:e.from.dataset.laneId??null};let t=o=>this.trackPointer(o);document.addEventListener("pointermove",t,{passive:!0}),document.addEventListener("touchmove",t,{passive:!0}),this.stopTrackingPointer=()=>{document.removeEventListener("pointermove",t),document.removeEventListener("touchmove",t)}},trackPointer(e){if(!window.Sortable.active){this.endDrag();return}this.markGhost();let t=e.touches?.[0]??e,o=document.elementFromPoint(t.clientX,t.clientY),r=o?.closest("[data-column-id]"),n=o?.closest("[data-column-root]");this.dragOverColumn=r?.dataset.columnId??n?.dataset.columnRoot??null,this.dragOverLane=r?.dataset.laneId??null},markGhost(){let e=window.Sortable.ghost;if(!e||e.hasAttribute("data-dragging"))return;e.removeAttribute("data-placeholder"),e.setAttribute("data-dragging",""),e.style.opacity="1";let t=getComputedStyle(this.placeholder);for(let o of S){let r=t.getPropertyValue(o);r!==""&&e.style.setProperty(o,r)}},endDrag(){document.documentElement.classList.remove("ff-dragging"),this.placeholder?.removeAttribute("data-placeholder"),this.placeholder=null,this.stopTrackingPointer?.(),this.stopTrackingPointer=null,this.dragOverColumn=null,this.dragOverLane=null,this.dragSource=null},toggleColumnCollapse(e,t,o=!1){e.target.closest(g)||o&&e.detail>1||Date.now()-this.railToggledAt<500||(o&&(this.railToggledAt=Date.now()),this.$wire.toggleBoardColumnCollapse(t))},openNewColumn(){this.addingColumn=!0,this.newColumnTouched=!0,this.$nextTick(()=>this.$refs.newColumnInput.focus())},cancelNewColumn(){this.addingColumn=!1,this.newColumnName=""},async submitNewColumn(){this.newColumnTouched=!1,await this.$wire.addBoardColumn(this.newColumnName),this.$root.querySelector(".ff-add-column-error")||this.cancelNewColumn()},suppressDoubleClickSelection(e){e.detail>1&&!e.target.closest(g)&&e.preventDefault()},initColumnMenu(e){let t=e.closest(".fi-dropdown");if(h.has(t))return;let o=window.Alpine.$data(t),r=o.toggle.bind(o);h.add(t),o.toggle=n=>n?.type==="mousedown"?void 0:r(n)},columnMenuPress(e){this.columnMenuPressAt={x:e.clientX,y:e.clientY}},columnMenuClick(e){let t=this.columnMenuPressAt;this.columnMenuPressAt=null,!(t&&Math.hypot(e.clientX-t.x,e.clientY-t.y)>4)&&window.Alpine.$data(e.currentTarget.closest(".fi-dropdown")).toggle(e)},columnDrop(e){return this.dragOverColumn!==e?null:this.isColumnBlocked(e)?"blocked":"active"},cellDrop(e,t){return this.dragOverColumn!==e||this.dragOverLane!==t?null:this.isCellBlocked(e,t)?"blocked":"active"},canDrop(e,t){if(!this.$root.contains(e)||!this.$root.contains(t))return!1;let o=e.dataset.laneId??null,r=t.dataset.laneId??null;return o!==r&&this.$root.dataset.lanesWritable!=="true"?!1:!this.isColumnBlocked(e.dataset.columnId,t.dataset.columnId)},isColumnBlocked(e,t=this.dragSource?.column){if(!e||e===t)return!1;let o=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"]`),r=o?.dataset.columnLimit;return r===void 0||r===""?!1:Number(o.dataset.columnTotal)>=Number(r)},isCellBlocked(e,t){return this.dragSource?t!==this.dragSource.lane&&this.$root.dataset.lanesWritable!=="true"?!0:this.isColumnBlocked(e):!1},displayCount(e,t){let o=this.pendingCounts[e]??t,r=this.dragSource?.column,n=this.dragOverColumn;return!r||!n||r===n||this.isColumnBlocked(n)?o:e===n?o+1:e===r?o-1:o},holdMovedCounts(e,t){if(e===t)return()=>{};let o={[e]:-1,[t]:1},r=!1;for(let[n,a]of Object.entries(o))this.pendingCounts[n]=this.renderedCount(n)+a;return this.pendingMoves++,n=>{if(!r){if(r=!0,n)for(let[a,l]of Object.entries(o))this.pendingCounts[a]-=l;--this.pendingMoves===0&&(this.pendingCounts={})}}},renderedCount(e){let t=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"] .ff-count`);return this.pendingCounts[e]??Number(t?.dataset.total)},handleSortableEnd(e){this.endDrag();let t=e.item,o=e.to,r=e.newDraggableIndex??e.newIndex,n=":scope > [x-sortable-item], :scope > [data-card-id]",a=s=>s.getAttribute("x-sortable-item")||s.getAttribute("data-card-id");if(e.from===o&&e.oldDraggableIndex===e.newDraggableIndex)return;if(r===0){let s=o.querySelector(n);s&&s!==t&&o.insertBefore(t,s)}let l=a(t);if(!l){console.error("Flowforge: Could not determine card ID for move operation");return}let i=o.getAttribute("data-column-id");if(!i){console.error("Flowforge: Target column ID is missing");return}let p=e.from.dataset.laneId??null,C=o.dataset.laneId??null,u=o.querySelectorAll(n),d=Array.prototype.indexOf.call(u,t),b=d>0?a(u[d-1]):null,w=d>=0&&d{this.setCardState(t,!1),f(s===!1),s===!1&&this.revertCard(e)}).catch(()=>{this.setCardState(t,!1),f(!0),this.revertCard(e)})},revertCard({item:e,from:t,oldDraggableIndex:o}){e.remove();let r=t.querySelectorAll(":scope > [x-sortable-item]"),n=r[r.length-1],a=r[o]??(n?n.nextSibling:t.firstChild);t.insertBefore(e,a)},setCardState(e,t){e.toggleAttribute("data-pending",t)},isLaneCollapsed(e){return this.collapsedLanes[e]===!0},toggleLane(e){this.collapsedLanes[e]=!this.isLaneCollapsed(e)},isLoadingColumn(e){return this.isLoading[e]||!1},isColumnFullyLoaded(e){return this.fullyLoaded[e]||!1},handleSmoothScroll(e){this.isLoadingColumn(e)||this.isColumnFullyLoaded(e)||(this.isLoading[e]=!0,this.$wire.loadMoreItems(e).then(()=>setTimeout(()=>this.isLoading[e]=!1,100)).catch(()=>this.isLoading[e]=!1))},handleColumnScroll(e,t){if(this.isColumnFullyLoaded(t))return;let{scrollTop:o,scrollHeight:r,clientHeight:n}=e.target;(o+n)/r>=.8&&!this.isLoadingColumn(t)&&this.handleSmoothScroll(t)}}}export{L as default}; +var S=["--ff-surface","--ff-surface-sunken","--ff-surface-raised","--ff-border","--ff-text","--ff-text-muted","--ff-accent","--ff-accent-tint","--ff-danger","--ff-warning","--ff-radius","--ff-gap","--ff-ease","--ff-duration","--ff-column-width","--ff-tray-bg","--ff-tray-radius","--ff-card-bg","--ff-card-ring","--ff-card-radius","--ff-card-shadow","--ff-card-padding","--ff-drag-tilt","--ff-drag-shadow","--ff-placeholder-border"],g='.ff-column-actions, .fi-dropdown-panel, input, textarea, select, [contenteditable]:not([contenteditable="false"])';var h=new WeakSet,c=new WeakSet,m=()=>window.Sortable.active||window.Sortable.dragged;function y(){return{isLoading:{},fullyLoaded:{},dragOverColumn:null,railToggledAt:0,columnMenuPressAt:null,dragOverLane:null,dragSource:null,pendingCounts:{},pendingMoves:0,collapsedLanes:{},addingColumn:!1,newColumnName:"",newColumnTouched:!1,addingColumnPending:!1,placeholder:null,stopTrackingPointer:null,init(){this.$wire.$on("kanban-items-loaded",e=>{let{columnId:t,isFullyLoaded:o}=e;o&&(this.fullyLoaded[t]=!0)})},configureSortable(e){if(!e.sortable||e.sortable.options.forceFallback)return;if(m()){this.configureSortableAfterDrag(e);return}let t=window.matchMedia("(prefers-reduced-motion: reduce)").matches;e.sortable.destroy(),e.sortable=window.Sortable.create(e,{draggable:"[x-sortable-item]",handle:"[x-sortable-handle]",dataIdAttr:"x-sortable-item",forceFallback:!0,fallbackTolerance:5,fallbackOnBody:!0,fallbackClass:"",ghostClass:"",delay:150,delayOnTouchOnly:!0,animation:t?0:200,scrollSensitivity:100,scrollSpeed:15,forceAutoScrollFallback:!0,group:{name:e.getAttribute("x-sortable-group"),pull:!0,put:(o,n)=>this.canDrop(o.el,n.el)},onStart:o=>this.startDrag(o),onEnd(o){let{item:n,to:r,oldDraggableIndex:a,newDraggableIndex:i}=o;if(a===i)return;let l=r.querySelectorAll(`:scope > ${this.options.draggable}`)[i-1];l&&r.insertBefore(n,l.nextSibling)}})},configureSortableAfterDrag(e){if(c.has(e))return;c.add(e);let t=()=>{if(m()){requestAnimationFrame(t);return}c.delete(e),e.isConnected&&this.configureSortable(e)};requestAnimationFrame(t)},startDrag(e){this.stopTrackingPointer?.(),this.placeholder=e.item,this.placeholder.setAttribute("data-placeholder",""),this.markGhost(),window.getSelection()?.removeAllRanges(),document.documentElement.classList.add("ff-dragging"),this.dragSource={column:e.from.dataset.columnId,lane:e.from.dataset.laneId??null};let t=o=>this.trackPointer(o);document.addEventListener("pointermove",t,{passive:!0}),document.addEventListener("touchmove",t,{passive:!0}),this.stopTrackingPointer=()=>{document.removeEventListener("pointermove",t),document.removeEventListener("touchmove",t)}},trackPointer(e){if(!window.Sortable.active){this.endDrag();return}this.markGhost();let t=e.touches?.[0]??e,o=document.elementFromPoint(t.clientX,t.clientY),n=o?.closest("[data-column-id]"),r=o?.closest("[data-column-root]");this.dragOverColumn=n?.dataset.columnId??r?.dataset.columnRoot??null,this.dragOverLane=n?.dataset.laneId??null},markGhost(){let e=window.Sortable.ghost;if(!e||e.hasAttribute("data-dragging"))return;e.removeAttribute("data-placeholder"),e.setAttribute("data-dragging",""),e.style.opacity="1";let t=getComputedStyle(this.placeholder);for(let o of S){let n=t.getPropertyValue(o);n!==""&&e.style.setProperty(o,n)}},endDrag(){document.documentElement.classList.remove("ff-dragging"),this.placeholder?.removeAttribute("data-placeholder"),this.placeholder=null,this.stopTrackingPointer?.(),this.stopTrackingPointer=null,this.dragOverColumn=null,this.dragOverLane=null,this.dragSource=null},toggleColumnCollapse(e,t,o=!1){e.target.closest(g)||o&&e.detail>1||Date.now()-this.railToggledAt<500||(o&&(this.railToggledAt=Date.now()),this.$wire.toggleBoardColumnCollapse(t))},openNewColumn(){this.addingColumn=!0,this.newColumnTouched=!0,this.$nextTick(()=>this.$refs.newColumnInput.focus())},cancelNewColumn(){this.addingColumn=!1,this.newColumnTouched=!0,this.newColumnName=""},async submitNewColumn(){if(!this.addingColumnPending){this.addingColumnPending=!0,this.newColumnTouched=!0;try{await this.$wire.addBoardColumn(this.newColumnName)}finally{this.addingColumnPending=!1}this.newColumnTouched=!1,this.$root.querySelector(".ff-add-column-error")||this.cancelNewColumn()}},suppressDoubleClickSelection(e){e.detail>1&&!e.target.closest(g)&&e.preventDefault()},initColumnMenu(e){let t=e.closest(".fi-dropdown");if(h.has(t))return;let o=window.Alpine.$data(t),n=o.toggle.bind(o);h.add(t),o.toggle=r=>r?.type==="mousedown"?void 0:n(r)},columnMenuPress(e){this.columnMenuPressAt={x:e.clientX,y:e.clientY}},columnMenuClick(e){let t=this.columnMenuPressAt;this.columnMenuPressAt=null,!(t&&Math.hypot(e.clientX-t.x,e.clientY-t.y)>4)&&window.Alpine.$data(e.currentTarget.closest(".fi-dropdown")).toggle(e)},columnDrop(e){return this.dragOverColumn!==e?null:this.isColumnBlocked(e)?"blocked":"active"},cellDrop(e,t){return this.dragOverColumn!==e||this.dragOverLane!==t?null:this.isCellBlocked(e,t)?"blocked":"active"},canDrop(e,t){if(!this.$root.contains(e)||!this.$root.contains(t))return!1;let o=e.dataset.laneId??null,n=t.dataset.laneId??null;return o!==n&&this.$root.dataset.lanesWritable!=="true"?!1:!this.isColumnBlocked(e.dataset.columnId,t.dataset.columnId)},isColumnBlocked(e,t=this.dragSource?.column){if(!e||e===t)return!1;let o=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"]`),n=o?.dataset.columnLimit;return n===void 0||n===""?!1:Number(o.dataset.columnTotal)>=Number(n)},isCellBlocked(e,t){return this.dragSource?t!==this.dragSource.lane&&this.$root.dataset.lanesWritable!=="true"?!0:this.isColumnBlocked(e):!1},displayCount(e,t){let o=this.pendingCounts[e]??t,n=this.dragSource?.column,r=this.dragOverColumn;return!n||!r||n===r||this.isColumnBlocked(r)?o:e===r?o+1:e===n?o-1:o},holdMovedCounts(e,t){if(e===t)return()=>{};let o={[e]:-1,[t]:1},n=!1;for(let[r,a]of Object.entries(o))this.pendingCounts[r]=this.renderedCount(r)+a;return this.pendingMoves++,r=>{if(!n){if(n=!0,r)for(let[a,i]of Object.entries(o))this.pendingCounts[a]-=i;--this.pendingMoves===0&&(this.pendingCounts={})}}},renderedCount(e){let t=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"] .ff-count`);return this.pendingCounts[e]??Number(t?.dataset.total)},handleSortableEnd(e){this.endDrag();let t=e.item,o=e.to,n=e.newDraggableIndex??e.newIndex,r=":scope > [x-sortable-item], :scope > [data-card-id]",a=s=>s.getAttribute("x-sortable-item")||s.getAttribute("data-card-id");if(e.from===o&&e.oldDraggableIndex===e.newDraggableIndex)return;if(n===0){let s=o.querySelector(r);s&&s!==t&&o.insertBefore(t,s)}let i=a(t);if(!i){console.error("Flowforge: Could not determine card ID for move operation");return}let l=o.getAttribute("data-column-id");if(!l){console.error("Flowforge: Target column ID is missing");return}let p=e.from.dataset.laneId??null,C=o.dataset.laneId??null,u=o.querySelectorAll(r),d=Array.prototype.indexOf.call(u,t),b=d>0?a(u[d-1]):null,w=d>=0&&d{this.setCardState(t,!1),f(s===!1),s===!1&&this.revertCard(e)}).catch(()=>{this.setCardState(t,!1),f(!0),this.revertCard(e)})},revertCard({item:e,from:t,oldDraggableIndex:o}){e.remove();let n=t.querySelectorAll(":scope > [x-sortable-item]"),r=n[n.length-1],a=n[o]??(r?r.nextSibling:t.firstChild);t.insertBefore(e,a)},setCardState(e,t){e.toggleAttribute("data-pending",t)},isLaneCollapsed(e){return this.collapsedLanes[e]===!0},toggleLane(e){this.collapsedLanes[e]=!this.isLaneCollapsed(e)},isLoadingColumn(e){return this.isLoading[e]||!1},isColumnFullyLoaded(e){return this.fullyLoaded[e]||!1},handleSmoothScroll(e){this.isLoadingColumn(e)||this.isColumnFullyLoaded(e)||(this.isLoading[e]=!0,this.$wire.loadMoreItems(e).then(()=>setTimeout(()=>this.isLoading[e]=!1,100)).catch(()=>this.isLoading[e]=!1))},handleColumnScroll(e,t){if(this.isColumnFullyLoaded(t))return;let{scrollTop:o,scrollHeight:n,clientHeight:r}=e.target;(o+r)/n>=.8&&!this.isLoadingColumn(t)&&this.handleSmoothScroll(t)}}}export{y as default}; diff --git a/resources/js/flowforge-modern.js b/resources/js/flowforge-modern.js index 74074cf15..983eda99e 100644 --- a/resources/js/flowforge-modern.js +++ b/resources/js/flowforge-modern.js @@ -52,6 +52,7 @@ export default function flowforgeModern() { addingColumn: false, newColumnName: '', newColumnTouched: false, + addingColumnPending: false, placeholder: null, stopTrackingPointer: null, @@ -250,13 +251,25 @@ export default function flowforgeModern() { cancelNewColumn() { this.addingColumn = false; + this.newColumnTouched = true; this.newColumnName = ''; }, async submitNewColumn() { - this.newColumnTouched = false; + if (this.addingColumnPending) { + return; + } - await this.$wire.addBoardColumn(this.newColumnName); + this.addingColumnPending = true; + this.newColumnTouched = true; + + try { + await this.$wire.addBoardColumn(this.newColumnName); + } finally { + this.addingColumnPending = false; + } + + this.newColumnTouched = false; if (!this.$root.querySelector('.ff-add-column-error')) { this.cancelNewColumn(); diff --git a/tests/Browser/ModernBoardTest.php b/tests/Browser/ModernBoardTest.php index e79dd0bb4..bd260bdfb 100644 --- a/tests/Browser/ModernBoardTest.php +++ b/tests/Browser/ModernBoardTest.php @@ -1082,3 +1082,111 @@ function boardTraySampler(int $budgetMilliseconds): string expect($page->script("document.querySelector('{$input}').offsetParent !== null"))->toBeTrue(); }); + +test('the add column tile leaves the lane heads row height unchanged', function () { + boardSeed('high'); + $height = "document.querySelector('.ff-lanes-heads').offsetHeight"; + + $without = boardPage('/modern/test-grouped-board?groupBy=priority')->script($height); + $page = boardPage('/modern/test-add-column-grouped-board?groupBy=priority'); + + expect($page->script($height))->toBe($without); +}); + +test('pressing enter twice quickly adds the column once', function () { + boardSeed(); + $page = boardPage('/modern/test-add-column-board'); + $pointer = Pointer::on($page); + $input = '.ff-add-column-input'; + + $pointer->click('.ff-add-column-button'); + $pointer->untilScript("document.activeElement === document.querySelector('{$input}')"); + $page->type($input, 'Won'); + $page->script(<<<'JS' + (() => { + window.__addCalls = 0; + + window.Livewire.hook('commit', ({ commit }) => { + window.__addCalls += (commit.calls ?? []).filter((call) => call.method === 'addBoardColumn').length; + }); + })() + JS); + $page->script(<<<'JS' + (async () => { + const form = document.querySelector('.ff-add-column-form'); + + form.requestSubmit(); + await new Promise((resolve) => setTimeout(resolve, 20)); + form.requestSubmit(); + })() + JS); + $pointer->untilScript("document.querySelectorAll('[data-column-root=\"Won\"]').length >= 1"); + $pointer->wait(600); + + expect($page->script("document.querySelectorAll('[data-column-root=\"Won\"]').length"))->toBe(1) + ->and($page->script('window.__addCalls'))->toBe(1); +}); + +test('a host rejection shows under the input, hides while the next submit is pending, and a valid name then adds the column', function () { + boardSeed(); + $page = boardPage('/modern/test-add-column-board'); + $pointer = Pointer::on($page); + $input = '.ff-add-column-input'; + $error = '.ff-add-column-error'; + + $pointer->click('.ff-add-column-button'); + $pointer->untilScript("document.activeElement === document.querySelector('{$input}')"); + $page->type($input, 'Lost'); + $page->keys($input, 'Enter'); + $pointer->untilScript("document.querySelector('{$error}')?.offsetParent !== null && document.querySelector('{$error}') !== null"); + + expect($page->script("document.querySelector('{$error}').innerText.trim()"))->toBe('Taken'); + + boardHoldUpdates($page); + $page->type($input, 'Won'); + $page->keys($input, 'Enter'); + $pointer->wait(300); + + expect($page->script("document.querySelector('{$error}') === null || document.querySelector('{$error}').offsetParent === null"))->toBeTrue(); + + boardReleaseUpdates($page); + $pointer->untilScript("document.querySelectorAll('[data-column-root=\"Won\"]').length === 1"); + $pointer->untilScript("document.querySelector('{$input}').offsetParent === null"); +}); + +test('reopening the add column input after escape shows no stale error', function () { + boardSeed(); + $page = boardPage('/modern/test-add-column-board'); + $pointer = Pointer::on($page); + $input = '.ff-add-column-input'; + $error = '.ff-add-column-error'; + + $pointer->click('.ff-add-column-button'); + $pointer->untilScript("document.activeElement === document.querySelector('{$input}')"); + $page->type($input, 'Lost'); + $page->keys($input, 'Enter'); + $pointer->untilScript("document.querySelector('{$error}')?.offsetParent !== null && document.querySelector('{$error}') !== null"); + $page->keys($input, 'Escape'); + $pointer->untilScript("document.querySelector('{$input}').offsetParent === null"); + $pointer->click('.ff-add-column-button'); + $pointer->untilScript("document.activeElement === document.querySelector('{$input}')"); + + expect($page->script("document.querySelector('{$error}') === null || document.querySelector('{$error}').offsetParent === null"))->toBeTrue(); +}); + +test('the add column tile in lanes adds a column and every lane gets its cell', function () { + boardSeed('high'); + Task::query()->create(['title' => 'Low one', 'status' => 'todo', 'order_position' => '9000.0000000000', 'priority' => 'low']); + $page = boardPage('/modern/test-add-column-grouped-board?groupBy=priority'); + $pointer = Pointer::on($page); + $input = '.ff-add-column-input'; + + $pointer->click('.ff-add-column-button'); + $pointer->untilScript("document.activeElement === document.querySelector('{$input}')"); + $page->type($input, 'Won'); + $page->keys($input, 'Enter'); + $pointer->untilScript("document.querySelectorAll('.ff-lanes-heads [data-column-root=\"Won\"]').length === 1"); + + expect($page->script("document.querySelectorAll('.ff-cell').length"))->toBe(2 * 3) + ->and($page->script("document.querySelectorAll('[data-column-id=\"Won\"]').length"))->toBe(2); +}); diff --git a/tests/Fixtures/Modern/ModernPanelProvider.php b/tests/Fixtures/Modern/ModernPanelProvider.php index df257fb85..72d4e6fb9 100644 --- a/tests/Fixtures/Modern/ModernPanelProvider.php +++ b/tests/Fixtures/Modern/ModernPanelProvider.php @@ -29,6 +29,7 @@ public function panel(Panel $panel): Panel ->pages([ TestBoard::class, TestAddColumnBoard::class, + TestAddColumnGroupedBoard::class, TestBrowserBoard::class, TestClassicBoard::class, TestCollapsibleBoard::class, diff --git a/tests/Fixtures/Modern/TestAddColumnBoard.php b/tests/Fixtures/Modern/TestAddColumnBoard.php index 5e4b9c535..4a494d42f 100644 --- a/tests/Fixtures/Modern/TestAddColumnBoard.php +++ b/tests/Fixtures/Modern/TestAddColumnBoard.php @@ -7,4 +7,6 @@ class TestAddColumnBoard extends TestBoard { public bool $withAddColumn = true; + + public ?string $rejectColumnName = 'Lost'; } diff --git a/tests/Fixtures/Modern/TestAddColumnGroupedBoard.php b/tests/Fixtures/Modern/TestAddColumnGroupedBoard.php new file mode 100644 index 000000000..dafb99f07 --- /dev/null +++ b/tests/Fixtures/Modern/TestAddColumnGroupedBoard.php @@ -0,0 +1,10 @@ + Date: Sat, 14 Nov 2026 04:39:28 +0400 Subject: [PATCH 12/34] docs(columns): describe column controls in the skill and tile border --- docs/content/2.essentials/7.design-system.md | 2 +- resources/boost/skills/flowforge-development/SKILL.md | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/content/2.essentials/7.design-system.md b/docs/content/2.essentials/7.design-system.md index 2c30d6627..28c5df67e 100644 --- a/docs/content/2.essentials/7.design-system.md +++ b/docs/content/2.essentials/7.design-system.md @@ -42,7 +42,7 @@ The dark column shows where the default changes under Filament's `.dark` class. | `--ff-surface` | semantic | `var(--gray-50)` / `var(--gray-950)` | 4.2.0 | Background of the sticky column-header strip in the lane view. Set it to the page background. | | `--ff-surface-sunken` | semantic | `var(--gray-100)` / `color-mix(in oklab, #fff 5%, transparent)` | 4.2.0 | Background of a column tray and of a lane cell. `--ff-tray-bg` overrides it. | | `--ff-surface-raised` | semantic | `#fff` / `var(--gray-900)` | 4.2.0 | Background of a card and of the filters panel. `--ff-card-bg` overrides it for cards. | -| `--ff-border` | semantic | `color-mix(in oklab, var(--gray-950) 5%, transparent)` / `color-mix(in oklab, #fff 10%, transparent)` | 4.2.0 | Ring around a card and around the filters panel, and the dashed border of the add column tile. `--ff-card-ring` overrides it for cards. | +| `--ff-border` | semantic | `color-mix(in oklab, var(--gray-950) 5%, transparent)` / `color-mix(in oklab, #fff 10%, transparent)` | 4.2.0 | Ring around a card and around the filters panel. `--ff-card-ring` overrides it for cards. The add column tile's dashed border also reads it when set, and otherwise uses a stronger default (15% light, 20% dark). | | `--ff-text` | semantic | `var(--gray-950)` / `#fff` | 4.2.0 | Column titles, lane titles, card titles and the add row on hover. | | `--ff-text-muted` | semantic | `var(--gray-500)` / `var(--gray-400)` | 4.2.0 | Secondary text and icons: the group-by label, column icons, counts, summaries, tags, card meta, the add row, the avatar overflow, lane counts and icons, and the header subheading. | | `--ff-accent` | semantic | `var(--primary-500)` | 4.2.0 | Outline of an accepting drop target, the drop gap border and the loading text. | diff --git a/resources/boost/skills/flowforge-development/SKILL.md b/resources/boost/skills/flowforge-development/SKILL.md index 079ab9777..77dc2b187 100644 --- a/resources/boost/skills/flowforge-development/SKILL.md +++ b/resources/boost/skills/flowforge-development/SKILL.md @@ -361,7 +361,11 @@ The closure gets the column's query with the active filters and search applied. ]) ``` -A "Group by" select appears and the choice lives in `?groupBy=`. `lanes()` returns `Lane::make($name)->label()->query(fn (Builder $query) => ...)` objects. Give every custom grouping an `emptyLane()`, because the header `+` creates a card without knowing the lane. Without `moveUsing()` the lanes are read-only. Throw `CardMoveRejectedException::because('...')` in `moveUsing()` to refuse a move and roll back both writes. `collapseEmptyColumns()` applies to the plain board only. +A "Group by" select appears and the choice lives in `?groupBy=`. `lanes()` returns `Lane::make($name)->label()->query(fn (Builder $query) => ...)` objects. Give every custom grouping an `emptyLane()`, because the header `+` creates a card without knowing the lane. Without `moveUsing()` the lanes are read-only. Throw `CardMoveRejectedException::because('...')` in `moveUsing()` to refuse a move and roll back both writes. `collapseEmptyColumns()` applies to the plain board only. Columns collapsed with `collapsedColumns()` or `collapseAllColumns()` hold in lanes too: each takes a narrow track, its cells show their count, and the track opens while a card is dragged. + +### Column controls + +The host owns the state and Flowforge renders it. `collapsedColumns(fn () => [...])` and `collapseAllColumns(fn () => ...)` collapse columns. `collapsibleColumns(fn (string $columnId, bool $collapsed) => ...)` lets a double-click on a header collapse it and a click on its rail expand it. Only columns listed in `collapsedColumns()` expand by click. `columnHeaderMenu(fn (array $column): ?Htmlable => ...)` turns the header into a menu holding the host block above the column actions. `addColumnUsing(fn (string $name) => ...)` with `addColumnLabel()` adds a tile after the last column; throw a `ValidationException` to show a message under its input. Pass any value the page changes during a request as a closure, because the board is built before the action runs. ### Styling a Modern Board From 7af62c92e613ee8885ec00751514ba793606d8bc Mon Sep 17 00:00:00 2001 From: Manuk Date: Sat, 14 Nov 2026 04:59:40 +0400 Subject: [PATCH 13/34] fix(columns): draw a collapsed column as one aligned rail without its add button --- resources/css/flowforge-modern.css | 15 ++++++------- .../views/modern/livewire/column.blade.php | 8 ++++++- tests/Browser/ModernBoardTest.php | 13 ++++++++++++ tests/Fixtures/Modern/ModernPanelProvider.php | 1 + .../Fixtures/Modern/TestCollapsedAllBoard.php | 12 +++++++++++ tests/Modern/Feature/CollapsedColumnsTest.php | 21 +++++++++++++++++++ 6 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 tests/Fixtures/Modern/TestCollapsedAllBoard.php diff --git a/resources/css/flowforge-modern.css b/resources/css/flowforge-modern.css index 086900b81..5c06ca062 100644 --- a/resources/css/flowforge-modern.css +++ b/resources/css/flowforge-modern.css @@ -202,11 +202,6 @@ padding: 0 0.25rem 0.5rem; } - .ff-column[data-collapsed]:not([data-drop], .ff-lanes-heads .ff-column) .ff-column-header { - flex-direction: column; - justify-content: normal; - } - .ff-column-heading { display: flex; align-items: center; @@ -214,8 +209,14 @@ min-width: 0; } - .ff-column[data-collapsed]:not([data-drop], .ff-lanes-heads .ff-column) .ff-column-heading { - display: contents; + .ff-tray > .ff-column-heading { + flex-shrink: 0; + padding: 0.75rem 0.25rem 0; + } + + .ff-column[data-collapsed]:not([data-drop], .ff-lanes-heads .ff-column) .ff-tray > .ff-column-heading { + flex-direction: column; + justify-content: flex-start; } .ff-column-dot { diff --git a/resources/views/modern/livewire/column.blade.php b/resources/views/modern/livewire/column.blade.php index fdf9fb033..22a29b4d8 100644 --- a/resources/views/modern/livewire/column.blade.php +++ b/resources/views/modern/livewire/column.blade.php @@ -27,13 +27,19 @@ class="ff-column" @endif x-bind:data-drop="columnDrop(@js((string) $columnId))" > - + @unless ($isCollapsed) + + @endunless
+ @if ($isCollapsed) + + @endif + @if (($column['limit'] ?? null) !== null)

untilEquals(fn () => boardStyle($page, $root, 'width'), '48px', 'the rail width after the drop'); }); +test('every collapsed rail starts at the same top and none draws an add card button', function () { + boardSeed(); + $page = boardPage('/modern/test-collapsed-all-board'); + + $tops = $page->script('[...document.querySelectorAll(".ff-column[data-collapsed] .ff-tray")].map((tray) => tray.getBoundingClientRect().top)'); + $labelTops = $page->script('[...document.querySelectorAll(".ff-column[data-collapsed] .ff-column-heading")].map((heading) => Math.round(heading.getBoundingClientRect().top))'); + + expect($tops)->toHaveCount(3) + ->and(array_unique($tops))->toHaveCount(1) + ->and(array_unique($labelTops))->toHaveCount(1) + ->and($page->script('document.querySelectorAll(".ff-column[data-collapsed] .ff-column-actions, .ff-column[data-collapsed] .ff-add-slot").length'))->toBe(0); +}); + test('double clicking a collapsed rail expands it', function () { boardSeed(); $page = boardPage('/modern/test-collapsible-board'); diff --git a/tests/Fixtures/Modern/ModernPanelProvider.php b/tests/Fixtures/Modern/ModernPanelProvider.php index 72d4e6fb9..26751e6a0 100644 --- a/tests/Fixtures/Modern/ModernPanelProvider.php +++ b/tests/Fixtures/Modern/ModernPanelProvider.php @@ -33,6 +33,7 @@ public function panel(Panel $panel): Panel TestBrowserBoard::class, TestClassicBoard::class, TestCollapsibleBoard::class, + TestCollapsedAllBoard::class, TestMenuBoard::class, TestMenuStaticBoard::class, TestContractBoard::class, diff --git a/tests/Fixtures/Modern/TestCollapsedAllBoard.php b/tests/Fixtures/Modern/TestCollapsedAllBoard.php new file mode 100644 index 000000000..c5a8611d5 --- /dev/null +++ b/tests/Fixtures/Modern/TestCollapsedAllBoard.php @@ -0,0 +1,12 @@ + []])->html(); + $collapsed = Livewire::test(TestCollapsibleBoard::class, ['collapseAll' => true])->html(); + + expect($expanded)->toContain('ff-column-actions') + ->and($collapsed)->not->toContain('ff-column-actions') + ->and($collapsed)->not->toContain('ff-column-header') + ->and($collapsed)->not->toContain('ff-add-slot'); + }); + + test('a collapsed column draws its label inside the tray', function () { + $html = Livewire::test(TestBoard::class, ['collapsedIds' => ['in_progress']])->html(); + + $own = '(?:(?!data-column-root).)*?'; + + expect($html)->toMatch('/data-column-root="in_progress"[^>]*data-collapsed' . $own . 'class="ff-tray"' . $own . 'ff-column-heading' . $own . 'ff-column-title[^>]*>\s*In Progress' . $own . 'class="ff-cards"/s'); + }); +}); + describe('toggling collapse', function () { test('toggling an expanded column asks the host to collapse it', function () { $component = Livewire::test(TestBoard::class, ['collapsible' => true]) From 5234d31753d44e96e33d50c843dfef5c955ad0f9 Mon Sep 17 00:00:00 2001 From: Manuk Date: Sat, 14 Nov 2026 05:13:24 +0400 Subject: [PATCH 14/34] fix(columns): ignore a rail click that ended a drag --- resources/dist/flowforge-modern.js | 2 +- resources/js/flowforge-modern.js | 15 +++++++++++++++ resources/views/modern/livewire/column.blade.php | 1 + resources/views/modern/livewire/lanes.blade.php | 1 + tests/Browser/ModernBoardTest.php | 14 ++++++++++++++ 5 files changed, 32 insertions(+), 1 deletion(-) diff --git a/resources/dist/flowforge-modern.js b/resources/dist/flowforge-modern.js index 2abce155f..fdf19eb5c 100644 --- a/resources/dist/flowforge-modern.js +++ b/resources/dist/flowforge-modern.js @@ -1 +1 @@ -var S=["--ff-surface","--ff-surface-sunken","--ff-surface-raised","--ff-border","--ff-text","--ff-text-muted","--ff-accent","--ff-accent-tint","--ff-danger","--ff-warning","--ff-radius","--ff-gap","--ff-ease","--ff-duration","--ff-column-width","--ff-tray-bg","--ff-tray-radius","--ff-card-bg","--ff-card-ring","--ff-card-radius","--ff-card-shadow","--ff-card-padding","--ff-drag-tilt","--ff-drag-shadow","--ff-placeholder-border"],g='.ff-column-actions, .fi-dropdown-panel, input, textarea, select, [contenteditable]:not([contenteditable="false"])';var h=new WeakSet,c=new WeakSet,m=()=>window.Sortable.active||window.Sortable.dragged;function y(){return{isLoading:{},fullyLoaded:{},dragOverColumn:null,railToggledAt:0,columnMenuPressAt:null,dragOverLane:null,dragSource:null,pendingCounts:{},pendingMoves:0,collapsedLanes:{},addingColumn:!1,newColumnName:"",newColumnTouched:!1,addingColumnPending:!1,placeholder:null,stopTrackingPointer:null,init(){this.$wire.$on("kanban-items-loaded",e=>{let{columnId:t,isFullyLoaded:o}=e;o&&(this.fullyLoaded[t]=!0)})},configureSortable(e){if(!e.sortable||e.sortable.options.forceFallback)return;if(m()){this.configureSortableAfterDrag(e);return}let t=window.matchMedia("(prefers-reduced-motion: reduce)").matches;e.sortable.destroy(),e.sortable=window.Sortable.create(e,{draggable:"[x-sortable-item]",handle:"[x-sortable-handle]",dataIdAttr:"x-sortable-item",forceFallback:!0,fallbackTolerance:5,fallbackOnBody:!0,fallbackClass:"",ghostClass:"",delay:150,delayOnTouchOnly:!0,animation:t?0:200,scrollSensitivity:100,scrollSpeed:15,forceAutoScrollFallback:!0,group:{name:e.getAttribute("x-sortable-group"),pull:!0,put:(o,n)=>this.canDrop(o.el,n.el)},onStart:o=>this.startDrag(o),onEnd(o){let{item:n,to:r,oldDraggableIndex:a,newDraggableIndex:i}=o;if(a===i)return;let l=r.querySelectorAll(`:scope > ${this.options.draggable}`)[i-1];l&&r.insertBefore(n,l.nextSibling)}})},configureSortableAfterDrag(e){if(c.has(e))return;c.add(e);let t=()=>{if(m()){requestAnimationFrame(t);return}c.delete(e),e.isConnected&&this.configureSortable(e)};requestAnimationFrame(t)},startDrag(e){this.stopTrackingPointer?.(),this.placeholder=e.item,this.placeholder.setAttribute("data-placeholder",""),this.markGhost(),window.getSelection()?.removeAllRanges(),document.documentElement.classList.add("ff-dragging"),this.dragSource={column:e.from.dataset.columnId,lane:e.from.dataset.laneId??null};let t=o=>this.trackPointer(o);document.addEventListener("pointermove",t,{passive:!0}),document.addEventListener("touchmove",t,{passive:!0}),this.stopTrackingPointer=()=>{document.removeEventListener("pointermove",t),document.removeEventListener("touchmove",t)}},trackPointer(e){if(!window.Sortable.active){this.endDrag();return}this.markGhost();let t=e.touches?.[0]??e,o=document.elementFromPoint(t.clientX,t.clientY),n=o?.closest("[data-column-id]"),r=o?.closest("[data-column-root]");this.dragOverColumn=n?.dataset.columnId??r?.dataset.columnRoot??null,this.dragOverLane=n?.dataset.laneId??null},markGhost(){let e=window.Sortable.ghost;if(!e||e.hasAttribute("data-dragging"))return;e.removeAttribute("data-placeholder"),e.setAttribute("data-dragging",""),e.style.opacity="1";let t=getComputedStyle(this.placeholder);for(let o of S){let n=t.getPropertyValue(o);n!==""&&e.style.setProperty(o,n)}},endDrag(){document.documentElement.classList.remove("ff-dragging"),this.placeholder?.removeAttribute("data-placeholder"),this.placeholder=null,this.stopTrackingPointer?.(),this.stopTrackingPointer=null,this.dragOverColumn=null,this.dragOverLane=null,this.dragSource=null},toggleColumnCollapse(e,t,o=!1){e.target.closest(g)||o&&e.detail>1||Date.now()-this.railToggledAt<500||(o&&(this.railToggledAt=Date.now()),this.$wire.toggleBoardColumnCollapse(t))},openNewColumn(){this.addingColumn=!0,this.newColumnTouched=!0,this.$nextTick(()=>this.$refs.newColumnInput.focus())},cancelNewColumn(){this.addingColumn=!1,this.newColumnTouched=!0,this.newColumnName=""},async submitNewColumn(){if(!this.addingColumnPending){this.addingColumnPending=!0,this.newColumnTouched=!0;try{await this.$wire.addBoardColumn(this.newColumnName)}finally{this.addingColumnPending=!1}this.newColumnTouched=!1,this.$root.querySelector(".ff-add-column-error")||this.cancelNewColumn()}},suppressDoubleClickSelection(e){e.detail>1&&!e.target.closest(g)&&e.preventDefault()},initColumnMenu(e){let t=e.closest(".fi-dropdown");if(h.has(t))return;let o=window.Alpine.$data(t),n=o.toggle.bind(o);h.add(t),o.toggle=r=>r?.type==="mousedown"?void 0:n(r)},columnMenuPress(e){this.columnMenuPressAt={x:e.clientX,y:e.clientY}},columnMenuClick(e){let t=this.columnMenuPressAt;this.columnMenuPressAt=null,!(t&&Math.hypot(e.clientX-t.x,e.clientY-t.y)>4)&&window.Alpine.$data(e.currentTarget.closest(".fi-dropdown")).toggle(e)},columnDrop(e){return this.dragOverColumn!==e?null:this.isColumnBlocked(e)?"blocked":"active"},cellDrop(e,t){return this.dragOverColumn!==e||this.dragOverLane!==t?null:this.isCellBlocked(e,t)?"blocked":"active"},canDrop(e,t){if(!this.$root.contains(e)||!this.$root.contains(t))return!1;let o=e.dataset.laneId??null,n=t.dataset.laneId??null;return o!==n&&this.$root.dataset.lanesWritable!=="true"?!1:!this.isColumnBlocked(e.dataset.columnId,t.dataset.columnId)},isColumnBlocked(e,t=this.dragSource?.column){if(!e||e===t)return!1;let o=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"]`),n=o?.dataset.columnLimit;return n===void 0||n===""?!1:Number(o.dataset.columnTotal)>=Number(n)},isCellBlocked(e,t){return this.dragSource?t!==this.dragSource.lane&&this.$root.dataset.lanesWritable!=="true"?!0:this.isColumnBlocked(e):!1},displayCount(e,t){let o=this.pendingCounts[e]??t,n=this.dragSource?.column,r=this.dragOverColumn;return!n||!r||n===r||this.isColumnBlocked(r)?o:e===r?o+1:e===n?o-1:o},holdMovedCounts(e,t){if(e===t)return()=>{};let o={[e]:-1,[t]:1},n=!1;for(let[r,a]of Object.entries(o))this.pendingCounts[r]=this.renderedCount(r)+a;return this.pendingMoves++,r=>{if(!n){if(n=!0,r)for(let[a,i]of Object.entries(o))this.pendingCounts[a]-=i;--this.pendingMoves===0&&(this.pendingCounts={})}}},renderedCount(e){let t=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"] .ff-count`);return this.pendingCounts[e]??Number(t?.dataset.total)},handleSortableEnd(e){this.endDrag();let t=e.item,o=e.to,n=e.newDraggableIndex??e.newIndex,r=":scope > [x-sortable-item], :scope > [data-card-id]",a=s=>s.getAttribute("x-sortable-item")||s.getAttribute("data-card-id");if(e.from===o&&e.oldDraggableIndex===e.newDraggableIndex)return;if(n===0){let s=o.querySelector(r);s&&s!==t&&o.insertBefore(t,s)}let i=a(t);if(!i){console.error("Flowforge: Could not determine card ID for move operation");return}let l=o.getAttribute("data-column-id");if(!l){console.error("Flowforge: Target column ID is missing");return}let p=e.from.dataset.laneId??null,C=o.dataset.laneId??null,u=o.querySelectorAll(r),d=Array.prototype.indexOf.call(u,t),b=d>0?a(u[d-1]):null,w=d>=0&&d{this.setCardState(t,!1),f(s===!1),s===!1&&this.revertCard(e)}).catch(()=>{this.setCardState(t,!1),f(!0),this.revertCard(e)})},revertCard({item:e,from:t,oldDraggableIndex:o}){e.remove();let n=t.querySelectorAll(":scope > [x-sortable-item]"),r=n[n.length-1],a=n[o]??(r?r.nextSibling:t.firstChild);t.insertBefore(e,a)},setCardState(e,t){e.toggleAttribute("data-pending",t)},isLaneCollapsed(e){return this.collapsedLanes[e]===!0},toggleLane(e){this.collapsedLanes[e]=!this.isLaneCollapsed(e)},isLoadingColumn(e){return this.isLoading[e]||!1},isColumnFullyLoaded(e){return this.fullyLoaded[e]||!1},handleSmoothScroll(e){this.isLoadingColumn(e)||this.isColumnFullyLoaded(e)||(this.isLoading[e]=!0,this.$wire.loadMoreItems(e).then(()=>setTimeout(()=>this.isLoading[e]=!1,100)).catch(()=>this.isLoading[e]=!1))},handleColumnScroll(e,t){if(this.isColumnFullyLoaded(t))return;let{scrollTop:o,scrollHeight:n,clientHeight:r}=e.target;(o+r)/n>=.8&&!this.isLoadingColumn(t)&&this.handleSmoothScroll(t)}}}export{y as default}; +var S=["--ff-surface","--ff-surface-sunken","--ff-surface-raised","--ff-border","--ff-text","--ff-text-muted","--ff-accent","--ff-accent-tint","--ff-danger","--ff-warning","--ff-radius","--ff-gap","--ff-ease","--ff-duration","--ff-column-width","--ff-tray-bg","--ff-tray-radius","--ff-card-bg","--ff-card-ring","--ff-card-radius","--ff-card-shadow","--ff-card-padding","--ff-drag-tilt","--ff-drag-shadow","--ff-placeholder-border"],g='.ff-column-actions, .fi-dropdown-panel, input, textarea, select, [contenteditable]:not([contenteditable="false"])';var h=new WeakSet,c=new WeakSet,m=()=>window.Sortable.active||window.Sortable.dragged;function y(){return{isLoading:{},fullyLoaded:{},dragOverColumn:null,railToggledAt:0,columnMenuPressAt:null,railPressAt:null,dragOverLane:null,dragSource:null,pendingCounts:{},pendingMoves:0,collapsedLanes:{},addingColumn:!1,newColumnName:"",newColumnTouched:!1,addingColumnPending:!1,placeholder:null,stopTrackingPointer:null,init(){this.$wire.$on("kanban-items-loaded",e=>{let{columnId:t,isFullyLoaded:o}=e;o&&(this.fullyLoaded[t]=!0)})},configureSortable(e){if(!e.sortable||e.sortable.options.forceFallback)return;if(m()){this.configureSortableAfterDrag(e);return}let t=window.matchMedia("(prefers-reduced-motion: reduce)").matches;e.sortable.destroy(),e.sortable=window.Sortable.create(e,{draggable:"[x-sortable-item]",handle:"[x-sortable-handle]",dataIdAttr:"x-sortable-item",forceFallback:!0,fallbackTolerance:5,fallbackOnBody:!0,fallbackClass:"",ghostClass:"",delay:150,delayOnTouchOnly:!0,animation:t?0:200,scrollSensitivity:100,scrollSpeed:15,forceAutoScrollFallback:!0,group:{name:e.getAttribute("x-sortable-group"),pull:!0,put:(o,r)=>this.canDrop(o.el,r.el)},onStart:o=>this.startDrag(o),onEnd(o){let{item:r,to:n,oldDraggableIndex:a,newDraggableIndex:i}=o;if(a===i)return;let l=n.querySelectorAll(`:scope > ${this.options.draggable}`)[i-1];l&&n.insertBefore(r,l.nextSibling)}})},configureSortableAfterDrag(e){if(c.has(e))return;c.add(e);let t=()=>{if(m()){requestAnimationFrame(t);return}c.delete(e),e.isConnected&&this.configureSortable(e)};requestAnimationFrame(t)},startDrag(e){this.stopTrackingPointer?.(),this.placeholder=e.item,this.placeholder.setAttribute("data-placeholder",""),this.markGhost(),window.getSelection()?.removeAllRanges(),document.documentElement.classList.add("ff-dragging"),this.dragSource={column:e.from.dataset.columnId,lane:e.from.dataset.laneId??null};let t=o=>this.trackPointer(o);document.addEventListener("pointermove",t,{passive:!0}),document.addEventListener("touchmove",t,{passive:!0}),this.stopTrackingPointer=()=>{document.removeEventListener("pointermove",t),document.removeEventListener("touchmove",t)}},trackPointer(e){if(!window.Sortable.active){this.endDrag();return}this.markGhost();let t=e.touches?.[0]??e,o=document.elementFromPoint(t.clientX,t.clientY),r=o?.closest("[data-column-id]"),n=o?.closest("[data-column-root]");this.dragOverColumn=r?.dataset.columnId??n?.dataset.columnRoot??null,this.dragOverLane=r?.dataset.laneId??null},markGhost(){let e=window.Sortable.ghost;if(!e||e.hasAttribute("data-dragging"))return;e.removeAttribute("data-placeholder"),e.setAttribute("data-dragging",""),e.style.opacity="1";let t=getComputedStyle(this.placeholder);for(let o of S){let r=t.getPropertyValue(o);r!==""&&e.style.setProperty(o,r)}},endDrag(){document.documentElement.classList.remove("ff-dragging"),this.placeholder?.removeAttribute("data-placeholder"),this.placeholder=null,this.stopTrackingPointer?.(),this.stopTrackingPointer=null,this.dragOverColumn=null,this.dragOverLane=null,this.dragSource=null},railPress(e){this.railPressAt={x:e.clientX,y:e.clientY}},toggleColumnCollapse(e,t,o=!1){if(!(e.target.closest(g)||o&&e.detail>1)){if(o){let r=this.railPressAt;if(this.railPressAt=null,r&&Math.hypot(e.clientX-r.x,e.clientY-r.y)>4)return}Date.now()-this.railToggledAt<500||(o&&(this.railToggledAt=Date.now()),this.$wire.toggleBoardColumnCollapse(t))}},openNewColumn(){this.addingColumn=!0,this.newColumnTouched=!0,this.$nextTick(()=>this.$refs.newColumnInput.focus())},cancelNewColumn(){this.addingColumn=!1,this.newColumnTouched=!0,this.newColumnName=""},async submitNewColumn(){if(!this.addingColumnPending){this.addingColumnPending=!0,this.newColumnTouched=!0;try{await this.$wire.addBoardColumn(this.newColumnName)}finally{this.addingColumnPending=!1}this.newColumnTouched=!1,this.$root.querySelector(".ff-add-column-error")||this.cancelNewColumn()}},suppressDoubleClickSelection(e){e.detail>1&&!e.target.closest(g)&&e.preventDefault()},initColumnMenu(e){let t=e.closest(".fi-dropdown");if(h.has(t))return;let o=window.Alpine.$data(t),r=o.toggle.bind(o);h.add(t),o.toggle=n=>n?.type==="mousedown"?void 0:r(n)},columnMenuPress(e){this.columnMenuPressAt={x:e.clientX,y:e.clientY}},columnMenuClick(e){let t=this.columnMenuPressAt;this.columnMenuPressAt=null,!(t&&Math.hypot(e.clientX-t.x,e.clientY-t.y)>4)&&window.Alpine.$data(e.currentTarget.closest(".fi-dropdown")).toggle(e)},columnDrop(e){return this.dragOverColumn!==e?null:this.isColumnBlocked(e)?"blocked":"active"},cellDrop(e,t){return this.dragOverColumn!==e||this.dragOverLane!==t?null:this.isCellBlocked(e,t)?"blocked":"active"},canDrop(e,t){if(!this.$root.contains(e)||!this.$root.contains(t))return!1;let o=e.dataset.laneId??null,r=t.dataset.laneId??null;return o!==r&&this.$root.dataset.lanesWritable!=="true"?!1:!this.isColumnBlocked(e.dataset.columnId,t.dataset.columnId)},isColumnBlocked(e,t=this.dragSource?.column){if(!e||e===t)return!1;let o=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"]`),r=o?.dataset.columnLimit;return r===void 0||r===""?!1:Number(o.dataset.columnTotal)>=Number(r)},isCellBlocked(e,t){return this.dragSource?t!==this.dragSource.lane&&this.$root.dataset.lanesWritable!=="true"?!0:this.isColumnBlocked(e):!1},displayCount(e,t){let o=this.pendingCounts[e]??t,r=this.dragSource?.column,n=this.dragOverColumn;return!r||!n||r===n||this.isColumnBlocked(n)?o:e===n?o+1:e===r?o-1:o},holdMovedCounts(e,t){if(e===t)return()=>{};let o={[e]:-1,[t]:1},r=!1;for(let[n,a]of Object.entries(o))this.pendingCounts[n]=this.renderedCount(n)+a;return this.pendingMoves++,n=>{if(!r){if(r=!0,n)for(let[a,i]of Object.entries(o))this.pendingCounts[a]-=i;--this.pendingMoves===0&&(this.pendingCounts={})}}},renderedCount(e){let t=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"] .ff-count`);return this.pendingCounts[e]??Number(t?.dataset.total)},handleSortableEnd(e){this.endDrag();let t=e.item,o=e.to,r=e.newDraggableIndex??e.newIndex,n=":scope > [x-sortable-item], :scope > [data-card-id]",a=s=>s.getAttribute("x-sortable-item")||s.getAttribute("data-card-id");if(e.from===o&&e.oldDraggableIndex===e.newDraggableIndex)return;if(r===0){let s=o.querySelector(n);s&&s!==t&&o.insertBefore(t,s)}let i=a(t);if(!i){console.error("Flowforge: Could not determine card ID for move operation");return}let l=o.getAttribute("data-column-id");if(!l){console.error("Flowforge: Target column ID is missing");return}let p=e.from.dataset.laneId??null,C=o.dataset.laneId??null,u=o.querySelectorAll(n),d=Array.prototype.indexOf.call(u,t),b=d>0?a(u[d-1]):null,w=d>=0&&d{this.setCardState(t,!1),f(s===!1),s===!1&&this.revertCard(e)}).catch(()=>{this.setCardState(t,!1),f(!0),this.revertCard(e)})},revertCard({item:e,from:t,oldDraggableIndex:o}){e.remove();let r=t.querySelectorAll(":scope > [x-sortable-item]"),n=r[r.length-1],a=r[o]??(n?n.nextSibling:t.firstChild);t.insertBefore(e,a)},setCardState(e,t){e.toggleAttribute("data-pending",t)},isLaneCollapsed(e){return this.collapsedLanes[e]===!0},toggleLane(e){this.collapsedLanes[e]=!this.isLaneCollapsed(e)},isLoadingColumn(e){return this.isLoading[e]||!1},isColumnFullyLoaded(e){return this.fullyLoaded[e]||!1},handleSmoothScroll(e){this.isLoadingColumn(e)||this.isColumnFullyLoaded(e)||(this.isLoading[e]=!0,this.$wire.loadMoreItems(e).then(()=>setTimeout(()=>this.isLoading[e]=!1,100)).catch(()=>this.isLoading[e]=!1))},handleColumnScroll(e,t){if(this.isColumnFullyLoaded(t))return;let{scrollTop:o,scrollHeight:r,clientHeight:n}=e.target;(o+n)/r>=.8&&!this.isLoadingColumn(t)&&this.handleSmoothScroll(t)}}}export{y as default}; diff --git a/resources/js/flowforge-modern.js b/resources/js/flowforge-modern.js index 983eda99e..9c3a7b587 100644 --- a/resources/js/flowforge-modern.js +++ b/resources/js/flowforge-modern.js @@ -44,6 +44,7 @@ export default function flowforgeModern() { railToggledAt: 0, columnMenuPressAt: null, + railPressAt: null, dragOverLane: null, dragSource: null, pendingCounts: {}, @@ -226,11 +227,25 @@ export default function flowforgeModern() { this.dragSource = null; }, + railPress(event) { + this.railPressAt = { x: event.clientX, y: event.clientY }; + }, + toggleColumnCollapse(event, columnId, fromRail = false) { if (event.target.closest(HEADER_GESTURE_IGNORED) || (fromRail && event.detail > 1)) { return; } + if (fromRail) { + const press = this.railPressAt; + + this.railPressAt = null; + + if (press && Math.hypot(event.clientX - press.x, event.clientY - press.y) > MENU_DRAG_THRESHOLD) { + return; + } + } + // The click that expands a rail must not let its double click collapse the header again. if (Date.now() - this.railToggledAt < 500) { return; diff --git a/resources/views/modern/livewire/column.blade.php b/resources/views/modern/livewire/column.blade.php index 22a29b4d8..85c5c4a49 100644 --- a/resources/views/modern/livewire/column.blade.php +++ b/resources/views/modern/livewire/column.blade.php @@ -23,6 +23,7 @@ class="ff-column" @if ($isCollapsed) data-collapsed title="{{ $plainLabel }}" @endif @if ($isCollapsed && ($column['canToggleCollapse'] ?? false)) x-on:click="toggleColumnCollapse($event, @js((string) $columnId), true)" + x-on:pointerdown="railPress($event)" x-on:mousedown="suppressDoubleClickSelection($event)" @endif x-bind:data-drop="columnDrop(@js((string) $columnId))" diff --git a/resources/views/modern/livewire/lanes.blade.php b/resources/views/modern/livewire/lanes.blade.php index 3d1beac37..f55dcc642 100644 --- a/resources/views/modern/livewire/lanes.blade.php +++ b/resources/views/modern/livewire/lanes.blade.php @@ -31,6 +31,7 @@ class="ff-column" @if ($isCollapsed) data-collapsed title="{{ strip_tags((string) $column['label']) }}" @endif @if ($isCollapsed && ($column['canToggleCollapse'] ?? false)) x-on:click="toggleColumnCollapse($event, @js((string) $columnId), true)" + x-on:pointerdown="railPress($event)" x-on:mousedown="suppressDoubleClickSelection($event)" @endif x-bind:data-drop="columnDrop(@js((string) $columnId))" diff --git a/tests/Browser/ModernBoardTest.php b/tests/Browser/ModernBoardTest.php index 325c1965b..596c804fa 100644 --- a/tests/Browser/ModernBoardTest.php +++ b/tests/Browser/ModernBoardTest.php @@ -801,6 +801,20 @@ function boardTraySampler(int $budgetMilliseconds): string expect(boardStyle($page, $root, 'width'))->toBe('300px'); }); +test('a press on a rail that moves before release leaves the rail collapsed', function () { + boardSeed(); + $page = boardPage('/modern/test-collapsible-board'); + $pointer = Pointer::on($page); + $root = '[data-column-root="completed"]'; + + $pointer->press($root)->nudge(0, 30)->release()->wait(600); + + expect($page->script("document.querySelector('{$root}').hasAttribute('data-collapsed')"))->toBeTrue(); + + $pointer->click($root); + $pointer->untilScript("! document.querySelector('{$root}').hasAttribute('data-collapsed')"); +}); + test('double clicking the add card button leaves the column expanded', function () { boardSeed(); $page = boardPage('/modern/test-collapsible-board'); From 6749d402f1759e8cc452ab8ff6827397428a14cc Mon Sep 17 00:00:00 2001 From: Manuk Date: Sat, 14 Nov 2026 14:26:02 +0400 Subject: [PATCH 15/34] fix(columns): draw the add tile as a header-level square --- docs/content/2.essentials/2.customization.md | 3 +- docs/content/2.essentials/4.api-reference.md | 2 ++ .../skills/flowforge-development/SKILL.md | 2 +- resources/css/flowforge-modern.css | 29 +++++++++------ resources/dist/flowforge-modern.js | 2 +- resources/js/flowforge-modern.js | 5 ++- resources/lang/de/flowforge.php | 2 +- resources/lang/en/flowforge.php | 2 +- resources/lang/es/flowforge.php | 2 +- resources/lang/nl/flowforge.php | 2 +- resources/views/modern/index.blade.php | 2 +- .../modern/livewire/add-column.blade.php | 4 +-- .../views/modern/livewire/lanes.blade.php | 2 +- src/Board.php | 1 + src/Concerns/HasColumnControls.php | 16 +++++++++ tests/Browser/ModernBoardTest.php | 35 ++++++++++++++++--- tests/Fixtures/Modern/TestBoard.php | 3 ++ tests/Modern/Feature/AddColumnTest.php | 17 +++++++++ 18 files changed, 103 insertions(+), 28 deletions(-) diff --git a/docs/content/2.essentials/2.customization.md b/docs/content/2.essentials/2.customization.md index 0cbd1e172..15dbad57e 100644 --- a/docs/content/2.essentials/2.customization.md +++ b/docs/content/2.essentials/2.customization.md @@ -375,11 +375,12 @@ use Illuminate\Validation\ValidationException; $this->stages->push($name); }) ->addColumnLabel('Add stage') +->addColumnPlaceholder('Stage name') ``` A blank name never reaches your closure. A `ValidationException` from the closure shows its first message under the input. `addColumnLabel()` sets the tooltip and the input label, and defaults to -"Add column". The tile renders only while `addColumnUsing()` is set, so hide it for a user by not +"Add column". `addColumnPlaceholder()` sets the input placeholder, and defaults to "Column name". The tile renders only while `addColumnUsing()` is set, so hide it for a user by not setting it. With a grouping active, the tile is an extra track in the header row only, and every lane cell keeps its column. diff --git a/docs/content/2.essentials/4.api-reference.md b/docs/content/2.essentials/4.api-reference.md index b3d455805..e0d28d4c6 100644 --- a/docs/content/2.essentials/4.api-reference.md +++ b/docs/content/2.essentials/4.api-reference.md @@ -34,6 +34,7 @@ navigation: | `columnHeaderMenu(?Closure)` | Turn the column heading into a menu trigger. The closure receives `array $column` and returns an `Htmlable` block, or `null` for none. The panel holds the block, then the column actions as list items | | | `addColumnUsing(?Closure)` | Show an add column tile after the last column. The closure receives `string $name`, the trimmed name the user typed. Throw a `ValidationException` to show its first message under the input. Leave it unset to hide the tile | | | `addColumnLabel(string\|Closure\|null)` | The tile's tooltip and input label. Defaults to "Add column" | | +| `addColumnPlaceholder(string\|Closure\|null)` | The input's placeholder. Defaults to "Column name" | | ## Board Methods @@ -150,6 +151,7 @@ use Filament\Support\Enums\Width; ->columnHeaderMenu(fn (array $column) => new HtmlString('...')) // Open a host block and the column actions from the heading ->addColumnUsing(fn (string $name) => ...) // Add a column from a tile after the last one ->addColumnLabel('Add stage') // Tooltip for the tile +->addColumnPlaceholder('Stage name') // Placeholder for the name input ``` ### Modern board additions diff --git a/resources/boost/skills/flowforge-development/SKILL.md b/resources/boost/skills/flowforge-development/SKILL.md index 77dc2b187..98a106fa6 100644 --- a/resources/boost/skills/flowforge-development/SKILL.md +++ b/resources/boost/skills/flowforge-development/SKILL.md @@ -365,7 +365,7 @@ A "Group by" select appears and the choice lives in `?groupBy=`. `lanes()` retur ### Column controls -The host owns the state and Flowforge renders it. `collapsedColumns(fn () => [...])` and `collapseAllColumns(fn () => ...)` collapse columns. `collapsibleColumns(fn (string $columnId, bool $collapsed) => ...)` lets a double-click on a header collapse it and a click on its rail expand it. Only columns listed in `collapsedColumns()` expand by click. `columnHeaderMenu(fn (array $column): ?Htmlable => ...)` turns the header into a menu holding the host block above the column actions. `addColumnUsing(fn (string $name) => ...)` with `addColumnLabel()` adds a tile after the last column; throw a `ValidationException` to show a message under its input. Pass any value the page changes during a request as a closure, because the board is built before the action runs. +The host owns the state and Flowforge renders it. `collapsedColumns(fn () => [...])` and `collapseAllColumns(fn () => ...)` collapse columns. `collapsibleColumns(fn (string $columnId, bool $collapsed) => ...)` lets a double-click on a header collapse it and a click on its rail expand it. Only columns listed in `collapsedColumns()` expand by click. `columnHeaderMenu(fn (array $column): ?Htmlable => ...)` turns the header into a menu holding the host block above the column actions. `addColumnUsing(fn (string $name) => ...)` with `addColumnLabel()` and `addColumnPlaceholder()` adds a tile after the last column; throw a `ValidationException` to show a message under its input. Pass any value the page changes during a request as a closure, because the board is built before the action runs. ### Styling a Modern Board diff --git a/resources/css/flowforge-modern.css b/resources/css/flowforge-modern.css index 5c06ca062..ddd80bd46 100644 --- a/resources/css/flowforge-modern.css +++ b/resources/css/flowforge-modern.css @@ -665,19 +665,18 @@ } .ff-add-column { - --_add-border: var(--ff-border, color-mix(in oklab, var(--gray-950) 15%, transparent)); + --_tile-bg: var(--ff-add-bg, color-mix(in oklab, var(--gray-950) 5%, transparent)); + --_tile-bg-hover: var(--ff-add-bg-hover, color-mix(in oklab, var(--gray-950) 9%, transparent)); position: relative; flex-shrink: 0; - align-self: stretch; + align-self: start; width: var(--_collapsed-width); - } - - .ff-columns > .ff-add-column { - min-height: 3rem; + height: var(--_collapsed-width); } :where(.dark) .ff-add-column { - --_add-border: var(--ff-border, color-mix(in oklab, #fff 20%, transparent)); + --_tile-bg: var(--ff-add-bg, color-mix(in oklab, #fff 8%, transparent)); + --_tile-bg-hover: var(--ff-add-bg-hover, color-mix(in oklab, #fff 13%, transparent)); } .ff-add-column-button { @@ -687,17 +686,17 @@ width: 100%; height: 100%; color: var(--_text-muted); - border: 1px dashed var(--_add-border); - border-radius: var(--ff-tray-radius, calc(var(--ff-radius, 0.75rem) + 0.25rem)); + background-color: var(--_tile-bg); + border-radius: 0.75rem; transition: color var(--_duration) var(--_ease), - border-color var(--_duration) var(--_ease); + background-color var(--_duration) var(--_ease); } .ff-add-column-button:hover, .ff-add-column-button:focus-visible { color: var(--_text); - border-color: var(--_accent); + background-color: var(--_tile-bg-hover); } .ff-add-column[data-adding] .ff-add-column-button { @@ -795,6 +794,14 @@ display: none; } + .ff-lanes-heads:has(> .ff-add-column) { + width: calc(100% + var(--_gap) + var(--_collapsed-width)); + } + + .ff-lanes-heads:has(> .ff-add-column[data-adding]) { + width: calc(100% + var(--_gap) + var(--_column-width)); + } + .ff-lanes-heads { position: sticky; top: 0; diff --git a/resources/dist/flowforge-modern.js b/resources/dist/flowforge-modern.js index fdf19eb5c..43c02d8b4 100644 --- a/resources/dist/flowforge-modern.js +++ b/resources/dist/flowforge-modern.js @@ -1 +1 @@ -var S=["--ff-surface","--ff-surface-sunken","--ff-surface-raised","--ff-border","--ff-text","--ff-text-muted","--ff-accent","--ff-accent-tint","--ff-danger","--ff-warning","--ff-radius","--ff-gap","--ff-ease","--ff-duration","--ff-column-width","--ff-tray-bg","--ff-tray-radius","--ff-card-bg","--ff-card-ring","--ff-card-radius","--ff-card-shadow","--ff-card-padding","--ff-drag-tilt","--ff-drag-shadow","--ff-placeholder-border"],g='.ff-column-actions, .fi-dropdown-panel, input, textarea, select, [contenteditable]:not([contenteditable="false"])';var h=new WeakSet,c=new WeakSet,m=()=>window.Sortable.active||window.Sortable.dragged;function y(){return{isLoading:{},fullyLoaded:{},dragOverColumn:null,railToggledAt:0,columnMenuPressAt:null,railPressAt:null,dragOverLane:null,dragSource:null,pendingCounts:{},pendingMoves:0,collapsedLanes:{},addingColumn:!1,newColumnName:"",newColumnTouched:!1,addingColumnPending:!1,placeholder:null,stopTrackingPointer:null,init(){this.$wire.$on("kanban-items-loaded",e=>{let{columnId:t,isFullyLoaded:o}=e;o&&(this.fullyLoaded[t]=!0)})},configureSortable(e){if(!e.sortable||e.sortable.options.forceFallback)return;if(m()){this.configureSortableAfterDrag(e);return}let t=window.matchMedia("(prefers-reduced-motion: reduce)").matches;e.sortable.destroy(),e.sortable=window.Sortable.create(e,{draggable:"[x-sortable-item]",handle:"[x-sortable-handle]",dataIdAttr:"x-sortable-item",forceFallback:!0,fallbackTolerance:5,fallbackOnBody:!0,fallbackClass:"",ghostClass:"",delay:150,delayOnTouchOnly:!0,animation:t?0:200,scrollSensitivity:100,scrollSpeed:15,forceAutoScrollFallback:!0,group:{name:e.getAttribute("x-sortable-group"),pull:!0,put:(o,r)=>this.canDrop(o.el,r.el)},onStart:o=>this.startDrag(o),onEnd(o){let{item:r,to:n,oldDraggableIndex:a,newDraggableIndex:i}=o;if(a===i)return;let l=n.querySelectorAll(`:scope > ${this.options.draggable}`)[i-1];l&&n.insertBefore(r,l.nextSibling)}})},configureSortableAfterDrag(e){if(c.has(e))return;c.add(e);let t=()=>{if(m()){requestAnimationFrame(t);return}c.delete(e),e.isConnected&&this.configureSortable(e)};requestAnimationFrame(t)},startDrag(e){this.stopTrackingPointer?.(),this.placeholder=e.item,this.placeholder.setAttribute("data-placeholder",""),this.markGhost(),window.getSelection()?.removeAllRanges(),document.documentElement.classList.add("ff-dragging"),this.dragSource={column:e.from.dataset.columnId,lane:e.from.dataset.laneId??null};let t=o=>this.trackPointer(o);document.addEventListener("pointermove",t,{passive:!0}),document.addEventListener("touchmove",t,{passive:!0}),this.stopTrackingPointer=()=>{document.removeEventListener("pointermove",t),document.removeEventListener("touchmove",t)}},trackPointer(e){if(!window.Sortable.active){this.endDrag();return}this.markGhost();let t=e.touches?.[0]??e,o=document.elementFromPoint(t.clientX,t.clientY),r=o?.closest("[data-column-id]"),n=o?.closest("[data-column-root]");this.dragOverColumn=r?.dataset.columnId??n?.dataset.columnRoot??null,this.dragOverLane=r?.dataset.laneId??null},markGhost(){let e=window.Sortable.ghost;if(!e||e.hasAttribute("data-dragging"))return;e.removeAttribute("data-placeholder"),e.setAttribute("data-dragging",""),e.style.opacity="1";let t=getComputedStyle(this.placeholder);for(let o of S){let r=t.getPropertyValue(o);r!==""&&e.style.setProperty(o,r)}},endDrag(){document.documentElement.classList.remove("ff-dragging"),this.placeholder?.removeAttribute("data-placeholder"),this.placeholder=null,this.stopTrackingPointer?.(),this.stopTrackingPointer=null,this.dragOverColumn=null,this.dragOverLane=null,this.dragSource=null},railPress(e){this.railPressAt={x:e.clientX,y:e.clientY}},toggleColumnCollapse(e,t,o=!1){if(!(e.target.closest(g)||o&&e.detail>1)){if(o){let r=this.railPressAt;if(this.railPressAt=null,r&&Math.hypot(e.clientX-r.x,e.clientY-r.y)>4)return}Date.now()-this.railToggledAt<500||(o&&(this.railToggledAt=Date.now()),this.$wire.toggleBoardColumnCollapse(t))}},openNewColumn(){this.addingColumn=!0,this.newColumnTouched=!0,this.$nextTick(()=>this.$refs.newColumnInput.focus())},cancelNewColumn(){this.addingColumn=!1,this.newColumnTouched=!0,this.newColumnName=""},async submitNewColumn(){if(!this.addingColumnPending){this.addingColumnPending=!0,this.newColumnTouched=!0;try{await this.$wire.addBoardColumn(this.newColumnName)}finally{this.addingColumnPending=!1}this.newColumnTouched=!1,this.$root.querySelector(".ff-add-column-error")||this.cancelNewColumn()}},suppressDoubleClickSelection(e){e.detail>1&&!e.target.closest(g)&&e.preventDefault()},initColumnMenu(e){let t=e.closest(".fi-dropdown");if(h.has(t))return;let o=window.Alpine.$data(t),r=o.toggle.bind(o);h.add(t),o.toggle=n=>n?.type==="mousedown"?void 0:r(n)},columnMenuPress(e){this.columnMenuPressAt={x:e.clientX,y:e.clientY}},columnMenuClick(e){let t=this.columnMenuPressAt;this.columnMenuPressAt=null,!(t&&Math.hypot(e.clientX-t.x,e.clientY-t.y)>4)&&window.Alpine.$data(e.currentTarget.closest(".fi-dropdown")).toggle(e)},columnDrop(e){return this.dragOverColumn!==e?null:this.isColumnBlocked(e)?"blocked":"active"},cellDrop(e,t){return this.dragOverColumn!==e||this.dragOverLane!==t?null:this.isCellBlocked(e,t)?"blocked":"active"},canDrop(e,t){if(!this.$root.contains(e)||!this.$root.contains(t))return!1;let o=e.dataset.laneId??null,r=t.dataset.laneId??null;return o!==r&&this.$root.dataset.lanesWritable!=="true"?!1:!this.isColumnBlocked(e.dataset.columnId,t.dataset.columnId)},isColumnBlocked(e,t=this.dragSource?.column){if(!e||e===t)return!1;let o=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"]`),r=o?.dataset.columnLimit;return r===void 0||r===""?!1:Number(o.dataset.columnTotal)>=Number(r)},isCellBlocked(e,t){return this.dragSource?t!==this.dragSource.lane&&this.$root.dataset.lanesWritable!=="true"?!0:this.isColumnBlocked(e):!1},displayCount(e,t){let o=this.pendingCounts[e]??t,r=this.dragSource?.column,n=this.dragOverColumn;return!r||!n||r===n||this.isColumnBlocked(n)?o:e===n?o+1:e===r?o-1:o},holdMovedCounts(e,t){if(e===t)return()=>{};let o={[e]:-1,[t]:1},r=!1;for(let[n,a]of Object.entries(o))this.pendingCounts[n]=this.renderedCount(n)+a;return this.pendingMoves++,n=>{if(!r){if(r=!0,n)for(let[a,i]of Object.entries(o))this.pendingCounts[a]-=i;--this.pendingMoves===0&&(this.pendingCounts={})}}},renderedCount(e){let t=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"] .ff-count`);return this.pendingCounts[e]??Number(t?.dataset.total)},handleSortableEnd(e){this.endDrag();let t=e.item,o=e.to,r=e.newDraggableIndex??e.newIndex,n=":scope > [x-sortable-item], :scope > [data-card-id]",a=s=>s.getAttribute("x-sortable-item")||s.getAttribute("data-card-id");if(e.from===o&&e.oldDraggableIndex===e.newDraggableIndex)return;if(r===0){let s=o.querySelector(n);s&&s!==t&&o.insertBefore(t,s)}let i=a(t);if(!i){console.error("Flowforge: Could not determine card ID for move operation");return}let l=o.getAttribute("data-column-id");if(!l){console.error("Flowforge: Target column ID is missing");return}let p=e.from.dataset.laneId??null,C=o.dataset.laneId??null,u=o.querySelectorAll(n),d=Array.prototype.indexOf.call(u,t),b=d>0?a(u[d-1]):null,w=d>=0&&d{this.setCardState(t,!1),f(s===!1),s===!1&&this.revertCard(e)}).catch(()=>{this.setCardState(t,!1),f(!0),this.revertCard(e)})},revertCard({item:e,from:t,oldDraggableIndex:o}){e.remove();let r=t.querySelectorAll(":scope > [x-sortable-item]"),n=r[r.length-1],a=r[o]??(n?n.nextSibling:t.firstChild);t.insertBefore(e,a)},setCardState(e,t){e.toggleAttribute("data-pending",t)},isLaneCollapsed(e){return this.collapsedLanes[e]===!0},toggleLane(e){this.collapsedLanes[e]=!this.isLaneCollapsed(e)},isLoadingColumn(e){return this.isLoading[e]||!1},isColumnFullyLoaded(e){return this.fullyLoaded[e]||!1},handleSmoothScroll(e){this.isLoadingColumn(e)||this.isColumnFullyLoaded(e)||(this.isLoading[e]=!0,this.$wire.loadMoreItems(e).then(()=>setTimeout(()=>this.isLoading[e]=!1,100)).catch(()=>this.isLoading[e]=!1))},handleColumnScroll(e,t){if(this.isColumnFullyLoaded(t))return;let{scrollTop:o,scrollHeight:r,clientHeight:n}=e.target;(o+n)/r>=.8&&!this.isLoadingColumn(t)&&this.handleSmoothScroll(t)}}}export{y as default}; +var S=["--ff-surface","--ff-surface-sunken","--ff-surface-raised","--ff-border","--ff-text","--ff-text-muted","--ff-accent","--ff-accent-tint","--ff-danger","--ff-warning","--ff-radius","--ff-gap","--ff-ease","--ff-duration","--ff-column-width","--ff-tray-bg","--ff-tray-radius","--ff-card-bg","--ff-card-ring","--ff-card-radius","--ff-card-shadow","--ff-card-padding","--ff-drag-tilt","--ff-drag-shadow","--ff-placeholder-border"],g='.ff-column-actions, .fi-dropdown-panel, input, textarea, select, [contenteditable]:not([contenteditable="false"])';var h=new WeakSet,c=new WeakSet,m=()=>window.Sortable.active||window.Sortable.dragged;function y(){return{isLoading:{},fullyLoaded:{},dragOverColumn:null,railToggledAt:0,columnMenuPressAt:null,railPressAt:null,dragOverLane:null,dragSource:null,pendingCounts:{},pendingMoves:0,collapsedLanes:{},addingColumn:!1,newColumnName:"",newColumnTouched:!1,addingColumnPending:!1,placeholder:null,stopTrackingPointer:null,init(){this.$wire.$on("kanban-items-loaded",e=>{let{columnId:t,isFullyLoaded:o}=e;o&&(this.fullyLoaded[t]=!0)})},configureSortable(e){if(!e.sortable||e.sortable.options.forceFallback)return;if(m()){this.configureSortableAfterDrag(e);return}let t=window.matchMedia("(prefers-reduced-motion: reduce)").matches;e.sortable.destroy(),e.sortable=window.Sortable.create(e,{draggable:"[x-sortable-item]",handle:"[x-sortable-handle]",dataIdAttr:"x-sortable-item",forceFallback:!0,fallbackTolerance:5,fallbackOnBody:!0,fallbackClass:"",ghostClass:"",delay:150,delayOnTouchOnly:!0,animation:t?0:200,scrollSensitivity:100,scrollSpeed:15,forceAutoScrollFallback:!0,group:{name:e.getAttribute("x-sortable-group"),pull:!0,put:(o,n)=>this.canDrop(o.el,n.el)},onStart:o=>this.startDrag(o),onEnd(o){let{item:n,to:r,oldDraggableIndex:s,newDraggableIndex:i}=o;if(s===i)return;let l=r.querySelectorAll(`:scope > ${this.options.draggable}`)[i-1];l&&r.insertBefore(n,l.nextSibling)}})},configureSortableAfterDrag(e){if(c.has(e))return;c.add(e);let t=()=>{if(m()){requestAnimationFrame(t);return}c.delete(e),e.isConnected&&this.configureSortable(e)};requestAnimationFrame(t)},startDrag(e){this.stopTrackingPointer?.(),this.placeholder=e.item,this.placeholder.setAttribute("data-placeholder",""),this.markGhost(),window.getSelection()?.removeAllRanges(),document.documentElement.classList.add("ff-dragging"),this.dragSource={column:e.from.dataset.columnId,lane:e.from.dataset.laneId??null};let t=o=>this.trackPointer(o);document.addEventListener("pointermove",t,{passive:!0}),document.addEventListener("touchmove",t,{passive:!0}),this.stopTrackingPointer=()=>{document.removeEventListener("pointermove",t),document.removeEventListener("touchmove",t)}},trackPointer(e){if(!window.Sortable.active){this.endDrag();return}this.markGhost();let t=e.touches?.[0]??e,o=document.elementFromPoint(t.clientX,t.clientY),n=o?.closest("[data-column-id]"),r=o?.closest("[data-column-root]");this.dragOverColumn=n?.dataset.columnId??r?.dataset.columnRoot??null,this.dragOverLane=n?.dataset.laneId??null},markGhost(){let e=window.Sortable.ghost;if(!e||e.hasAttribute("data-dragging"))return;e.removeAttribute("data-placeholder"),e.setAttribute("data-dragging",""),e.style.opacity="1";let t=getComputedStyle(this.placeholder);for(let o of S){let n=t.getPropertyValue(o);n!==""&&e.style.setProperty(o,n)}},endDrag(){document.documentElement.classList.remove("ff-dragging"),this.placeholder?.removeAttribute("data-placeholder"),this.placeholder=null,this.stopTrackingPointer?.(),this.stopTrackingPointer=null,this.dragOverColumn=null,this.dragOverLane=null,this.dragSource=null},railPress(e){this.railPressAt={x:e.clientX,y:e.clientY}},toggleColumnCollapse(e,t,o=!1){if(!(e.target.closest(g)||o&&e.detail>1)){if(o){let n=this.railPressAt;if(this.railPressAt=null,n&&Math.hypot(e.clientX-n.x,e.clientY-n.y)>4)return}Date.now()-this.railToggledAt<500||(o&&(this.railToggledAt=Date.now()),this.$wire.toggleBoardColumnCollapse(t))}},openNewColumn(){this.addingColumn=!0,this.newColumnTouched=!0,this.$nextTick(()=>{this.$refs.newColumnInput.focus({preventScroll:!0}),requestAnimationFrame(()=>this.$refs.newColumnInput.scrollIntoView({block:"nearest",inline:"nearest"}))})},cancelNewColumn(){this.addingColumn=!1,this.newColumnTouched=!0,this.newColumnName=""},async submitNewColumn(){if(!this.addingColumnPending){this.addingColumnPending=!0,this.newColumnTouched=!0;try{await this.$wire.addBoardColumn(this.newColumnName)}finally{this.addingColumnPending=!1}this.newColumnTouched=!1,this.$root.querySelector(".ff-add-column-error")||this.cancelNewColumn()}},suppressDoubleClickSelection(e){e.detail>1&&!e.target.closest(g)&&e.preventDefault()},initColumnMenu(e){let t=e.closest(".fi-dropdown");if(h.has(t))return;let o=window.Alpine.$data(t),n=o.toggle.bind(o);h.add(t),o.toggle=r=>r?.type==="mousedown"?void 0:n(r)},columnMenuPress(e){this.columnMenuPressAt={x:e.clientX,y:e.clientY}},columnMenuClick(e){let t=this.columnMenuPressAt;this.columnMenuPressAt=null,!(t&&Math.hypot(e.clientX-t.x,e.clientY-t.y)>4)&&window.Alpine.$data(e.currentTarget.closest(".fi-dropdown")).toggle(e)},columnDrop(e){return this.dragOverColumn!==e?null:this.isColumnBlocked(e)?"blocked":"active"},cellDrop(e,t){return this.dragOverColumn!==e||this.dragOverLane!==t?null:this.isCellBlocked(e,t)?"blocked":"active"},canDrop(e,t){if(!this.$root.contains(e)||!this.$root.contains(t))return!1;let o=e.dataset.laneId??null,n=t.dataset.laneId??null;return o!==n&&this.$root.dataset.lanesWritable!=="true"?!1:!this.isColumnBlocked(e.dataset.columnId,t.dataset.columnId)},isColumnBlocked(e,t=this.dragSource?.column){if(!e||e===t)return!1;let o=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"]`),n=o?.dataset.columnLimit;return n===void 0||n===""?!1:Number(o.dataset.columnTotal)>=Number(n)},isCellBlocked(e,t){return this.dragSource?t!==this.dragSource.lane&&this.$root.dataset.lanesWritable!=="true"?!0:this.isColumnBlocked(e):!1},displayCount(e,t){let o=this.pendingCounts[e]??t,n=this.dragSource?.column,r=this.dragOverColumn;return!n||!r||n===r||this.isColumnBlocked(r)?o:e===r?o+1:e===n?o-1:o},holdMovedCounts(e,t){if(e===t)return()=>{};let o={[e]:-1,[t]:1},n=!1;for(let[r,s]of Object.entries(o))this.pendingCounts[r]=this.renderedCount(r)+s;return this.pendingMoves++,r=>{if(!n){if(n=!0,r)for(let[s,i]of Object.entries(o))this.pendingCounts[s]-=i;--this.pendingMoves===0&&(this.pendingCounts={})}}},renderedCount(e){let t=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"] .ff-count`);return this.pendingCounts[e]??Number(t?.dataset.total)},handleSortableEnd(e){this.endDrag();let t=e.item,o=e.to,n=e.newDraggableIndex??e.newIndex,r=":scope > [x-sortable-item], :scope > [data-card-id]",s=a=>a.getAttribute("x-sortable-item")||a.getAttribute("data-card-id");if(e.from===o&&e.oldDraggableIndex===e.newDraggableIndex)return;if(n===0){let a=o.querySelector(r);a&&a!==t&&o.insertBefore(t,a)}let i=s(t);if(!i){console.error("Flowforge: Could not determine card ID for move operation");return}let l=o.getAttribute("data-column-id");if(!l){console.error("Flowforge: Target column ID is missing");return}let p=e.from.dataset.laneId??null,C=o.dataset.laneId??null,u=o.querySelectorAll(r),d=Array.prototype.indexOf.call(u,t),b=d>0?s(u[d-1]):null,w=d>=0&&d{this.setCardState(t,!1),f(a===!1),a===!1&&this.revertCard(e)}).catch(()=>{this.setCardState(t,!1),f(!0),this.revertCard(e)})},revertCard({item:e,from:t,oldDraggableIndex:o}){e.remove();let n=t.querySelectorAll(":scope > [x-sortable-item]"),r=n[n.length-1],s=n[o]??(r?r.nextSibling:t.firstChild);t.insertBefore(e,s)},setCardState(e,t){e.toggleAttribute("data-pending",t)},isLaneCollapsed(e){return this.collapsedLanes[e]===!0},toggleLane(e){this.collapsedLanes[e]=!this.isLaneCollapsed(e)},isLoadingColumn(e){return this.isLoading[e]||!1},isColumnFullyLoaded(e){return this.fullyLoaded[e]||!1},handleSmoothScroll(e){this.isLoadingColumn(e)||this.isColumnFullyLoaded(e)||(this.isLoading[e]=!0,this.$wire.loadMoreItems(e).then(()=>setTimeout(()=>this.isLoading[e]=!1,100)).catch(()=>this.isLoading[e]=!1))},handleColumnScroll(e,t){if(this.isColumnFullyLoaded(t))return;let{scrollTop:o,scrollHeight:n,clientHeight:r}=e.target;(o+r)/n>=.8&&!this.isLoadingColumn(t)&&this.handleSmoothScroll(t)}}}export{y as default}; diff --git a/resources/js/flowforge-modern.js b/resources/js/flowforge-modern.js index 9c3a7b587..324317183 100644 --- a/resources/js/flowforge-modern.js +++ b/resources/js/flowforge-modern.js @@ -261,7 +261,10 @@ export default function flowforgeModern() { openNewColumn() { this.addingColumn = true; this.newColumnTouched = true; - this.$nextTick(() => this.$refs.newColumnInput.focus()); + this.$nextTick(() => { + this.$refs.newColumnInput.focus({ preventScroll: true }); + requestAnimationFrame(() => this.$refs.newColumnInput.scrollIntoView({ block: 'nearest', inline: 'nearest' })); + }); }, cancelNewColumn() { diff --git a/resources/lang/de/flowforge.php b/resources/lang/de/flowforge.php index aaecdd5d7..6d4130e99 100644 --- a/resources/lang/de/flowforge.php +++ b/resources/lang/de/flowforge.php @@ -22,7 +22,7 @@ 'no_grouping' => 'Keine', 'show_more_lanes' => 'Weitere Bahnen anzeigen', 'add_column' => 'Spalte hinzufügen', - 'column_name_required' => 'Name ist erforderlich', + 'column_name_required' => 'Gib einen Namen ein.', 'column_name' => 'Spaltenname', 'show_more_cards' => ':count weitere anzeigen', 'lane_write_failed' => 'Die Karte konnte nicht in diese Bahn verschoben werden.', diff --git a/resources/lang/en/flowforge.php b/resources/lang/en/flowforge.php index 0f87de946..6e105e58b 100644 --- a/resources/lang/en/flowforge.php +++ b/resources/lang/en/flowforge.php @@ -22,7 +22,7 @@ 'no_grouping' => 'None', 'show_more_lanes' => 'Show more lanes', 'add_column' => 'Add column', - 'column_name_required' => 'Name is required', + 'column_name_required' => 'Enter a name.', 'column_name' => 'Column name', 'show_more_cards' => 'Show :count more', 'lane_write_failed' => 'The card could not be moved to that lane.', diff --git a/resources/lang/es/flowforge.php b/resources/lang/es/flowforge.php index 3a508466c..d5cedcedb 100644 --- a/resources/lang/es/flowforge.php +++ b/resources/lang/es/flowforge.php @@ -22,7 +22,7 @@ 'no_grouping' => 'Ninguno', 'show_more_lanes' => 'Mostrar más carriles', 'add_column' => 'Añadir columna', - 'column_name_required' => 'El nombre es obligatorio', + 'column_name_required' => 'Introduce un nombre.', 'column_name' => 'Nombre de la columna', 'show_more_cards' => 'Mostrar :count más', 'lane_write_failed' => 'No se pudo mover la tarjeta a ese carril.', diff --git a/resources/lang/nl/flowforge.php b/resources/lang/nl/flowforge.php index f0fa102ba..dae036678 100644 --- a/resources/lang/nl/flowforge.php +++ b/resources/lang/nl/flowforge.php @@ -22,7 +22,7 @@ 'no_grouping' => 'Geen', 'show_more_lanes' => 'Meer banen tonen', 'add_column' => 'Kolom toevoegen', - 'column_name_required' => 'Naam is verplicht', + 'column_name_required' => 'Voer een naam in.', 'column_name' => 'Kolomnaam', 'show_more_cards' => ':count meer tonen', 'lane_write_failed' => 'De kaart kon niet naar die baan worden verplaatst.', diff --git a/resources/views/modern/index.blade.php b/resources/views/modern/index.blade.php index 520a8cee6..9691e65d2 100644 --- a/resources/views/modern/index.blade.php +++ b/resources/views/modern/index.blade.php @@ -41,7 +41,7 @@ class="ff-board" @endforeach @if ($config['canAddColumns'] ?? false) - + @endif

@endif diff --git a/resources/views/modern/livewire/add-column.blade.php b/resources/views/modern/livewire/add-column.blade.php index 572562c12..5e9497056 100644 --- a/resources/views/modern/livewire/add-column.blade.php +++ b/resources/views/modern/livewire/add-column.blade.php @@ -1,4 +1,4 @@ -@props(['label']) +@props(['label', 'placeholder']) @php use Filament\Support\Enums\IconSize; @@ -28,7 +28,7 @@ class="ff-add-column-input" x-model="newColumnName" x-on:input="newColumnTouched = true" x-on:keydown.escape.prevent="cancelNewColumn()" - placeholder="{{ __('flowforge::flowforge.column_name') }}" + placeholder="{{ $placeholder }}" aria-label="{{ $label }}" /> diff --git a/resources/views/modern/livewire/lanes.blade.php b/resources/views/modern/livewire/lanes.blade.php index f55dcc642..b709d9315 100644 --- a/resources/views/modern/livewire/lanes.blade.php +++ b/resources/views/modern/livewire/lanes.blade.php @@ -42,7 +42,7 @@ class="ff-column" @endforeach @if ($canAddColumns) - + @endif
diff --git a/src/Board.php b/src/Board.php index a76b0f825..6c8b7da64 100644 --- a/src/Board.php +++ b/src/Board.php @@ -131,6 +131,7 @@ public function getViewData(): array 'collapsible' => $this->isColumnCollapsible(), 'canAddColumns' => $this->canAddColumns(), 'addColumnLabel' => $this->getAddColumnLabel(), + 'addColumnPlaceholder' => $this->getAddColumnPlaceholder(), 'collapseEmptyColumns' => $grouping === null && $this->collapsesEmptyColumns() && array_sum(array_column($columns, 'total')) > 0, diff --git a/src/Concerns/HasColumnControls.php b/src/Concerns/HasColumnControls.php index 8506ade13..53a155efb 100644 --- a/src/Concerns/HasColumnControls.php +++ b/src/Concerns/HasColumnControls.php @@ -25,6 +25,8 @@ trait HasColumnControls protected string | Closure | null $addColumnLabel = null; + protected string | Closure | null $addColumnPlaceholder = null; + /** * @param array|Closure $columnIds */ @@ -130,6 +132,13 @@ public function addColumnLabel(string | Closure | null $label): static return $this; } + public function addColumnPlaceholder(string | Closure | null $placeholder): static + { + $this->addColumnPlaceholder = $placeholder; + + return $this; + } + public function canAddColumns(): bool { return $this->addColumn instanceof Closure; @@ -142,6 +151,13 @@ public function getAddColumnLabel(): string return filled($label) ? (string) $label : __('flowforge::flowforge.add_column'); } + public function getAddColumnPlaceholder(): string + { + $placeholder = $this->evaluate($this->addColumnPlaceholder); + + return filled($placeholder) ? (string) $placeholder : __('flowforge::flowforge.column_name'); + } + public function addColumn(string $name): void { if (! $this->addColumn instanceof Closure) { diff --git a/tests/Browser/ModernBoardTest.php b/tests/Browser/ModernBoardTest.php index 596c804fa..188cc6783 100644 --- a/tests/Browser/ModernBoardTest.php +++ b/tests/Browser/ModernBoardTest.php @@ -1110,14 +1110,39 @@ function boardTraySampler(int $budgetMilliseconds): string expect($page->script("document.querySelector('{$input}').offsetParent !== null"))->toBeTrue(); }); -test('the add column tile leaves the lane heads row height unchanged', function () { - boardSeed('high'); - $height = "document.querySelector('.ff-lanes-heads').offsetHeight"; +test('the add column tile is a square at the column header level on a flat board', function () { + boardSeed(); + $page = boardPage('/modern/test-add-column-board'); - $without = boardPage('/modern/test-grouped-board?groupBy=priority')->script($height); + $box = $page->script("(() => { const tile = document.querySelector('.ff-add-column-button').getBoundingClientRect(); const column = document.querySelector('.ff-column').getBoundingClientRect(); return [tile.width, tile.height, tile.top - column.top]; })()"); + + expect($box[0])->toBeGreaterThan(44)->toBeLessThan(52) + ->and($box[1])->toBeGreaterThan(44)->toBeLessThan(52) + ->and(abs($box[2]))->toBeLessThan(1.5); +}); + +test('the add column tile and its input sit inside the painted lane heads box', function () { + boardSeed('high'); $page = boardPage('/modern/test-add-column-grouped-board?groupBy=priority'); + $pointer = Pointer::on($page); + $inside = <<<'JS' + (() => { + const heads = document.querySelector('.ff-lanes-heads').getBoundingClientRect(); + const column = document.querySelector('.ff-lanes-heads .ff-column').getBoundingClientRect(); + const target = document.querySelector('.ff-add-column-input')?.offsetParent + ? document.querySelector('.ff-add-column-input').getBoundingClientRect() + : document.querySelector('.ff-add-column-button').getBoundingClientRect(); + + return [target.left >= heads.left - 0.5, target.right <= heads.right + 0.5, target.top >= heads.top - 0.5, target.bottom <= heads.bottom + 0.5, Math.abs(document.querySelector('.ff-add-column-button').getBoundingClientRect().top - column.top) < 1.5]; + })() + JS; + + expect($page->script($inside))->toBe([true, true, true, true, true]); + + $pointer->click('.ff-add-column-button'); + $pointer->untilScript("document.activeElement === document.querySelector('.ff-add-column-input')"); - expect($page->script($height))->toBe($without); + expect($page->script($inside))->toBe([true, true, true, true, true]); }); test('pressing enter twice quickly adds the column once', function () { diff --git a/tests/Fixtures/Modern/TestBoard.php b/tests/Fixtures/Modern/TestBoard.php index 002bc5db1..2f5556680 100644 --- a/tests/Fixtures/Modern/TestBoard.php +++ b/tests/Fixtures/Modern/TestBoard.php @@ -49,6 +49,8 @@ class TestBoard extends BoardPage public ?string $addColumnTitle = null; + public ?string $addColumnHint = null; + public bool $withHeaderToolbar = false; public bool $withCreateAction = false; @@ -109,6 +111,7 @@ public function board(Board $board): Board : null) ->addColumnUsing($this->withAddColumn ? $this->addColumnClosure(...) : null) ->addColumnLabel($this->addColumnTitle) + ->addColumnPlaceholder($this->addColumnHint) ->headerToolbar($this->withHeaderToolbar) ->columnActions(match (true) { $this->withHeaderMenu => [Action::make('archiveColumn')->label('Archive column')->action(function (): void {})], diff --git a/tests/Modern/Feature/AddColumnTest.php b/tests/Modern/Feature/AddColumnTest.php index df5a4e267..9b0d34a65 100644 --- a/tests/Modern/Feature/AddColumnTest.php +++ b/tests/Modern/Feature/AddColumnTest.php @@ -44,6 +44,23 @@ function headTracks(string $html, string $property): string ->assertSeeHtml('title="Add stage"'); }); + test('the input placeholder defaults to the column name text', function () { + Livewire::test(TestBoard::class, ['withAddColumn' => true]) + ->assertSeeHtml('placeholder="' . __('flowforge::flowforge.column_name') . '"'); + }); + + test('the input placeholder carries the host text', function () { + Livewire::test(TestBoard::class, ['withAddColumn' => true, 'addColumnHint' => 'Stage name']) + ->assertSeeHtml('placeholder="Stage name"') + ->assertDontSeeHtml('placeholder="' . __('flowforge::flowforge.column_name') . '"'); + }); + + test('a blank name reads as a request for a name', function () { + $component = Livewire::test(TestBoard::class, ['withAddColumn' => true])->call('addBoardColumn', ' '); + + expect($component->errors()->get('boardNewColumn'))->toBe(['Enter a name.']); + }); + test('adding a column passes the trimmed name to the host', function () { Livewire::test(TestBoard::class, ['withAddColumn' => true]) ->call('addBoardColumn', ' Won ') From 2c503a552941a83fa2432e83b4187e6afc2c7d48 Mon Sep 17 00:00:00 2001 From: Manuk Date: Sat, 14 Nov 2026 14:44:33 +0400 Subject: [PATCH 16/34] fix(columns): keep the add tile within the lane heads row and its tokens private --- docs/content/2.essentials/7.design-system.md | 2 +- resources/css/flowforge-modern.css | 16 ++++++++++++---- tests/Browser/ModernBoardTest.php | 10 ++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/docs/content/2.essentials/7.design-system.md b/docs/content/2.essentials/7.design-system.md index 28c5df67e..8e05f8299 100644 --- a/docs/content/2.essentials/7.design-system.md +++ b/docs/content/2.essentials/7.design-system.md @@ -42,7 +42,7 @@ The dark column shows where the default changes under Filament's `.dark` class. | `--ff-surface` | semantic | `var(--gray-50)` / `var(--gray-950)` | 4.2.0 | Background of the sticky column-header strip in the lane view. Set it to the page background. | | `--ff-surface-sunken` | semantic | `var(--gray-100)` / `color-mix(in oklab, #fff 5%, transparent)` | 4.2.0 | Background of a column tray and of a lane cell. `--ff-tray-bg` overrides it. | | `--ff-surface-raised` | semantic | `#fff` / `var(--gray-900)` | 4.2.0 | Background of a card and of the filters panel. `--ff-card-bg` overrides it for cards. | -| `--ff-border` | semantic | `color-mix(in oklab, var(--gray-950) 5%, transparent)` / `color-mix(in oklab, #fff 10%, transparent)` | 4.2.0 | Ring around a card and around the filters panel. `--ff-card-ring` overrides it for cards. The add column tile's dashed border also reads it when set, and otherwise uses a stronger default (15% light, 20% dark). | +| `--ff-border` | semantic | `color-mix(in oklab, var(--gray-950) 5%, transparent)` / `color-mix(in oklab, #fff 10%, transparent)` | 4.2.0 | Ring around a card and around the filters panel. `--ff-card-ring` overrides it for cards. | | `--ff-text` | semantic | `var(--gray-950)` / `#fff` | 4.2.0 | Column titles, lane titles, card titles and the add row on hover. | | `--ff-text-muted` | semantic | `var(--gray-500)` / `var(--gray-400)` | 4.2.0 | Secondary text and icons: the group-by label, column icons, counts, summaries, tags, card meta, the add row, the avatar overflow, lane counts and icons, and the header subheading. | | `--ff-accent` | semantic | `var(--primary-500)` | 4.2.0 | Outline of an accepting drop target, the drop gap border and the loading text. | diff --git a/resources/css/flowforge-modern.css b/resources/css/flowforge-modern.css index ddd80bd46..74ad4ddaf 100644 --- a/resources/css/flowforge-modern.css +++ b/resources/css/flowforge-modern.css @@ -665,8 +665,8 @@ } .ff-add-column { - --_tile-bg: var(--ff-add-bg, color-mix(in oklab, var(--gray-950) 5%, transparent)); - --_tile-bg-hover: var(--ff-add-bg-hover, color-mix(in oklab, var(--gray-950) 9%, transparent)); + --_tile-bg: color-mix(in oklab, var(--gray-950) 5%, transparent); + --_tile-bg-hover: color-mix(in oklab, var(--gray-950) 9%, transparent); position: relative; flex-shrink: 0; align-self: start; @@ -675,8 +675,8 @@ } :where(.dark) .ff-add-column { - --_tile-bg: var(--ff-add-bg, color-mix(in oklab, #fff 8%, transparent)); - --_tile-bg-hover: var(--ff-add-bg-hover, color-mix(in oklab, #fff 13%, transparent)); + --_tile-bg: color-mix(in oklab, #fff 8%, transparent); + --_tile-bg-hover: color-mix(in oklab, #fff 13%, transparent); } .ff-add-column-button { @@ -794,6 +794,14 @@ display: none; } + .ff-lanes-heads > .ff-add-column { + height: 1.75rem; + } + + .ff-lanes-heads .ff-add-column-input { + padding-block: 0.1875rem; + } + .ff-lanes-heads:has(> .ff-add-column) { width: calc(100% + var(--_gap) + var(--_collapsed-width)); } diff --git a/tests/Browser/ModernBoardTest.php b/tests/Browser/ModernBoardTest.php index 188cc6783..90673a4db 100644 --- a/tests/Browser/ModernBoardTest.php +++ b/tests/Browser/ModernBoardTest.php @@ -1145,6 +1145,16 @@ function boardTraySampler(int $budgetMilliseconds): string expect($page->script($inside))->toBe([true, true, true, true, true]); }); +test('the add column tile leaves the lane heads row height unchanged', function () { + boardSeed('high'); + $height = "document.querySelector('.ff-lanes-heads').offsetHeight"; + + $without = boardPage('/modern/test-grouped-board?groupBy=priority')->script($height); + $page = boardPage('/modern/test-add-column-grouped-board?groupBy=priority'); + + expect($page->script($height))->toBe($without); +}); + test('pressing enter twice quickly adds the column once', function () { boardSeed(); $page = boardPage('/modern/test-add-column-board'); From 08eef78437131caecce0dd0e90b9aca5638f22c7 Mon Sep 17 00:00:00 2001 From: Manuk Date: Sat, 14 Nov 2026 22:48:42 +0400 Subject: [PATCH 17/34] fix(columns): open a header menu over its column and leave double clicks to it --- docs/content/2.essentials/2.customization.md | 11 +++-- docs/content/2.essentials/4.api-reference.md | 2 +- docs/content/2.essentials/6.swimlanes.md | 2 +- .../skills/flowforge-development/SKILL.md | 2 +- resources/css/flowforge-modern.css | 8 ++++ resources/dist/flowforge-modern.js | 2 +- resources/js/flowforge-modern.js | 19 ++++++++- .../modern/livewire/column-header.blade.php | 7 +++- tests/Browser/ModernBoardTest.php | 42 ++++++++++++------- tests/Fixtures/Modern/TestBoard.php | 2 +- tests/Modern/Feature/ColumnHeaderMenuTest.php | 6 +++ 11 files changed, 74 insertions(+), 29 deletions(-) diff --git a/docs/content/2.essentials/2.customization.md b/docs/content/2.essentials/2.customization.md index 15dbad57e..ff1867176 100644 --- a/docs/content/2.essentials/2.customization.md +++ b/docs/content/2.essentials/2.customization.md @@ -311,6 +311,8 @@ same rail as an empty one and stays a full drop target. The empty-column rule fr ### Let users toggle columns `collapsibleColumns()` turns on double-click on a column header and a click on a collapsed rail. +A header that opens a menu from `columnHeaderMenu()` leaves its clicks to the menu, so only the +menu's own items collapse it. Flowforge keeps no state. It calls your closure with the column id and the new state, and you store it where `collapsedColumns()` reads it: @@ -346,10 +348,11 @@ use Illuminate\Support\HtmlString; )) ``` -A click opens the menu at once. A press that moves more than 4px before release is a header drag, -so it does not open the menu. With `collapsibleColumns()`, a double-click closes the menu and -collapses the column. Double-clicks inside the panel and on inputs, textareas, selects and editable -content never collapse it, so a word in your block's inputs can be selected. Return `null` for no +A click opens the menu at once, over the column and 4px past each of its edges, so it covers the +header it came from. The second click of a double-click lands in the menu and leaves it open. A +press that moves more than 4px before release is a header drag, so it does not open the menu. Mark +a field in your block with `data-autofocus` and a mouse or trackpad click focuses it with the caret +at the end. A touch tap does not, so a phone keeps its keyboard down. Return `null` for no block. A column with no block and no visible actions renders a plain header, and a collapsed column has no menu. diff --git a/docs/content/2.essentials/4.api-reference.md b/docs/content/2.essentials/4.api-reference.md index e0d28d4c6..4f5eef717 100644 --- a/docs/content/2.essentials/4.api-reference.md +++ b/docs/content/2.essentials/4.api-reference.md @@ -30,7 +30,7 @@ navigation: | `collapseEmptyColumns(bool)` | Collapse columns holding no cards into a rail | | | `collapsedColumns(array\|Closure)` | Collapse the listed column ids into a rail. Unknown and hidden ids are ignored | | | `collapseAllColumns(bool\|Closure)` | Collapse every visible column into a rail | | -| `collapsibleColumns(?Closure)` | Let users toggle a column by double-clicking its header or clicking its rail. Only columns listed in `collapsedColumns()` expand from the rail. The closure receives `string $columnId` and `bool $collapsed` (the new state) | | +| `collapsibleColumns(?Closure)` | Let users toggle a column by double-clicking its header (one without a `columnHeaderMenu()`) or clicking its rail. Only columns listed in `collapsedColumns()` expand from the rail. The closure receives `string $columnId` and `bool $collapsed` (the new state) | | | `columnHeaderMenu(?Closure)` | Turn the column heading into a menu trigger. The closure receives `array $column` and returns an `Htmlable` block, or `null` for none. The panel holds the block, then the column actions as list items | | | `addColumnUsing(?Closure)` | Show an add column tile after the last column. The closure receives `string $name`, the trimmed name the user typed. Throw a `ValidationException` to show its first message under the input. Leave it unset to hide the tile | | | `addColumnLabel(string\|Closure\|null)` | The tile's tooltip and input label. Defaults to "Add column" | | diff --git a/docs/content/2.essentials/6.swimlanes.md b/docs/content/2.essentials/6.swimlanes.md index 47c172bc6..2c5294cd8 100644 --- a/docs/content/2.essentials/6.swimlanes.md +++ b/docs/content/2.essentials/6.swimlanes.md @@ -94,5 +94,5 @@ While the board query carries an order, a card dragged within a cell is written - `collapsedColumns()` and `collapseAllColumns()` apply in lanes. A collapsed column takes one narrow track in every lane. Its head shows a color dot and the count at the normal head height, with the name as a tooltip, and each cell under it shows its card count and no cards. Each cell under a collapsed column loads one record for its count and shows no cards. - With `addColumnUsing()` set, the add column tile is one extra track at the end of the header row, at head height. The lane headers and cells do not get that track, so every cell keeps its column. - While a card is dragged, every collapsed track opens to full width, so each cell under it is a drop target. The tracks close again after the drop. -- With `collapsibleColumns()`, double-click a column head to collapse it and click its rail to open it again, as on the plain board. +- With `collapsibleColumns()`, double-click a column head without a header menu to collapse it and click its rail to open it again, as on the plain board. - `collapseEmptyColumns()` applies to the plain board only. In lanes an empty column keeps its width, so every cell stays a drop target. diff --git a/resources/boost/skills/flowforge-development/SKILL.md b/resources/boost/skills/flowforge-development/SKILL.md index 98a106fa6..fb7cceeb9 100644 --- a/resources/boost/skills/flowforge-development/SKILL.md +++ b/resources/boost/skills/flowforge-development/SKILL.md @@ -365,7 +365,7 @@ A "Group by" select appears and the choice lives in `?groupBy=`. `lanes()` retur ### Column controls -The host owns the state and Flowforge renders it. `collapsedColumns(fn () => [...])` and `collapseAllColumns(fn () => ...)` collapse columns. `collapsibleColumns(fn (string $columnId, bool $collapsed) => ...)` lets a double-click on a header collapse it and a click on its rail expand it. Only columns listed in `collapsedColumns()` expand by click. `columnHeaderMenu(fn (array $column): ?Htmlable => ...)` turns the header into a menu holding the host block above the column actions. `addColumnUsing(fn (string $name) => ...)` with `addColumnLabel()` and `addColumnPlaceholder()` adds a tile after the last column; throw a `ValidationException` to show a message under its input. Pass any value the page changes during a request as a closure, because the board is built before the action runs. +The host owns the state and Flowforge renders it. `collapsedColumns(fn () => [...])` and `collapseAllColumns(fn () => ...)` collapse columns. `collapsibleColumns(fn (string $columnId, bool $collapsed) => ...)` lets a double-click on a header collapse it and a click on its rail expand it. Only columns listed in `collapsedColumns()` expand by click. `columnHeaderMenu(fn (array $column): ?Htmlable => ...)` turns the header into a menu holding the host block above the column actions. It opens over its column, takes the header's clicks so a double-click no longer collapses, and focuses a `data-autofocus` field on a mouse click. `addColumnUsing(fn (string $name) => ...)` with `addColumnLabel()` and `addColumnPlaceholder()` adds a tile after the last column; throw a `ValidationException` to show a message under its input. Pass any value the page changes during a request as a closure, because the board is built before the action runs. ### Styling a Modern Board diff --git a/resources/css/flowforge-modern.css b/resources/css/flowforge-modern.css index 74ad4ddaf..438712c81 100644 --- a/resources/css/flowforge-modern.css +++ b/resources/css/flowforge-modern.css @@ -287,6 +287,14 @@ padding: 0.5rem 0.75rem; } + /* The menu opens over its column, 4px past each edge, so it covers the header it came from. */ + @media (width >= 40rem) { + .ff-column-menu > .fi-dropdown-panel { + width: calc(var(--_column-width) + 0.5rem); + min-width: calc(var(--_column-width) + 0.5rem); + } + } + .ff-column-actions { display: flex; flex-shrink: 0; diff --git a/resources/dist/flowforge-modern.js b/resources/dist/flowforge-modern.js index 43c02d8b4..4a9105621 100644 --- a/resources/dist/flowforge-modern.js +++ b/resources/dist/flowforge-modern.js @@ -1 +1 @@ -var S=["--ff-surface","--ff-surface-sunken","--ff-surface-raised","--ff-border","--ff-text","--ff-text-muted","--ff-accent","--ff-accent-tint","--ff-danger","--ff-warning","--ff-radius","--ff-gap","--ff-ease","--ff-duration","--ff-column-width","--ff-tray-bg","--ff-tray-radius","--ff-card-bg","--ff-card-ring","--ff-card-radius","--ff-card-shadow","--ff-card-padding","--ff-drag-tilt","--ff-drag-shadow","--ff-placeholder-border"],g='.ff-column-actions, .fi-dropdown-panel, input, textarea, select, [contenteditable]:not([contenteditable="false"])';var h=new WeakSet,c=new WeakSet,m=()=>window.Sortable.active||window.Sortable.dragged;function y(){return{isLoading:{},fullyLoaded:{},dragOverColumn:null,railToggledAt:0,columnMenuPressAt:null,railPressAt:null,dragOverLane:null,dragSource:null,pendingCounts:{},pendingMoves:0,collapsedLanes:{},addingColumn:!1,newColumnName:"",newColumnTouched:!1,addingColumnPending:!1,placeholder:null,stopTrackingPointer:null,init(){this.$wire.$on("kanban-items-loaded",e=>{let{columnId:t,isFullyLoaded:o}=e;o&&(this.fullyLoaded[t]=!0)})},configureSortable(e){if(!e.sortable||e.sortable.options.forceFallback)return;if(m()){this.configureSortableAfterDrag(e);return}let t=window.matchMedia("(prefers-reduced-motion: reduce)").matches;e.sortable.destroy(),e.sortable=window.Sortable.create(e,{draggable:"[x-sortable-item]",handle:"[x-sortable-handle]",dataIdAttr:"x-sortable-item",forceFallback:!0,fallbackTolerance:5,fallbackOnBody:!0,fallbackClass:"",ghostClass:"",delay:150,delayOnTouchOnly:!0,animation:t?0:200,scrollSensitivity:100,scrollSpeed:15,forceAutoScrollFallback:!0,group:{name:e.getAttribute("x-sortable-group"),pull:!0,put:(o,n)=>this.canDrop(o.el,n.el)},onStart:o=>this.startDrag(o),onEnd(o){let{item:n,to:r,oldDraggableIndex:s,newDraggableIndex:i}=o;if(s===i)return;let l=r.querySelectorAll(`:scope > ${this.options.draggable}`)[i-1];l&&r.insertBefore(n,l.nextSibling)}})},configureSortableAfterDrag(e){if(c.has(e))return;c.add(e);let t=()=>{if(m()){requestAnimationFrame(t);return}c.delete(e),e.isConnected&&this.configureSortable(e)};requestAnimationFrame(t)},startDrag(e){this.stopTrackingPointer?.(),this.placeholder=e.item,this.placeholder.setAttribute("data-placeholder",""),this.markGhost(),window.getSelection()?.removeAllRanges(),document.documentElement.classList.add("ff-dragging"),this.dragSource={column:e.from.dataset.columnId,lane:e.from.dataset.laneId??null};let t=o=>this.trackPointer(o);document.addEventListener("pointermove",t,{passive:!0}),document.addEventListener("touchmove",t,{passive:!0}),this.stopTrackingPointer=()=>{document.removeEventListener("pointermove",t),document.removeEventListener("touchmove",t)}},trackPointer(e){if(!window.Sortable.active){this.endDrag();return}this.markGhost();let t=e.touches?.[0]??e,o=document.elementFromPoint(t.clientX,t.clientY),n=o?.closest("[data-column-id]"),r=o?.closest("[data-column-root]");this.dragOverColumn=n?.dataset.columnId??r?.dataset.columnRoot??null,this.dragOverLane=n?.dataset.laneId??null},markGhost(){let e=window.Sortable.ghost;if(!e||e.hasAttribute("data-dragging"))return;e.removeAttribute("data-placeholder"),e.setAttribute("data-dragging",""),e.style.opacity="1";let t=getComputedStyle(this.placeholder);for(let o of S){let n=t.getPropertyValue(o);n!==""&&e.style.setProperty(o,n)}},endDrag(){document.documentElement.classList.remove("ff-dragging"),this.placeholder?.removeAttribute("data-placeholder"),this.placeholder=null,this.stopTrackingPointer?.(),this.stopTrackingPointer=null,this.dragOverColumn=null,this.dragOverLane=null,this.dragSource=null},railPress(e){this.railPressAt={x:e.clientX,y:e.clientY}},toggleColumnCollapse(e,t,o=!1){if(!(e.target.closest(g)||o&&e.detail>1)){if(o){let n=this.railPressAt;if(this.railPressAt=null,n&&Math.hypot(e.clientX-n.x,e.clientY-n.y)>4)return}Date.now()-this.railToggledAt<500||(o&&(this.railToggledAt=Date.now()),this.$wire.toggleBoardColumnCollapse(t))}},openNewColumn(){this.addingColumn=!0,this.newColumnTouched=!0,this.$nextTick(()=>{this.$refs.newColumnInput.focus({preventScroll:!0}),requestAnimationFrame(()=>this.$refs.newColumnInput.scrollIntoView({block:"nearest",inline:"nearest"}))})},cancelNewColumn(){this.addingColumn=!1,this.newColumnTouched=!0,this.newColumnName=""},async submitNewColumn(){if(!this.addingColumnPending){this.addingColumnPending=!0,this.newColumnTouched=!0;try{await this.$wire.addBoardColumn(this.newColumnName)}finally{this.addingColumnPending=!1}this.newColumnTouched=!1,this.$root.querySelector(".ff-add-column-error")||this.cancelNewColumn()}},suppressDoubleClickSelection(e){e.detail>1&&!e.target.closest(g)&&e.preventDefault()},initColumnMenu(e){let t=e.closest(".fi-dropdown");if(h.has(t))return;let o=window.Alpine.$data(t),n=o.toggle.bind(o);h.add(t),o.toggle=r=>r?.type==="mousedown"?void 0:n(r)},columnMenuPress(e){this.columnMenuPressAt={x:e.clientX,y:e.clientY}},columnMenuClick(e){let t=this.columnMenuPressAt;this.columnMenuPressAt=null,!(t&&Math.hypot(e.clientX-t.x,e.clientY-t.y)>4)&&window.Alpine.$data(e.currentTarget.closest(".fi-dropdown")).toggle(e)},columnDrop(e){return this.dragOverColumn!==e?null:this.isColumnBlocked(e)?"blocked":"active"},cellDrop(e,t){return this.dragOverColumn!==e||this.dragOverLane!==t?null:this.isCellBlocked(e,t)?"blocked":"active"},canDrop(e,t){if(!this.$root.contains(e)||!this.$root.contains(t))return!1;let o=e.dataset.laneId??null,n=t.dataset.laneId??null;return o!==n&&this.$root.dataset.lanesWritable!=="true"?!1:!this.isColumnBlocked(e.dataset.columnId,t.dataset.columnId)},isColumnBlocked(e,t=this.dragSource?.column){if(!e||e===t)return!1;let o=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"]`),n=o?.dataset.columnLimit;return n===void 0||n===""?!1:Number(o.dataset.columnTotal)>=Number(n)},isCellBlocked(e,t){return this.dragSource?t!==this.dragSource.lane&&this.$root.dataset.lanesWritable!=="true"?!0:this.isColumnBlocked(e):!1},displayCount(e,t){let o=this.pendingCounts[e]??t,n=this.dragSource?.column,r=this.dragOverColumn;return!n||!r||n===r||this.isColumnBlocked(r)?o:e===r?o+1:e===n?o-1:o},holdMovedCounts(e,t){if(e===t)return()=>{};let o={[e]:-1,[t]:1},n=!1;for(let[r,s]of Object.entries(o))this.pendingCounts[r]=this.renderedCount(r)+s;return this.pendingMoves++,r=>{if(!n){if(n=!0,r)for(let[s,i]of Object.entries(o))this.pendingCounts[s]-=i;--this.pendingMoves===0&&(this.pendingCounts={})}}},renderedCount(e){let t=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"] .ff-count`);return this.pendingCounts[e]??Number(t?.dataset.total)},handleSortableEnd(e){this.endDrag();let t=e.item,o=e.to,n=e.newDraggableIndex??e.newIndex,r=":scope > [x-sortable-item], :scope > [data-card-id]",s=a=>a.getAttribute("x-sortable-item")||a.getAttribute("data-card-id");if(e.from===o&&e.oldDraggableIndex===e.newDraggableIndex)return;if(n===0){let a=o.querySelector(r);a&&a!==t&&o.insertBefore(t,a)}let i=s(t);if(!i){console.error("Flowforge: Could not determine card ID for move operation");return}let l=o.getAttribute("data-column-id");if(!l){console.error("Flowforge: Target column ID is missing");return}let p=e.from.dataset.laneId??null,C=o.dataset.laneId??null,u=o.querySelectorAll(r),d=Array.prototype.indexOf.call(u,t),b=d>0?s(u[d-1]):null,w=d>=0&&d{this.setCardState(t,!1),f(a===!1),a===!1&&this.revertCard(e)}).catch(()=>{this.setCardState(t,!1),f(!0),this.revertCard(e)})},revertCard({item:e,from:t,oldDraggableIndex:o}){e.remove();let n=t.querySelectorAll(":scope > [x-sortable-item]"),r=n[n.length-1],s=n[o]??(r?r.nextSibling:t.firstChild);t.insertBefore(e,s)},setCardState(e,t){e.toggleAttribute("data-pending",t)},isLaneCollapsed(e){return this.collapsedLanes[e]===!0},toggleLane(e){this.collapsedLanes[e]=!this.isLaneCollapsed(e)},isLoadingColumn(e){return this.isLoading[e]||!1},isColumnFullyLoaded(e){return this.fullyLoaded[e]||!1},handleSmoothScroll(e){this.isLoadingColumn(e)||this.isColumnFullyLoaded(e)||(this.isLoading[e]=!0,this.$wire.loadMoreItems(e).then(()=>setTimeout(()=>this.isLoading[e]=!1,100)).catch(()=>this.isLoading[e]=!1))},handleColumnScroll(e,t){if(this.isColumnFullyLoaded(t))return;let{scrollTop:o,scrollHeight:n,clientHeight:r}=e.target;(o+r)/n>=.8&&!this.isLoadingColumn(t)&&this.handleSmoothScroll(t)}}}export{y as default}; +var S=["--ff-surface","--ff-surface-sunken","--ff-surface-raised","--ff-border","--ff-text","--ff-text-muted","--ff-accent","--ff-accent-tint","--ff-danger","--ff-warning","--ff-radius","--ff-gap","--ff-ease","--ff-duration","--ff-column-width","--ff-tray-bg","--ff-tray-radius","--ff-card-bg","--ff-card-ring","--ff-card-radius","--ff-card-shadow","--ff-card-padding","--ff-drag-tilt","--ff-drag-shadow","--ff-placeholder-border"],g='.ff-column-actions, .fi-dropdown-panel, input, textarea, select, [contenteditable]:not([contenteditable="false"])';var y=e=>{let t=e.querySelector("[data-autofocus]");!t||e.style.display!=="block"||!window.matchMedia("(pointer: fine)").matches||(t.focus({preventScroll:!0}),t.setSelectionRange?.(t.value.length,t.value.length))},h=new WeakSet,c=new WeakSet,m=()=>window.Sortable.active||window.Sortable.dragged;function A(){return{isLoading:{},fullyLoaded:{},dragOverColumn:null,railToggledAt:0,columnMenuPressAt:null,railPressAt:null,dragOverLane:null,dragSource:null,pendingCounts:{},pendingMoves:0,collapsedLanes:{},addingColumn:!1,newColumnName:"",newColumnTouched:!1,addingColumnPending:!1,placeholder:null,stopTrackingPointer:null,init(){this.$wire.$on("kanban-items-loaded",e=>{let{columnId:t,isFullyLoaded:o}=e;o&&(this.fullyLoaded[t]=!0)})},configureSortable(e){if(!e.sortable||e.sortable.options.forceFallback)return;if(m()){this.configureSortableAfterDrag(e);return}let t=window.matchMedia("(prefers-reduced-motion: reduce)").matches;e.sortable.destroy(),e.sortable=window.Sortable.create(e,{draggable:"[x-sortable-item]",handle:"[x-sortable-handle]",dataIdAttr:"x-sortable-item",forceFallback:!0,fallbackTolerance:5,fallbackOnBody:!0,fallbackClass:"",ghostClass:"",delay:150,delayOnTouchOnly:!0,animation:t?0:200,scrollSensitivity:100,scrollSpeed:15,forceAutoScrollFallback:!0,group:{name:e.getAttribute("x-sortable-group"),pull:!0,put:(o,n)=>this.canDrop(o.el,n.el)},onStart:o=>this.startDrag(o),onEnd(o){let{item:n,to:r,oldDraggableIndex:s,newDraggableIndex:i}=o;if(s===i)return;let l=r.querySelectorAll(`:scope > ${this.options.draggable}`)[i-1];l&&r.insertBefore(n,l.nextSibling)}})},configureSortableAfterDrag(e){if(c.has(e))return;c.add(e);let t=()=>{if(m()){requestAnimationFrame(t);return}c.delete(e),e.isConnected&&this.configureSortable(e)};requestAnimationFrame(t)},startDrag(e){this.stopTrackingPointer?.(),this.placeholder=e.item,this.placeholder.setAttribute("data-placeholder",""),this.markGhost(),window.getSelection()?.removeAllRanges(),document.documentElement.classList.add("ff-dragging"),this.dragSource={column:e.from.dataset.columnId,lane:e.from.dataset.laneId??null};let t=o=>this.trackPointer(o);document.addEventListener("pointermove",t,{passive:!0}),document.addEventListener("touchmove",t,{passive:!0}),this.stopTrackingPointer=()=>{document.removeEventListener("pointermove",t),document.removeEventListener("touchmove",t)}},trackPointer(e){if(!window.Sortable.active){this.endDrag();return}this.markGhost();let t=e.touches?.[0]??e,o=document.elementFromPoint(t.clientX,t.clientY),n=o?.closest("[data-column-id]"),r=o?.closest("[data-column-root]");this.dragOverColumn=n?.dataset.columnId??r?.dataset.columnRoot??null,this.dragOverLane=n?.dataset.laneId??null},markGhost(){let e=window.Sortable.ghost;if(!e||e.hasAttribute("data-dragging"))return;e.removeAttribute("data-placeholder"),e.setAttribute("data-dragging",""),e.style.opacity="1";let t=getComputedStyle(this.placeholder);for(let o of S){let n=t.getPropertyValue(o);n!==""&&e.style.setProperty(o,n)}},endDrag(){document.documentElement.classList.remove("ff-dragging"),this.placeholder?.removeAttribute("data-placeholder"),this.placeholder=null,this.stopTrackingPointer?.(),this.stopTrackingPointer=null,this.dragOverColumn=null,this.dragOverLane=null,this.dragSource=null},railPress(e){this.railPressAt={x:e.clientX,y:e.clientY}},toggleColumnCollapse(e,t,o=!1){if(!(e.target.closest(g)||o&&e.detail>1)){if(o){let n=this.railPressAt;if(this.railPressAt=null,n&&Math.hypot(e.clientX-n.x,e.clientY-n.y)>4)return}Date.now()-this.railToggledAt<500||(o&&(this.railToggledAt=Date.now()),this.$wire.toggleBoardColumnCollapse(t))}},openNewColumn(){this.addingColumn=!0,this.newColumnTouched=!0,this.$nextTick(()=>{this.$refs.newColumnInput.focus({preventScroll:!0}),requestAnimationFrame(()=>this.$refs.newColumnInput.scrollIntoView({block:"nearest",inline:"nearest"}))})},cancelNewColumn(){this.addingColumn=!1,this.newColumnTouched=!0,this.newColumnName=""},async submitNewColumn(){if(!this.addingColumnPending){this.addingColumnPending=!0,this.newColumnTouched=!0;try{await this.$wire.addBoardColumn(this.newColumnName)}finally{this.addingColumnPending=!1}this.newColumnTouched=!1,this.$root.querySelector(".ff-add-column-error")||this.cancelNewColumn()}},suppressDoubleClickSelection(e){e.detail>1&&!e.target.closest(g)&&e.preventDefault()},initColumnMenu(e){let t=e.closest(".fi-dropdown");if(h.has(t))return;let o=window.Alpine.$data(t),n=o.toggle.bind(o);h.add(t),o.toggle=r=>r?.type==="mousedown"?void 0:n(r)},columnMenuPress(e){this.columnMenuPressAt={x:e.clientX,y:e.clientY}},columnMenuClick(e){let t=this.columnMenuPressAt;if(this.columnMenuPressAt=null,e.detail>1||t&&Math.hypot(e.clientX-t.x,e.clientY-t.y)>4)return;let o=e.currentTarget.closest(".fi-dropdown");window.Alpine.$data(o).toggle(e),requestAnimationFrame(()=>y(o.querySelector(":scope > .fi-dropdown-panel")))},columnDrop(e){return this.dragOverColumn!==e?null:this.isColumnBlocked(e)?"blocked":"active"},cellDrop(e,t){return this.dragOverColumn!==e||this.dragOverLane!==t?null:this.isCellBlocked(e,t)?"blocked":"active"},canDrop(e,t){if(!this.$root.contains(e)||!this.$root.contains(t))return!1;let o=e.dataset.laneId??null,n=t.dataset.laneId??null;return o!==n&&this.$root.dataset.lanesWritable!=="true"?!1:!this.isColumnBlocked(e.dataset.columnId,t.dataset.columnId)},isColumnBlocked(e,t=this.dragSource?.column){if(!e||e===t)return!1;let o=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"]`),n=o?.dataset.columnLimit;return n===void 0||n===""?!1:Number(o.dataset.columnTotal)>=Number(n)},isCellBlocked(e,t){return this.dragSource?t!==this.dragSource.lane&&this.$root.dataset.lanesWritable!=="true"?!0:this.isColumnBlocked(e):!1},displayCount(e,t){let o=this.pendingCounts[e]??t,n=this.dragSource?.column,r=this.dragOverColumn;return!n||!r||n===r||this.isColumnBlocked(r)?o:e===r?o+1:e===n?o-1:o},holdMovedCounts(e,t){if(e===t)return()=>{};let o={[e]:-1,[t]:1},n=!1;for(let[r,s]of Object.entries(o))this.pendingCounts[r]=this.renderedCount(r)+s;return this.pendingMoves++,r=>{if(!n){if(n=!0,r)for(let[s,i]of Object.entries(o))this.pendingCounts[s]-=i;--this.pendingMoves===0&&(this.pendingCounts={})}}},renderedCount(e){let t=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"] .ff-count`);return this.pendingCounts[e]??Number(t?.dataset.total)},handleSortableEnd(e){this.endDrag();let t=e.item,o=e.to,n=e.newDraggableIndex??e.newIndex,r=":scope > [x-sortable-item], :scope > [data-card-id]",s=a=>a.getAttribute("x-sortable-item")||a.getAttribute("data-card-id");if(e.from===o&&e.oldDraggableIndex===e.newDraggableIndex)return;if(n===0){let a=o.querySelector(r);a&&a!==t&&o.insertBefore(t,a)}let i=s(t);if(!i){console.error("Flowforge: Could not determine card ID for move operation");return}let l=o.getAttribute("data-column-id");if(!l){console.error("Flowforge: Target column ID is missing");return}let p=e.from.dataset.laneId??null,C=o.dataset.laneId??null,u=o.querySelectorAll(r),d=Array.prototype.indexOf.call(u,t),b=d>0?s(u[d-1]):null,w=d>=0&&d{this.setCardState(t,!1),f(a===!1),a===!1&&this.revertCard(e)}).catch(()=>{this.setCardState(t,!1),f(!0),this.revertCard(e)})},revertCard({item:e,from:t,oldDraggableIndex:o}){e.remove();let n=t.querySelectorAll(":scope > [x-sortable-item]"),r=n[n.length-1],s=n[o]??(r?r.nextSibling:t.firstChild);t.insertBefore(e,s)},setCardState(e,t){e.toggleAttribute("data-pending",t)},isLaneCollapsed(e){return this.collapsedLanes[e]===!0},toggleLane(e){this.collapsedLanes[e]=!this.isLaneCollapsed(e)},isLoadingColumn(e){return this.isLoading[e]||!1},isColumnFullyLoaded(e){return this.fullyLoaded[e]||!1},handleSmoothScroll(e){this.isLoadingColumn(e)||this.isColumnFullyLoaded(e)||(this.isLoading[e]=!0,this.$wire.loadMoreItems(e).then(()=>setTimeout(()=>this.isLoading[e]=!1,100)).catch(()=>this.isLoading[e]=!1))},handleColumnScroll(e,t){if(this.isColumnFullyLoaded(t))return;let{scrollTop:o,scrollHeight:n,clientHeight:r}=e.target;(o+r)/n>=.8&&!this.isLoadingColumn(t)&&this.handleSmoothScroll(t)}}}export{A as default}; diff --git a/resources/js/flowforge-modern.js b/resources/js/flowforge-modern.js index 324317183..92cf579ab 100644 --- a/resources/js/flowforge-modern.js +++ b/resources/js/flowforge-modern.js @@ -30,6 +30,18 @@ const HEADER_GESTURE_IGNORED = '.ff-column-actions, .fi-dropdown-panel, input, t const MENU_DRAG_THRESHOLD = 4; +const focusMenuField = (panel) => { + const field = panel.querySelector('[data-autofocus]'); + + // A touch screen would raise its keyboard for a menu opened to collapse or hide. + if (!field || panel.style.display !== 'block' || !window.matchMedia('(pointer: fine)').matches) { + return; + } + + field.focus({ preventScroll: true }); + field.setSelectionRange?.(field.value.length, field.value.length); +}; + const menusIgnoringMousedown = new WeakSet(); const sortablesAwaitingDrag = new WeakSet(); @@ -324,11 +336,14 @@ export default function flowforgeModern() { this.columnMenuPressAt = null; - if (press && Math.hypot(event.clientX - press.x, event.clientY - press.y) > MENU_DRAG_THRESHOLD) { + if (event.detail > 1 || (press && Math.hypot(event.clientX - press.x, event.clientY - press.y) > MENU_DRAG_THRESHOLD)) { return; } - window.Alpine.$data(event.currentTarget.closest('.fi-dropdown')).toggle(event); + const root = event.currentTarget.closest('.fi-dropdown'); + + window.Alpine.$data(root).toggle(event); + requestAnimationFrame(() => focusMenuField(root.querySelector(':scope > .fi-dropdown-panel'))); }, columnDrop(columnId) { diff --git a/resources/views/modern/livewire/column-header.blade.php b/resources/views/modern/livewire/column-header.blade.php index 1f8340863..1b68eb56b 100644 --- a/resources/views/modern/livewire/column-header.blade.php +++ b/resources/views/modern/livewire/column-header.blade.php @@ -20,17 +20,20 @@ } $createAction = $createAction?->isVisible() ? $createAction : null; + + // x-float reads this before the board's Alpine data loads, so it carries its own logic. The 4px matches the 0.5rem wider panel. + $menuOffset = '({ elements: { reference } }) => { const column = reference.closest(\'[data-column-root]\').getBoundingClientRect(); const trigger = reference.getBoundingClientRect(); return { mainAxis: column.top - 4 - trigger.bottom, crossAxis: column.left - 4 - trigger.left }; }'; @endphp
@if ($hasMenu) - + script("document.querySelector('{$root} .fi-dropdown-panel').innerText"))->toContain("Block for {$label}")->toContain('Archive column'); })->with([['todo', 'To Do'], ['in_progress', 'In Progress']]); -test('double clicking a header with a menu closes the menu and collapses the column', function () { +test('double clicking a header with a menu leaves the menu open and the column expanded', function (string $path) { + boardSeed(); + $page = boardPage($path); + $pointer = Pointer::on($page); + $root = '[data-column-root="todo"]'; + + $pointer->doubleClick("{$root} .ff-column-heading", 120)->wait(600); + + expect($page->script("document.querySelector('{$root} .fi-dropdown-panel').style.display"))->toBe('block') + ->and($page->script("document.querySelector('{$root}').hasAttribute('data-collapsed')"))->toBeFalse(); +})->with(['/modern/test-menu-board', '/modern/test-menu-static-board']); + +test('a header click opens the menu over its column with the marked field focused', function () { boardSeed(); $page = boardPage('/modern/test-menu-board'); $pointer = Pointer::on($page); $root = '[data-column-root="todo"]'; - $pointer->doubleClick("{$root} .ff-column-heading"); - $pointer->untilScript("document.querySelector('{$root}').hasAttribute('data-collapsed')"); + $pointer->click("{$root} .ff-column-heading"); + $pointer->untilScript("document.activeElement.matches('{$root} .ff-test-menu-input')"); + + $geometry = $page->script(<< { + const column = document.querySelector('{$root}').getBoundingClientRect(); + const panel = document.querySelector('{$root} .fi-dropdown-panel').getBoundingClientRect(); - expect($page->script("document.querySelectorAll('.fi-dropdown-panel[style*=\"display: block\"]').length"))->toBe(0); + return [column.left - panel.left, column.top - panel.top, panel.width - column.width]; + })() + JS); + + expect($geometry)->toBe([4, 4, 8]) + ->and($page->script('document.activeElement.selectionStart'))->toBe(7); }); test('releasing a header drag does not open the menu', function (string $column) { @@ -935,18 +957,6 @@ function boardTraySampler(int $budgetMilliseconds): string $pointer->untilScript("document.querySelector('{$root} .fi-dropdown-panel').style.display === 'block'"); }); -test('a double click closes the menu it opened when nothing collapses', function () { - boardSeed(); - $page = boardPage('/modern/test-menu-static-board'); - $pointer = Pointer::on($page); - $root = '[data-column-root="todo"]'; - - $pointer->doubleClick("{$root} .ff-column-heading", 120)->wait(600); - - expect($page->script("document.querySelector('{$root} .fi-dropdown-panel').style.display"))->not->toBe('block') - ->and($page->script("document.querySelector('{$root}').hasAttribute('data-collapsed')"))->toBeFalse(); -}); - test('a board update leaves an open menu open', function () { boardSeed(); $page = boardPage('/modern/test-menu-board'); diff --git a/tests/Fixtures/Modern/TestBoard.php b/tests/Fixtures/Modern/TestBoard.php index 2f5556680..c1d9af654 100644 --- a/tests/Fixtures/Modern/TestBoard.php +++ b/tests/Fixtures/Modern/TestBoard.php @@ -121,7 +121,7 @@ public function board(Board $board): Board ->columnHeaderMenu($this->withHeaderMenu ? fn (array $column): ?HtmlString => $this->nullMenuBlock ? null - : new HtmlString('
Block for ' . $column['label'] . '
') + : new HtmlString('
Block for ' . $column['label'] . '
') : null) ->query($this->getEloquentQuery()) ->recordTitleAttribute('title') diff --git a/tests/Modern/Feature/ColumnHeaderMenuTest.php b/tests/Modern/Feature/ColumnHeaderMenuTest.php index 3e27cbb45..f76eea77d 100644 --- a/tests/Modern/Feature/ColumnHeaderMenuTest.php +++ b/tests/Modern/Feature/ColumnHeaderMenuTest.php @@ -43,6 +43,12 @@ function menuHasClass(string $class): string ->and(menuXpath($html, '//div[' . menuHasClass('ff-column-actions') . ']//button'))->toHaveCount(3); }); + test('a collapsible header with a menu leaves the double click to the menu', function () { + $html = Livewire::test(TestBoard::class, ['withHeaderMenu' => true, 'collapsible' => true])->html(); + + expect($html)->not->toContain('x-on:dblclick'); + }); + test('the trigger is a div with the button role so a header drag handle does not filter it out', function () { $html = Livewire::test(TestBoard::class, ['withHeaderMenu' => true])->html(); From 6e8c42527c6ae3ac7b3957ef51ad477097e492f9 Mon Sep 17 00:00:00 2001 From: Manuk Date: Sat, 14 Nov 2026 23:18:03 +0400 Subject: [PATCH 18/34] feat(columns): collapse from empty space, draw hex dots exactly, and size the menu to its column --- docs/content/2.essentials/2.customization.md | 11 +++---- docs/content/2.essentials/4.api-reference.md | 2 +- docs/content/2.essentials/6.swimlanes.md | 2 +- .../skills/flowforge-development/SKILL.md | 2 +- resources/css/flowforge-modern.css | 6 ++-- resources/dist/flowforge-modern.js | 2 +- resources/js/flowforge-modern.js | 14 +++++++++ .../modern/livewire/column-header.blade.php | 4 +-- .../modern/livewire/column-heading.blade.php | 10 ++----- .../views/modern/livewire/column.blade.php | 4 +++ .../views/modern/livewire/lanes.blade.php | 4 +++ src/Support/ColorResolver.php | 18 ++++++++++++ tests/Browser/ModernBoardTest.php | 29 ++++++++++++++++++- tests/Fixtures/Modern/TestBoard.php | 4 ++- tests/Modern/Feature/ColumnHeaderMenuTest.php | 3 +- tests/Modern/Feature/ColumnLayoutTest.php | 6 ++++ 16 files changed, 97 insertions(+), 24 deletions(-) diff --git a/docs/content/2.essentials/2.customization.md b/docs/content/2.essentials/2.customization.md index ff1867176..2ef10e116 100644 --- a/docs/content/2.essentials/2.customization.md +++ b/docs/content/2.essentials/2.customization.md @@ -310,9 +310,10 @@ same rail as an empty one and stays a full drop target. The empty-column rule fr ### Let users toggle columns -`collapsibleColumns()` turns on double-click on a column header and a click on a collapsed rail. -A header that opens a menu from `columnHeaderMenu()` leaves its clicks to the menu, so only the -menu's own items collapse it. +`collapsibleColumns()` turns on double-click in a column's empty space, flat or in a lane cell, and +a click on a collapsed rail. A double-click on a card, the add card row or a button does nothing. A +header without a `columnHeaderMenu()` collapses on double-click too. A header with one leaves its +clicks to the menu. Flowforge keeps no state. It calls your closure with the column id and the new state, and you store it where `collapsedColumns()` reads it: @@ -348,8 +349,8 @@ use Illuminate\Support\HtmlString; )) ``` -A click opens the menu at once, over the column and 4px past each of its edges, so it covers the -header it came from. The second click of a double-click lands in the menu and leaves it open. A +A click opens the menu at once, over the column at the column's width, so it covers the header it +came from. The second click of a double-click lands in the menu and leaves it open. A press that moves more than 4px before release is a header drag, so it does not open the menu. Mark a field in your block with `data-autofocus` and a mouse or trackpad click focuses it with the caret at the end. A touch tap does not, so a phone keeps its keyboard down. Return `null` for no diff --git a/docs/content/2.essentials/4.api-reference.md b/docs/content/2.essentials/4.api-reference.md index 4f5eef717..475735ab6 100644 --- a/docs/content/2.essentials/4.api-reference.md +++ b/docs/content/2.essentials/4.api-reference.md @@ -30,7 +30,7 @@ navigation: | `collapseEmptyColumns(bool)` | Collapse columns holding no cards into a rail | | | `collapsedColumns(array\|Closure)` | Collapse the listed column ids into a rail. Unknown and hidden ids are ignored | | | `collapseAllColumns(bool\|Closure)` | Collapse every visible column into a rail | | -| `collapsibleColumns(?Closure)` | Let users toggle a column by double-clicking its header (one without a `columnHeaderMenu()`) or clicking its rail. Only columns listed in `collapsedColumns()` expand from the rail. The closure receives `string $columnId` and `bool $collapsed` (the new state) | | +| `collapsibleColumns(?Closure)` | Let users toggle a column by double-clicking its empty space or its header (one without a `columnHeaderMenu()`), or clicking its rail. Only columns listed in `collapsedColumns()` expand from the rail. The closure receives `string $columnId` and `bool $collapsed` (the new state) | | | `columnHeaderMenu(?Closure)` | Turn the column heading into a menu trigger. The closure receives `array $column` and returns an `Htmlable` block, or `null` for none. The panel holds the block, then the column actions as list items | | | `addColumnUsing(?Closure)` | Show an add column tile after the last column. The closure receives `string $name`, the trimmed name the user typed. Throw a `ValidationException` to show its first message under the input. Leave it unset to hide the tile | | | `addColumnLabel(string\|Closure\|null)` | The tile's tooltip and input label. Defaults to "Add column" | | diff --git a/docs/content/2.essentials/6.swimlanes.md b/docs/content/2.essentials/6.swimlanes.md index 2c5294cd8..d67cab6fe 100644 --- a/docs/content/2.essentials/6.swimlanes.md +++ b/docs/content/2.essentials/6.swimlanes.md @@ -94,5 +94,5 @@ While the board query carries an order, a card dragged within a cell is written - `collapsedColumns()` and `collapseAllColumns()` apply in lanes. A collapsed column takes one narrow track in every lane. Its head shows a color dot and the count at the normal head height, with the name as a tooltip, and each cell under it shows its card count and no cards. Each cell under a collapsed column loads one record for its count and shows no cards. - With `addColumnUsing()` set, the add column tile is one extra track at the end of the header row, at head height. The lane headers and cells do not get that track, so every cell keeps its column. - While a card is dragged, every collapsed track opens to full width, so each cell under it is a drop target. The tracks close again after the drop. -- With `collapsibleColumns()`, double-click a column head without a header menu to collapse it and click its rail to open it again, as on the plain board. +- With `collapsibleColumns()`, double-click an empty lane cell, or a column head without a header menu, to collapse its column and click its rail to open it again, as on the plain board. - `collapseEmptyColumns()` applies to the plain board only. In lanes an empty column keeps its width, so every cell stays a drop target. diff --git a/resources/boost/skills/flowforge-development/SKILL.md b/resources/boost/skills/flowforge-development/SKILL.md index fb7cceeb9..b56bb2b45 100644 --- a/resources/boost/skills/flowforge-development/SKILL.md +++ b/resources/boost/skills/flowforge-development/SKILL.md @@ -365,7 +365,7 @@ A "Group by" select appears and the choice lives in `?groupBy=`. `lanes()` retur ### Column controls -The host owns the state and Flowforge renders it. `collapsedColumns(fn () => [...])` and `collapseAllColumns(fn () => ...)` collapse columns. `collapsibleColumns(fn (string $columnId, bool $collapsed) => ...)` lets a double-click on a header collapse it and a click on its rail expand it. Only columns listed in `collapsedColumns()` expand by click. `columnHeaderMenu(fn (array $column): ?Htmlable => ...)` turns the header into a menu holding the host block above the column actions. It opens over its column, takes the header's clicks so a double-click no longer collapses, and focuses a `data-autofocus` field on a mouse click. `addColumnUsing(fn (string $name) => ...)` with `addColumnLabel()` and `addColumnPlaceholder()` adds a tile after the last column; throw a `ValidationException` to show a message under its input. Pass any value the page changes during a request as a closure, because the board is built before the action runs. +The host owns the state and Flowforge renders it. `collapsedColumns(fn () => [...])` and `collapseAllColumns(fn () => ...)` collapse columns. `collapsibleColumns(fn (string $columnId, bool $collapsed) => ...)` lets a double-click in a column's empty space, or on a header without a menu, collapse it and a click on its rail expand it. Only columns listed in `collapsedColumns()` expand by click. `columnHeaderMenu(fn (array $column): ?Htmlable => ...)` turns the header into a menu holding the host block above the column actions. It opens over its column, takes the header's clicks, and focuses a `data-autofocus` field on a mouse click. `addColumnUsing(fn (string $name) => ...)` with `addColumnLabel()` and `addColumnPlaceholder()` adds a tile after the last column; throw a `ValidationException` to show a message under its input. Pass any value the page changes during a request as a closure, because the board is built before the action runs. ### Styling a Modern Board diff --git a/resources/css/flowforge-modern.css b/resources/css/flowforge-modern.css index 438712c81..a18f92a49 100644 --- a/resources/css/flowforge-modern.css +++ b/resources/css/flowforge-modern.css @@ -287,11 +287,11 @@ padding: 0.5rem 0.75rem; } - /* The menu opens over its column, 4px past each edge, so it covers the header it came from. */ + /* The menu opens over its column at the column's width, so it covers the header it came from. */ @media (width >= 40rem) { .ff-column-menu > .fi-dropdown-panel { - width: calc(var(--_column-width) + 0.5rem); - min-width: calc(var(--_column-width) + 0.5rem); + width: var(--_column-width); + min-width: var(--_column-width); } } diff --git a/resources/dist/flowforge-modern.js b/resources/dist/flowforge-modern.js index 4a9105621..850453c51 100644 --- a/resources/dist/flowforge-modern.js +++ b/resources/dist/flowforge-modern.js @@ -1 +1 @@ -var S=["--ff-surface","--ff-surface-sunken","--ff-surface-raised","--ff-border","--ff-text","--ff-text-muted","--ff-accent","--ff-accent-tint","--ff-danger","--ff-warning","--ff-radius","--ff-gap","--ff-ease","--ff-duration","--ff-column-width","--ff-tray-bg","--ff-tray-radius","--ff-card-bg","--ff-card-ring","--ff-card-radius","--ff-card-shadow","--ff-card-padding","--ff-drag-tilt","--ff-drag-shadow","--ff-placeholder-border"],g='.ff-column-actions, .fi-dropdown-panel, input, textarea, select, [contenteditable]:not([contenteditable="false"])';var y=e=>{let t=e.querySelector("[data-autofocus]");!t||e.style.display!=="block"||!window.matchMedia("(pointer: fine)").matches||(t.focus({preventScroll:!0}),t.setSelectionRange?.(t.value.length,t.value.length))},h=new WeakSet,c=new WeakSet,m=()=>window.Sortable.active||window.Sortable.dragged;function A(){return{isLoading:{},fullyLoaded:{},dragOverColumn:null,railToggledAt:0,columnMenuPressAt:null,railPressAt:null,dragOverLane:null,dragSource:null,pendingCounts:{},pendingMoves:0,collapsedLanes:{},addingColumn:!1,newColumnName:"",newColumnTouched:!1,addingColumnPending:!1,placeholder:null,stopTrackingPointer:null,init(){this.$wire.$on("kanban-items-loaded",e=>{let{columnId:t,isFullyLoaded:o}=e;o&&(this.fullyLoaded[t]=!0)})},configureSortable(e){if(!e.sortable||e.sortable.options.forceFallback)return;if(m()){this.configureSortableAfterDrag(e);return}let t=window.matchMedia("(prefers-reduced-motion: reduce)").matches;e.sortable.destroy(),e.sortable=window.Sortable.create(e,{draggable:"[x-sortable-item]",handle:"[x-sortable-handle]",dataIdAttr:"x-sortable-item",forceFallback:!0,fallbackTolerance:5,fallbackOnBody:!0,fallbackClass:"",ghostClass:"",delay:150,delayOnTouchOnly:!0,animation:t?0:200,scrollSensitivity:100,scrollSpeed:15,forceAutoScrollFallback:!0,group:{name:e.getAttribute("x-sortable-group"),pull:!0,put:(o,n)=>this.canDrop(o.el,n.el)},onStart:o=>this.startDrag(o),onEnd(o){let{item:n,to:r,oldDraggableIndex:s,newDraggableIndex:i}=o;if(s===i)return;let l=r.querySelectorAll(`:scope > ${this.options.draggable}`)[i-1];l&&r.insertBefore(n,l.nextSibling)}})},configureSortableAfterDrag(e){if(c.has(e))return;c.add(e);let t=()=>{if(m()){requestAnimationFrame(t);return}c.delete(e),e.isConnected&&this.configureSortable(e)};requestAnimationFrame(t)},startDrag(e){this.stopTrackingPointer?.(),this.placeholder=e.item,this.placeholder.setAttribute("data-placeholder",""),this.markGhost(),window.getSelection()?.removeAllRanges(),document.documentElement.classList.add("ff-dragging"),this.dragSource={column:e.from.dataset.columnId,lane:e.from.dataset.laneId??null};let t=o=>this.trackPointer(o);document.addEventListener("pointermove",t,{passive:!0}),document.addEventListener("touchmove",t,{passive:!0}),this.stopTrackingPointer=()=>{document.removeEventListener("pointermove",t),document.removeEventListener("touchmove",t)}},trackPointer(e){if(!window.Sortable.active){this.endDrag();return}this.markGhost();let t=e.touches?.[0]??e,o=document.elementFromPoint(t.clientX,t.clientY),n=o?.closest("[data-column-id]"),r=o?.closest("[data-column-root]");this.dragOverColumn=n?.dataset.columnId??r?.dataset.columnRoot??null,this.dragOverLane=n?.dataset.laneId??null},markGhost(){let e=window.Sortable.ghost;if(!e||e.hasAttribute("data-dragging"))return;e.removeAttribute("data-placeholder"),e.setAttribute("data-dragging",""),e.style.opacity="1";let t=getComputedStyle(this.placeholder);for(let o of S){let n=t.getPropertyValue(o);n!==""&&e.style.setProperty(o,n)}},endDrag(){document.documentElement.classList.remove("ff-dragging"),this.placeholder?.removeAttribute("data-placeholder"),this.placeholder=null,this.stopTrackingPointer?.(),this.stopTrackingPointer=null,this.dragOverColumn=null,this.dragOverLane=null,this.dragSource=null},railPress(e){this.railPressAt={x:e.clientX,y:e.clientY}},toggleColumnCollapse(e,t,o=!1){if(!(e.target.closest(g)||o&&e.detail>1)){if(o){let n=this.railPressAt;if(this.railPressAt=null,n&&Math.hypot(e.clientX-n.x,e.clientY-n.y)>4)return}Date.now()-this.railToggledAt<500||(o&&(this.railToggledAt=Date.now()),this.$wire.toggleBoardColumnCollapse(t))}},openNewColumn(){this.addingColumn=!0,this.newColumnTouched=!0,this.$nextTick(()=>{this.$refs.newColumnInput.focus({preventScroll:!0}),requestAnimationFrame(()=>this.$refs.newColumnInput.scrollIntoView({block:"nearest",inline:"nearest"}))})},cancelNewColumn(){this.addingColumn=!1,this.newColumnTouched=!0,this.newColumnName=""},async submitNewColumn(){if(!this.addingColumnPending){this.addingColumnPending=!0,this.newColumnTouched=!0;try{await this.$wire.addBoardColumn(this.newColumnName)}finally{this.addingColumnPending=!1}this.newColumnTouched=!1,this.$root.querySelector(".ff-add-column-error")||this.cancelNewColumn()}},suppressDoubleClickSelection(e){e.detail>1&&!e.target.closest(g)&&e.preventDefault()},initColumnMenu(e){let t=e.closest(".fi-dropdown");if(h.has(t))return;let o=window.Alpine.$data(t),n=o.toggle.bind(o);h.add(t),o.toggle=r=>r?.type==="mousedown"?void 0:n(r)},columnMenuPress(e){this.columnMenuPressAt={x:e.clientX,y:e.clientY}},columnMenuClick(e){let t=this.columnMenuPressAt;if(this.columnMenuPressAt=null,e.detail>1||t&&Math.hypot(e.clientX-t.x,e.clientY-t.y)>4)return;let o=e.currentTarget.closest(".fi-dropdown");window.Alpine.$data(o).toggle(e),requestAnimationFrame(()=>y(o.querySelector(":scope > .fi-dropdown-panel")))},columnDrop(e){return this.dragOverColumn!==e?null:this.isColumnBlocked(e)?"blocked":"active"},cellDrop(e,t){return this.dragOverColumn!==e||this.dragOverLane!==t?null:this.isCellBlocked(e,t)?"blocked":"active"},canDrop(e,t){if(!this.$root.contains(e)||!this.$root.contains(t))return!1;let o=e.dataset.laneId??null,n=t.dataset.laneId??null;return o!==n&&this.$root.dataset.lanesWritable!=="true"?!1:!this.isColumnBlocked(e.dataset.columnId,t.dataset.columnId)},isColumnBlocked(e,t=this.dragSource?.column){if(!e||e===t)return!1;let o=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"]`),n=o?.dataset.columnLimit;return n===void 0||n===""?!1:Number(o.dataset.columnTotal)>=Number(n)},isCellBlocked(e,t){return this.dragSource?t!==this.dragSource.lane&&this.$root.dataset.lanesWritable!=="true"?!0:this.isColumnBlocked(e):!1},displayCount(e,t){let o=this.pendingCounts[e]??t,n=this.dragSource?.column,r=this.dragOverColumn;return!n||!r||n===r||this.isColumnBlocked(r)?o:e===r?o+1:e===n?o-1:o},holdMovedCounts(e,t){if(e===t)return()=>{};let o={[e]:-1,[t]:1},n=!1;for(let[r,s]of Object.entries(o))this.pendingCounts[r]=this.renderedCount(r)+s;return this.pendingMoves++,r=>{if(!n){if(n=!0,r)for(let[s,i]of Object.entries(o))this.pendingCounts[s]-=i;--this.pendingMoves===0&&(this.pendingCounts={})}}},renderedCount(e){let t=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"] .ff-count`);return this.pendingCounts[e]??Number(t?.dataset.total)},handleSortableEnd(e){this.endDrag();let t=e.item,o=e.to,n=e.newDraggableIndex??e.newIndex,r=":scope > [x-sortable-item], :scope > [data-card-id]",s=a=>a.getAttribute("x-sortable-item")||a.getAttribute("data-card-id");if(e.from===o&&e.oldDraggableIndex===e.newDraggableIndex)return;if(n===0){let a=o.querySelector(r);a&&a!==t&&o.insertBefore(t,a)}let i=s(t);if(!i){console.error("Flowforge: Could not determine card ID for move operation");return}let l=o.getAttribute("data-column-id");if(!l){console.error("Flowforge: Target column ID is missing");return}let p=e.from.dataset.laneId??null,C=o.dataset.laneId??null,u=o.querySelectorAll(r),d=Array.prototype.indexOf.call(u,t),b=d>0?s(u[d-1]):null,w=d>=0&&d{this.setCardState(t,!1),f(a===!1),a===!1&&this.revertCard(e)}).catch(()=>{this.setCardState(t,!1),f(!0),this.revertCard(e)})},revertCard({item:e,from:t,oldDraggableIndex:o}){e.remove();let n=t.querySelectorAll(":scope > [x-sortable-item]"),r=n[n.length-1],s=n[o]??(r?r.nextSibling:t.firstChild);t.insertBefore(e,s)},setCardState(e,t){e.toggleAttribute("data-pending",t)},isLaneCollapsed(e){return this.collapsedLanes[e]===!0},toggleLane(e){this.collapsedLanes[e]=!this.isLaneCollapsed(e)},isLoadingColumn(e){return this.isLoading[e]||!1},isColumnFullyLoaded(e){return this.fullyLoaded[e]||!1},handleSmoothScroll(e){this.isLoadingColumn(e)||this.isColumnFullyLoaded(e)||(this.isLoading[e]=!0,this.$wire.loadMoreItems(e).then(()=>setTimeout(()=>this.isLoading[e]=!1,100)).catch(()=>this.isLoading[e]=!1))},handleColumnScroll(e,t){if(this.isColumnFullyLoaded(t))return;let{scrollTop:o,scrollHeight:n,clientHeight:r}=e.target;(o+r)/n>=.8&&!this.isLoadingColumn(t)&&this.handleSmoothScroll(t)}}}export{A as default}; +var A=["--ff-surface","--ff-surface-sunken","--ff-surface-raised","--ff-border","--ff-text","--ff-text-muted","--ff-accent","--ff-accent-tint","--ff-danger","--ff-warning","--ff-radius","--ff-gap","--ff-ease","--ff-duration","--ff-column-width","--ff-tray-bg","--ff-tray-radius","--ff-card-bg","--ff-card-ring","--ff-card-radius","--ff-card-shadow","--ff-card-padding","--ff-drag-tilt","--ff-drag-shadow","--ff-placeholder-border"],f='.ff-column-actions, .fi-dropdown-panel, input, textarea, select, [contenteditable]:not([contenteditable="false"])',h=`.ff-card, .ff-column-header, .ff-add-slot, .ff-add-row, .ff-cards-more, .ff-limit-hint, button, a, ${f}`,m=4,L=e=>{let t=e.querySelector("[data-autofocus]");!t||e.style.display!=="block"||!window.matchMedia("(pointer: fine)").matches||(t.focus({preventScroll:!0}),t.setSelectionRange?.(t.value.length,t.value.length))},p=new WeakSet,c=new WeakSet,C=()=>window.Sortable.active||window.Sortable.dragged;function k(){return{isLoading:{},fullyLoaded:{},dragOverColumn:null,railToggledAt:0,columnMenuPressAt:null,railPressAt:null,dragOverLane:null,dragSource:null,pendingCounts:{},pendingMoves:0,collapsedLanes:{},addingColumn:!1,newColumnName:"",newColumnTouched:!1,addingColumnPending:!1,placeholder:null,stopTrackingPointer:null,init(){this.$wire.$on("kanban-items-loaded",e=>{let{columnId:t,isFullyLoaded:o}=e;o&&(this.fullyLoaded[t]=!0)})},configureSortable(e){if(!e.sortable||e.sortable.options.forceFallback)return;if(C()){this.configureSortableAfterDrag(e);return}let t=window.matchMedia("(prefers-reduced-motion: reduce)").matches;e.sortable.destroy(),e.sortable=window.Sortable.create(e,{draggable:"[x-sortable-item]",handle:"[x-sortable-handle]",dataIdAttr:"x-sortable-item",forceFallback:!0,fallbackTolerance:5,fallbackOnBody:!0,fallbackClass:"",ghostClass:"",delay:150,delayOnTouchOnly:!0,animation:t?0:200,scrollSensitivity:100,scrollSpeed:15,forceAutoScrollFallback:!0,group:{name:e.getAttribute("x-sortable-group"),pull:!0,put:(o,r)=>this.canDrop(o.el,r.el)},onStart:o=>this.startDrag(o),onEnd(o){let{item:r,to:n,oldDraggableIndex:a,newDraggableIndex:l}=o;if(a===l)return;let i=n.querySelectorAll(`:scope > ${this.options.draggable}`)[l-1];i&&n.insertBefore(r,i.nextSibling)}})},configureSortableAfterDrag(e){if(c.has(e))return;c.add(e);let t=()=>{if(C()){requestAnimationFrame(t);return}c.delete(e),e.isConnected&&this.configureSortable(e)};requestAnimationFrame(t)},startDrag(e){this.stopTrackingPointer?.(),this.placeholder=e.item,this.placeholder.setAttribute("data-placeholder",""),this.markGhost(),window.getSelection()?.removeAllRanges(),document.documentElement.classList.add("ff-dragging"),this.dragSource={column:e.from.dataset.columnId,lane:e.from.dataset.laneId??null};let t=o=>this.trackPointer(o);document.addEventListener("pointermove",t,{passive:!0}),document.addEventListener("touchmove",t,{passive:!0}),this.stopTrackingPointer=()=>{document.removeEventListener("pointermove",t),document.removeEventListener("touchmove",t)}},trackPointer(e){if(!window.Sortable.active){this.endDrag();return}this.markGhost();let t=e.touches?.[0]??e,o=document.elementFromPoint(t.clientX,t.clientY),r=o?.closest("[data-column-id]"),n=o?.closest("[data-column-root]");this.dragOverColumn=r?.dataset.columnId??n?.dataset.columnRoot??null,this.dragOverLane=r?.dataset.laneId??null},markGhost(){let e=window.Sortable.ghost;if(!e||e.hasAttribute("data-dragging"))return;e.removeAttribute("data-placeholder"),e.setAttribute("data-dragging",""),e.style.opacity="1";let t=getComputedStyle(this.placeholder);for(let o of A){let r=t.getPropertyValue(o);r!==""&&e.style.setProperty(o,r)}},endDrag(){document.documentElement.classList.remove("ff-dragging"),this.placeholder?.removeAttribute("data-placeholder"),this.placeholder=null,this.stopTrackingPointer?.(),this.stopTrackingPointer=null,this.dragOverColumn=null,this.dragOverLane=null,this.dragSource=null},railPress(e){this.railPressAt={x:e.clientX,y:e.clientY}},toggleColumnCollapse(e,t,o=!1){if(!(e.target.closest(f)||o&&e.detail>1)){if(o){let r=this.railPressAt;if(this.railPressAt=null,r&&Math.hypot(e.clientX-r.x,e.clientY-r.y)>m)return}Date.now()-this.railToggledAt<500||(o&&(this.railToggledAt=Date.now()),this.$wire.toggleBoardColumnCollapse(t))}},collapseFromEmptySpace(e,t){e.target.closest(h)||this.toggleColumnCollapse(e,t)},suppressEmptySpaceSelection(e){e.detail>1&&!e.target.closest(h)&&e.preventDefault()},openNewColumn(){this.addingColumn=!0,this.newColumnTouched=!0,this.$nextTick(()=>{this.$refs.newColumnInput.focus({preventScroll:!0}),requestAnimationFrame(()=>this.$refs.newColumnInput.scrollIntoView({block:"nearest",inline:"nearest"}))})},cancelNewColumn(){this.addingColumn=!1,this.newColumnTouched=!0,this.newColumnName=""},async submitNewColumn(){if(!this.addingColumnPending){this.addingColumnPending=!0,this.newColumnTouched=!0;try{await this.$wire.addBoardColumn(this.newColumnName)}finally{this.addingColumnPending=!1}this.newColumnTouched=!1,this.$root.querySelector(".ff-add-column-error")||this.cancelNewColumn()}},suppressDoubleClickSelection(e){e.detail>1&&!e.target.closest(f)&&e.preventDefault()},initColumnMenu(e){let t=e.closest(".fi-dropdown");if(p.has(t))return;let o=window.Alpine.$data(t),r=o.toggle.bind(o);p.add(t),o.toggle=n=>n?.type==="mousedown"?void 0:r(n)},columnMenuPress(e){this.columnMenuPressAt={x:e.clientX,y:e.clientY}},columnMenuClick(e){let t=this.columnMenuPressAt;if(this.columnMenuPressAt=null,e.detail>1||t&&Math.hypot(e.clientX-t.x,e.clientY-t.y)>m)return;let o=e.currentTarget.closest(".fi-dropdown");window.Alpine.$data(o).toggle(e),requestAnimationFrame(()=>L(o.querySelector(":scope > .fi-dropdown-panel")))},columnDrop(e){return this.dragOverColumn!==e?null:this.isColumnBlocked(e)?"blocked":"active"},cellDrop(e,t){return this.dragOverColumn!==e||this.dragOverLane!==t?null:this.isCellBlocked(e,t)?"blocked":"active"},canDrop(e,t){if(!this.$root.contains(e)||!this.$root.contains(t))return!1;let o=e.dataset.laneId??null,r=t.dataset.laneId??null;return o!==r&&this.$root.dataset.lanesWritable!=="true"?!1:!this.isColumnBlocked(e.dataset.columnId,t.dataset.columnId)},isColumnBlocked(e,t=this.dragSource?.column){if(!e||e===t)return!1;let o=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"]`),r=o?.dataset.columnLimit;return r===void 0||r===""?!1:Number(o.dataset.columnTotal)>=Number(r)},isCellBlocked(e,t){return this.dragSource?t!==this.dragSource.lane&&this.$root.dataset.lanesWritable!=="true"?!0:this.isColumnBlocked(e):!1},displayCount(e,t){let o=this.pendingCounts[e]??t,r=this.dragSource?.column,n=this.dragOverColumn;return!r||!n||r===n||this.isColumnBlocked(n)?o:e===n?o+1:e===r?o-1:o},holdMovedCounts(e,t){if(e===t)return()=>{};let o={[e]:-1,[t]:1},r=!1;for(let[n,a]of Object.entries(o))this.pendingCounts[n]=this.renderedCount(n)+a;return this.pendingMoves++,n=>{if(!r){if(r=!0,n)for(let[a,l]of Object.entries(o))this.pendingCounts[a]-=l;--this.pendingMoves===0&&(this.pendingCounts={})}}},renderedCount(e){let t=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"] .ff-count`);return this.pendingCounts[e]??Number(t?.dataset.total)},handleSortableEnd(e){this.endDrag();let t=e.item,o=e.to,r=e.newDraggableIndex??e.newIndex,n=":scope > [x-sortable-item], :scope > [data-card-id]",a=s=>s.getAttribute("x-sortable-item")||s.getAttribute("data-card-id");if(e.from===o&&e.oldDraggableIndex===e.newDraggableIndex)return;if(r===0){let s=o.querySelector(n);s&&s!==t&&o.insertBefore(t,s)}let l=a(t);if(!l){console.error("Flowforge: Could not determine card ID for move operation");return}let i=o.getAttribute("data-column-id");if(!i){console.error("Flowforge: Target column ID is missing");return}let b=e.from.dataset.laneId??null,w=o.dataset.laneId??null,u=o.querySelectorAll(n),d=Array.prototype.indexOf.call(u,t),S=d>0?a(u[d-1]):null,y=d>=0&&d{this.setCardState(t,!1),g(s===!1),s===!1&&this.revertCard(e)}).catch(()=>{this.setCardState(t,!1),g(!0),this.revertCard(e)})},revertCard({item:e,from:t,oldDraggableIndex:o}){e.remove();let r=t.querySelectorAll(":scope > [x-sortable-item]"),n=r[r.length-1],a=r[o]??(n?n.nextSibling:t.firstChild);t.insertBefore(e,a)},setCardState(e,t){e.toggleAttribute("data-pending",t)},isLaneCollapsed(e){return this.collapsedLanes[e]===!0},toggleLane(e){this.collapsedLanes[e]=!this.isLaneCollapsed(e)},isLoadingColumn(e){return this.isLoading[e]||!1},isColumnFullyLoaded(e){return this.fullyLoaded[e]||!1},handleSmoothScroll(e){this.isLoadingColumn(e)||this.isColumnFullyLoaded(e)||(this.isLoading[e]=!0,this.$wire.loadMoreItems(e).then(()=>setTimeout(()=>this.isLoading[e]=!1,100)).catch(()=>this.isLoading[e]=!1))},handleColumnScroll(e,t){if(this.isColumnFullyLoaded(t))return;let{scrollTop:o,scrollHeight:r,clientHeight:n}=e.target;(o+n)/r>=.8&&!this.isLoadingColumn(t)&&this.handleSmoothScroll(t)}}}export{k as default}; diff --git a/resources/js/flowforge-modern.js b/resources/js/flowforge-modern.js index 92cf579ab..80857eda0 100644 --- a/resources/js/flowforge-modern.js +++ b/resources/js/flowforge-modern.js @@ -28,6 +28,8 @@ const FLOWFORGE_TOKENS = [ const HEADER_GESTURE_IGNORED = '.ff-column-actions, .fi-dropdown-panel, input, textarea, select, [contenteditable]:not([contenteditable="false"])'; +const EMPTY_SPACE_IGNORED = `.ff-card, .ff-column-header, .ff-add-slot, .ff-add-row, .ff-cards-more, .ff-limit-hint, button, a, ${HEADER_GESTURE_IGNORED}`; + const MENU_DRAG_THRESHOLD = 4; const focusMenuField = (panel) => { @@ -270,6 +272,18 @@ export default function flowforgeModern() { this.$wire.toggleBoardColumnCollapse(columnId); }, + collapseFromEmptySpace(event, columnId) { + if (!event.target.closest(EMPTY_SPACE_IGNORED)) { + this.toggleColumnCollapse(event, columnId); + } + }, + + suppressEmptySpaceSelection(event) { + if (event.detail > 1 && !event.target.closest(EMPTY_SPACE_IGNORED)) { + event.preventDefault(); + } + }, + openNewColumn() { this.addingColumn = true; this.newColumnTouched = true; diff --git a/resources/views/modern/livewire/column-header.blade.php b/resources/views/modern/livewire/column-header.blade.php index 1b68eb56b..c22421438 100644 --- a/resources/views/modern/livewire/column-header.blade.php +++ b/resources/views/modern/livewire/column-header.blade.php @@ -21,8 +21,8 @@ $createAction = $createAction?->isVisible() ? $createAction : null; - // x-float reads this before the board's Alpine data loads, so it carries its own logic. The 4px matches the 0.5rem wider panel. - $menuOffset = '({ elements: { reference } }) => { const column = reference.closest(\'[data-column-root]\').getBoundingClientRect(); const trigger = reference.getBoundingClientRect(); return { mainAxis: column.top - 4 - trigger.bottom, crossAxis: column.left - 4 - trigger.left }; }'; + // x-float reads this before the board's Alpine data loads, so it carries its own logic. + $menuOffset = '({ elements: { reference } }) => { const column = reference.closest(\'[data-column-root]\').getBoundingClientRect(); const trigger = reference.getBoundingClientRect(); return { mainAxis: column.top - trigger.bottom, crossAxis: column.left - trigger.left }; }'; @endphp
class(['ff-column-heading']) }}> - @if ($dotColor) - + @if ($dotStyle) + @endif @if ($column['icon'] ?? null) diff --git a/resources/views/modern/livewire/column.blade.php b/resources/views/modern/livewire/column.blade.php index 85c5c4a49..08bc2b69b 100644 --- a/resources/views/modern/livewire/column.blade.php +++ b/resources/views/modern/livewire/column.blade.php @@ -26,6 +26,10 @@ class="ff-column" x-on:pointerdown="railPress($event)" x-on:mousedown="suppressDoubleClickSelection($event)" @endif + @if (! $isCollapsed && ($column['canToggleCollapse'] ?? false)) + x-on:dblclick="collapseFromEmptySpace($event, @js((string) $columnId))" + x-on:mousedown="suppressEmptySpaceSelection($event)" + @endif x-bind:data-drop="columnDrop(@js((string) $columnId))" > @unless ($isCollapsed) diff --git a/resources/views/modern/livewire/lanes.blade.php b/resources/views/modern/livewire/lanes.blade.php index b709d9315..c6fbd9fa1 100644 --- a/resources/views/modern/livewire/lanes.blade.php +++ b/resources/views/modern/livewire/lanes.blade.php @@ -90,6 +90,10 @@ class="ff-lane-toggle"
and($page->script("document.querySelector('{$root}').hasAttribute('data-collapsed')"))->toBeFalse(); })->with(['/modern/test-menu-board', '/modern/test-menu-static-board']); +test('double clicking a column\'s empty space collapses it and a card leaves it open', function () { + [, , , $card] = boardSeed(); + $page = boardPage('/modern/test-menu-board'); + $pointer = Pointer::on($page); + $root = '[data-column-root="in_progress"]'; + + $pointer->doubleClick(boardCard($card), 120)->wait(600); + + expect($page->script("document.querySelector('{$root}').hasAttribute('data-collapsed')"))->toBeFalse(); + + $pointer->doubleClick("{$root} .ff-cards", 120); + $pointer->untilScript("document.querySelector('{$root}').hasAttribute('data-collapsed')"); + + $pointer->doubleClick($root, 120)->wait(800); + + expect($page->script("document.querySelector('{$root}').hasAttribute('data-collapsed')"))->toBeFalse(); +}); + +test('double clicking an empty lane cell collapses its column', function () { + boardSeed('high'); + $page = boardPage('/modern/test-collapsible-grouped-board?groupBy=priority'); + $pointer = Pointer::on($page); + + $pointer->doubleClick('.ff-cell-cards[data-column-id="in_progress"][data-lane-id="high"]', 120); + $pointer->untilScript("document.querySelector('.ff-lanes-heads [data-column-root=\"in_progress\"]').hasAttribute('data-collapsed')"); +}); + test('a header click opens the menu over its column with the marked field focused', function () { boardSeed(); $page = boardPage('/modern/test-menu-board'); @@ -924,7 +951,7 @@ function boardTraySampler(int $budgetMilliseconds): string })() JS); - expect($geometry)->toBe([4, 4, 8]) + expect($geometry)->toBe([0, 0, 0]) ->and($page->script('document.activeElement.selectionStart'))->toBe(7); }); diff --git a/tests/Fixtures/Modern/TestBoard.php b/tests/Fixtures/Modern/TestBoard.php index c1d9af654..35efd27d7 100644 --- a/tests/Fixtures/Modern/TestBoard.php +++ b/tests/Fixtures/Modern/TestBoard.php @@ -67,6 +67,8 @@ class TestBoard extends BoardPage public bool $htmlLabel = false; + public bool $hexCompleted = false; + public ?int $todoLimit = null; public ?string $denyMovesFor = null; @@ -152,7 +154,7 @@ public function board(Board $board): Board Column::make('hidden_column')->visible(fn () => $this->showAllColumns && ! $this->hideEverything)->label('Hidden Column'), Column::make('archived')->label('Archived Column')->hidden(true), Column::make('in_progress')->label($this->htmlLabel ? new HtmlString('In Progress') : 'In Progress')->color('blue')->visible(fn () => ! $this->hideEverything), - Column::make('completed')->label('Completed')->color('green')->visible(fn () => ! $this->hideEverything), + Column::make('completed')->label('Completed')->color($this->hexCompleted ? '#FF5454' : 'green')->visible(fn () => ! $this->hideEverything), ...array_map(fn (string $name): Column => Column::make($name)->label($name), $this->addedColumns), ]); } diff --git a/tests/Modern/Feature/ColumnHeaderMenuTest.php b/tests/Modern/Feature/ColumnHeaderMenuTest.php index f76eea77d..5a9dcb344 100644 --- a/tests/Modern/Feature/ColumnHeaderMenuTest.php +++ b/tests/Modern/Feature/ColumnHeaderMenuTest.php @@ -46,7 +46,8 @@ function menuHasClass(string $class): string test('a collapsible header with a menu leaves the double click to the menu', function () { $html = Livewire::test(TestBoard::class, ['withHeaderMenu' => true, 'collapsible' => true])->html(); - expect($html)->not->toContain('x-on:dblclick'); + expect($html)->not->toMatch('/]*class="ff-column-header"[^>]*x-on:dblclick/') + ->and($html)->toMatch('/]*data-column-root="todo"[^>]*x-on:dblclick="collapseFromEmptySpace/'); }); test('the trigger is a div with the button role so a header drag handle does not filter it out', function () { diff --git a/tests/Modern/Feature/ColumnLayoutTest.php b/tests/Modern/Feature/ColumnLayoutTest.php index bf77d884b..87315e796 100644 --- a/tests/Modern/Feature/ColumnLayoutTest.php +++ b/tests/Modern/Feature/ColumnLayoutTest.php @@ -37,6 +37,12 @@ Livewire::test(TestBoard::class)->assertSeeHtml('ff-column-dot'); }); +test('a hex column color draws its dot in that exact color', function () { + $html = Livewire::test(TestBoard::class, ['hexCompleted' => true])->html(); + + expect($html)->toContain('style="--color-500:#ff5454"'); +}); + test('the header sits above the tray, outside it', function () { $html = Livewire::test(TestBoard::class)->html(); From c2a33696f2d70f01b605ccf8c0b7b12d6cf042f6 Mon Sep 17 00:00:00 2001 From: Manuk Date: Sat, 14 Nov 2026 23:22:07 +0400 Subject: [PATCH 19/34] feat(columns): let a collapse all rail expand through the host --- docs/content/2.essentials/2.customization.md | 7 ++--- docs/content/2.essentials/4.api-reference.md | 2 +- .../skills/flowforge-development/SKILL.md | 2 +- src/Board.php | 6 ++--- tests/Modern/Feature/CollapsedColumnsTest.php | 27 +++++++++---------- 5 files changed, 21 insertions(+), 23 deletions(-) diff --git a/docs/content/2.essentials/2.customization.md b/docs/content/2.essentials/2.customization.md index 2ef10e116..bf5d3b46c 100644 --- a/docs/content/2.essentials/2.customization.md +++ b/docs/content/2.essentials/2.customization.md @@ -329,9 +329,10 @@ store it where `collapsedColumns()` reads it: The closure never runs for an unknown or hidden column id. A double-click on the header's action buttons does not toggle the column. -Only a column listed in `collapsedColumns()` can be expanded from its rail. A column that -`collapseAllColumns()` or `collapseEmptyColumns()` collapses has no click binding, and a toggle -for it never reaches your closure. Flowforge rebuilds the board after your closure runs. Still, pass +A rail collapsed by `collapsedColumns()` or `collapseAllColumns()` expands on a click. Under +`collapseAllColumns()` your closure gets the column id and `false`, so turn collapse all off and list +the other columns as collapsed. A column that `collapseEmptyColumns()` collapses has no click +binding, and a toggle for it never reaches your closure. Flowforge rebuilds the board after your closure runs. Still, pass a value your page changes during a request as a closure, as above, so every read sees the new state. ### Open a menu from the column header diff --git a/docs/content/2.essentials/4.api-reference.md b/docs/content/2.essentials/4.api-reference.md index 475735ab6..ed0afdb89 100644 --- a/docs/content/2.essentials/4.api-reference.md +++ b/docs/content/2.essentials/4.api-reference.md @@ -30,7 +30,7 @@ navigation: | `collapseEmptyColumns(bool)` | Collapse columns holding no cards into a rail | | | `collapsedColumns(array\|Closure)` | Collapse the listed column ids into a rail. Unknown and hidden ids are ignored | | | `collapseAllColumns(bool\|Closure)` | Collapse every visible column into a rail | | -| `collapsibleColumns(?Closure)` | Let users toggle a column by double-clicking its empty space or its header (one without a `columnHeaderMenu()`), or clicking its rail. Only columns listed in `collapsedColumns()` expand from the rail. The closure receives `string $columnId` and `bool $collapsed` (the new state) | | +| `collapsibleColumns(?Closure)` | Let users toggle a column by double-clicking its empty space or its header (one without a `columnHeaderMenu()`), or clicking its rail. Columns from `collapsedColumns()` or `collapseAllColumns()` expand from the rail. The closure receives `string $columnId` and `bool $collapsed` (the new state) | | | `columnHeaderMenu(?Closure)` | Turn the column heading into a menu trigger. The closure receives `array $column` and returns an `Htmlable` block, or `null` for none. The panel holds the block, then the column actions as list items | | | `addColumnUsing(?Closure)` | Show an add column tile after the last column. The closure receives `string $name`, the trimmed name the user typed. Throw a `ValidationException` to show its first message under the input. Leave it unset to hide the tile | | | `addColumnLabel(string\|Closure\|null)` | The tile's tooltip and input label. Defaults to "Add column" | | diff --git a/resources/boost/skills/flowforge-development/SKILL.md b/resources/boost/skills/flowforge-development/SKILL.md index b56bb2b45..9daa078da 100644 --- a/resources/boost/skills/flowforge-development/SKILL.md +++ b/resources/boost/skills/flowforge-development/SKILL.md @@ -365,7 +365,7 @@ A "Group by" select appears and the choice lives in `?groupBy=`. `lanes()` retur ### Column controls -The host owns the state and Flowforge renders it. `collapsedColumns(fn () => [...])` and `collapseAllColumns(fn () => ...)` collapse columns. `collapsibleColumns(fn (string $columnId, bool $collapsed) => ...)` lets a double-click in a column's empty space, or on a header without a menu, collapse it and a click on its rail expand it. Only columns listed in `collapsedColumns()` expand by click. `columnHeaderMenu(fn (array $column): ?Htmlable => ...)` turns the header into a menu holding the host block above the column actions. It opens over its column, takes the header's clicks, and focuses a `data-autofocus` field on a mouse click. `addColumnUsing(fn (string $name) => ...)` with `addColumnLabel()` and `addColumnPlaceholder()` adds a tile after the last column; throw a `ValidationException` to show a message under its input. Pass any value the page changes during a request as a closure, because the board is built before the action runs. +The host owns the state and Flowforge renders it. `collapsedColumns(fn () => [...])` and `collapseAllColumns(fn () => ...)` collapse columns. `collapsibleColumns(fn (string $columnId, bool $collapsed) => ...)` lets a double-click in a column's empty space, or on a header without a menu, collapse it and a click on its rail expand it. Columns from `collapsedColumns()` or `collapseAllColumns()` expand by click, the latter handing the closure `false`. `columnHeaderMenu(fn (array $column): ?Htmlable => ...)` turns the header into a menu holding the host block above the column actions. It opens over its column, takes the header's clicks, and focuses a `data-autofocus` field on a mouse click. `addColumnUsing(fn (string $name) => ...)` with `addColumnLabel()` and `addColumnPlaceholder()` adds a tile after the last column; throw a `ValidationException` to show a message under its input. Pass any value the page changes during a request as a closure, because the board is built before the action runs. ### Styling a Modern Board diff --git a/src/Board.php b/src/Board.php index 6c8b7da64..f114ec5aa 100644 --- a/src/Board.php +++ b/src/Board.php @@ -163,15 +163,15 @@ protected function makeCollapseResolver(array $allCounts): Closure && array_sum(array_map(fn (Column $column): int => $allCounts[$column->getName()] ?? 0, $this->getColumns())) > 0; return function (string $columnId) use ($listed, $visible, $collapseAll, $collapseEmpty, $allCounts): array { - $byRule = $collapseAll || ($collapseEmpty && ($allCounts[$columnId] ?? 0) === 0); + $byEmptyRule = ! $collapseAll && $collapseEmpty && ($allCounts[$columnId] ?? 0) === 0; $isListed = in_array($columnId, $listed, true); - $collapsed = $byRule || $isListed; + $collapsed = $collapseAll || $byEmptyRule || $isListed; return [ 'collapsed' => $collapsed, 'toggleable' => $this->isColumnCollapsible() && in_array($columnId, $visible, true) - && (! $collapsed || ($isListed && ! $byRule)), + && ! $byEmptyRule, ]; }; } diff --git a/tests/Modern/Feature/CollapsedColumnsTest.php b/tests/Modern/Feature/CollapsedColumnsTest.php index 820175805..eaa156bfd 100644 --- a/tests/Modern/Feature/CollapsedColumnsTest.php +++ b/tests/Modern/Feature/CollapsedColumnsTest.php @@ -128,26 +128,23 @@ ->and($component->html())->toMatch('/]*data-column-root="in_progress"[^>]*data-collapsed/'); }); - test('toggling under collapse all is ignored and every column stays collapsed', function () { - $component = Livewire::test(TestBoard::class, ['collapsible' => true, 'collapseAll' => true, 'collapsedIds' => ['todo']]) - ->call('toggleBoardColumnCollapse', 'todo') - ->call('toggleBoardColumnCollapse', 'in_progress'); - - expect($component->get('toggled'))->toBe([]) - ->and(substr_count($component->html(), 'data-collapsed'))->toBe(3); - }); - - test('a rail collapsed only by a rule binds no click', function () { + test('a rail collapsed by the empty rule binds no click', function () { Task::factory()->todo()->create(['title' => 'Only Task']); $empty = Livewire::test(TestBoard::class, ['collapsible' => true, 'collapseEmpty' => true])->html(); - $all = Livewire::test(TestBoard::class, ['collapsible' => true, 'collapseAll' => true, 'collapsedIds' => ['todo']])->html(); expect($empty)->toContain('data-collapsed') - ->and($empty)->not->toMatch('/]*data-column-root="in_progress"[^>]*x-on:click/') - ->and($all)->toContain('data-collapsed') - ->and($all)->not->toMatch('/]*data-column-root="[a-z_]+"[^>]*x-on:click/') - ->and($all)->not->toContain('x-on:dblclick'); + ->and($empty)->not->toMatch('/]*data-column-root="in_progress"[^>]*x-on:click/'); + }); + + test('a rail collapsed by collapse all binds the click and hands the host an expand', function () { + $component = Livewire::test(TestBoard::class, ['collapsible' => true, 'collapseAll' => true]); + + expect($component->html())->toMatch('/]*data-column-root="in_progress"[^>]*data-collapsed[^>]*x-on:click/'); + + $component->call('toggleBoardColumnCollapse', 'in_progress'); + + expect($component->get('toggled'))->toBe([['in_progress', false]]); }); test('a toggle shows the new state in the same response for a plain array of ids', function () { From dd5282615a61d14677e881a37c9924dd30434203 Mon Sep 17 00:00:00 2001 From: Manuk Date: Sat, 14 Nov 2026 23:28:08 +0400 Subject: [PATCH 20/34] feat(columns): open a new column as a ghost column with its name form, and close it on an outside click --- resources/css/flowforge-modern.css | 98 ++++++++++++++----- .../modern/livewire/add-column.blade.php | 49 +++++----- tests/Browser/ModernBoardTest.php | 47 +++++++-- 3 files changed, 142 insertions(+), 52 deletions(-) diff --git a/resources/css/flowforge-modern.css b/resources/css/flowforge-modern.css index a18f92a49..742baf968 100644 --- a/resources/css/flowforge-modern.css +++ b/resources/css/flowforge-modern.css @@ -86,14 +86,16 @@ } .ff-tray, - .ff-cell { + .ff-cell, + .ff-add-column-ghost { --_accent-tint: var(--ff-accent-tint, var(--primary-50)); --_tray-bg: var(--ff-tray-bg, var(--ff-surface-sunken, var(--gray-100))); --_tray-radius: var(--ff-tray-radius, calc(var(--ff-radius, 0.75rem) + 0.25rem)); } :where(.dark) .ff-tray, - :where(.dark) .ff-cell { + :where(.dark) .ff-cell, + :where(.dark) .ff-add-column-ghost { --_accent-tint: var(--ff-accent-tint, color-mix(in oklab, var(--primary-500) 10%, transparent)); --_tray-bg: var(--ff-tray-bg, var(--ff-surface-sunken, color-mix(in oklab, #fff 5%, transparent))); } @@ -676,10 +678,10 @@ --_tile-bg: color-mix(in oklab, var(--gray-950) 5%, transparent); --_tile-bg-hover: color-mix(in oklab, var(--gray-950) 9%, transparent); position: relative; + display: flex; flex-shrink: 0; - align-self: start; - width: var(--_collapsed-width); - height: var(--_collapsed-width); + align-items: flex-start; + gap: var(--_gap); } :where(.dark) .ff-add-column { @@ -689,10 +691,11 @@ .ff-add-column-button { display: flex; + flex-shrink: 0; align-items: center; justify-content: center; - width: 100%; - height: 100%; + width: var(--_collapsed-width); + height: var(--_collapsed-width); color: var(--_text-muted); background-color: var(--_tile-bg); border-radius: 0.75rem; @@ -707,32 +710,83 @@ background-color: var(--_tile-bg-hover); } - .ff-add-column[data-adding] .ff-add-column-button { - visibility: hidden; + .ff-add-column-ghost { + position: relative; + flex-shrink: 0; + align-self: stretch; + width: var(--_column-width); + background-color: var(--_tray-bg); + border-radius: var(--_tray-radius); } - .ff-add-column-form { + .ff-lanes-heads .ff-add-column-ghost { position: absolute; inset-block-start: 0; inset-inline-start: 0; z-index: 20; - width: var(--_column-width); + background-color: transparent; + } + + .ff-add-column-form { + position: absolute; + inset-block-start: 0; + inset-inline: 0; + z-index: 20; + padding: 0.75rem; + background-color: var(--ff-surface-raised, #fff); + border-radius: 0.75rem; + box-shadow: + 0 0 0 1px color-mix(in oklab, var(--gray-950) 5%, transparent), + 0 10px 15px -3px rgb(0 0 0 / 0.1), + 0 4px 6px -4px rgb(0 0 0 / 0.1); + } + + :where(.dark) .ff-add-column-form { + background-color: var(--ff-surface-raised, var(--gray-900)); + box-shadow: + 0 0 0 1px color-mix(in oklab, #fff 10%, transparent), + 0 10px 15px -3px rgb(0 0 0 / 0.3); + } + + .ff-add-column-field { + display: flex; + align-items: center; + gap: 0.625rem; + height: 2.25rem; + padding: 0 0.75rem; + border: 1px solid var(--gray-200); + border-radius: 0.625rem; + transition: border-color var(--_duration) var(--_ease); + } + + :where(.dark) .ff-add-column-field { + border-color: color-mix(in oklab, #fff 10%, transparent); + } + + .ff-add-column-field:focus-within { + border-color: var(--_accent); + } + + .ff-add-column-dot { + flex-shrink: 0; + width: 0.875rem; + height: 0.875rem; + background-color: var(--gray-400); + border-radius: 9999px; } .ff-add-column-input { - width: 100%; - padding: 0.5rem 0.75rem; + flex: 1 1 auto; + min-width: 0; + padding: 0; font-size: 0.875rem; line-height: 1.25rem; + font-weight: 600; color: var(--_text); - background-color: var(--ff-surface-raised, #fff); - border: 1px solid var(--_accent); - border-radius: 0.5rem; + background-color: transparent; + border: 0; outline: none; - } - - :where(.dark) .ff-add-column-input { - background-color: var(--ff-surface-raised, var(--gray-900)); + box-shadow: none; } .ff-add-column-error { @@ -806,8 +860,8 @@ height: 1.75rem; } - .ff-lanes-heads .ff-add-column-input { - padding-block: 0.1875rem; + .ff-lanes-heads .ff-add-column-button { + height: 100%; } .ff-lanes-heads:has(> .ff-add-column) { diff --git a/resources/views/modern/livewire/add-column.blade.php b/resources/views/modern/livewire/add-column.blade.php index 5e9497056..35c3b5601 100644 --- a/resources/views/modern/livewire/add-column.blade.php +++ b/resources/views/modern/livewire/add-column.blade.php @@ -5,6 +5,33 @@ @endphp
+
+
+
+ + + +
+ + @error('boardNewColumn') +

{{ $message }}

+ @enderror +
+
+ - -
- - - @error('boardNewColumn') -

{{ $message }}

- @enderror -
diff --git a/tests/Browser/ModernBoardTest.php b/tests/Browser/ModernBoardTest.php index 97319d4aa..13b53de7d 100644 --- a/tests/Browser/ModernBoardTest.php +++ b/tests/Browser/ModernBoardTest.php @@ -1158,28 +1158,59 @@ function boardTraySampler(int $budgetMilliseconds): string ->and(abs($box[2]))->toBeLessThan(1.5); }); -test('the add column tile and its input sit inside the painted lane heads box', function () { +test('the add column tile sits in the lane heads and its form opens on top of the lanes', function () { boardSeed('high'); $page = boardPage('/modern/test-add-column-grouped-board?groupBy=priority'); $pointer = Pointer::on($page); - $inside = <<<'JS' + $tile = <<<'JS' (() => { const heads = document.querySelector('.ff-lanes-heads').getBoundingClientRect(); const column = document.querySelector('.ff-lanes-heads .ff-column').getBoundingClientRect(); - const target = document.querySelector('.ff-add-column-input')?.offsetParent - ? document.querySelector('.ff-add-column-input').getBoundingClientRect() - : document.querySelector('.ff-add-column-button').getBoundingClientRect(); + const tile = document.querySelector('.ff-add-column-button').getBoundingClientRect(); - return [target.left >= heads.left - 0.5, target.right <= heads.right + 0.5, target.top >= heads.top - 0.5, target.bottom <= heads.bottom + 0.5, Math.abs(document.querySelector('.ff-add-column-button').getBoundingClientRect().top - column.top) < 1.5]; + return [tile.left >= heads.left - 0.5, tile.right <= heads.right + 0.5, tile.top >= heads.top - 0.5, tile.bottom <= heads.bottom + 0.5, Math.abs(tile.top - column.top) < 1.5]; })() JS; - expect($page->script($inside))->toBe([true, true, true, true, true]); + expect($page->script($tile))->toBe([true, true, true, true, true]); $pointer->click('.ff-add-column-button'); $pointer->untilScript("document.activeElement === document.querySelector('.ff-add-column-input')"); - expect($page->script($inside))->toBe([true, true, true, true, true]); + $reachable = <<<'JS' + (() => { + const input = document.querySelector('.ff-add-column-input').getBoundingClientRect(); + + return document.elementFromPoint(input.left + input.width / 2, input.top + input.height / 2) === document.querySelector('.ff-add-column-input'); + })() + JS; + + expect($page->script($reachable))->toBeTrue(); +}); + +test('the add column form opens as a column before the tile and an outside click closes it', function () { + boardSeed(); + $page = boardPage('/modern/test-add-column-board'); + $pointer = Pointer::on($page); + + $pointer->click('.ff-add-column-button'); + $pointer->untilScript("document.activeElement === document.querySelector('.ff-add-column-input')"); + + $geometry = $page->script(<<<'JS' + (() => { + const column = document.querySelector('.ff-columns > .ff-column').getBoundingClientRect(); + const ghost = document.querySelector('.ff-add-column-ghost').getBoundingClientRect(); + const tile = document.querySelector('.ff-add-column-button').getBoundingClientRect(); + + return [Math.round(ghost.width) === Math.round(column.width), Math.abs(ghost.height - column.height) < 1.5, tile.left > ghost.right, getComputedStyle(document.querySelector('.ff-add-column-button')).visibility]; + })() + JS); + + expect($geometry)->toBe([true, true, true, 'visible']); + + $page->script("document.querySelector('.ff-add-column-input').value = 'Draft'"); + $pointer->click('[data-column-root="todo"] .ff-column-title'); + $pointer->untilScript("getComputedStyle(document.querySelector('.ff-add-column-ghost')).display === 'none'"); }); test('the add column tile leaves the lane heads row height unchanged', function () { From 223121fd5a21e905ea9d015c31440c92b71f2d04 Mon Sep 17 00:00:00 2001 From: Manuk Date: Sat, 14 Nov 2026 23:46:07 +0400 Subject: [PATCH 21/34] feat(columns): tell a click from a double-click on a collapse all rail --- docs/content/2.essentials/2.customization.md | 5 +++-- .../skills/flowforge-development/SKILL.md | 2 +- resources/dist/flowforge-modern.js | 2 +- resources/js/flowforge-modern.js | 22 +++++++++++++++++++ .../views/modern/livewire/column.blade.php | 6 ++++- .../views/modern/livewire/lanes.blade.php | 6 ++++- src/Board.php | 6 +++-- src/Concerns/HasColumnControls.php | 3 ++- src/Modern/Concerns/InteractsWithBoard.php | 4 ++-- tests/Fixtures/Modern/TestBoard.php | 5 ++++- tests/Modern/Feature/CollapsedColumnsTest.php | 7 ++++-- 11 files changed, 54 insertions(+), 14 deletions(-) diff --git a/docs/content/2.essentials/2.customization.md b/docs/content/2.essentials/2.customization.md index bf5d3b46c..41bef19f1 100644 --- a/docs/content/2.essentials/2.customization.md +++ b/docs/content/2.essentials/2.customization.md @@ -330,8 +330,9 @@ The closure never runs for an unknown or hidden column id. A double-click on the buttons does not toggle the column. A rail collapsed by `collapsedColumns()` or `collapseAllColumns()` expands on a click. Under -`collapseAllColumns()` your closure gets the column id and `false`, so turn collapse all off and list -the other columns as collapsed. A column that `collapseEmptyColumns()` collapses has no click +`collapseAllColumns()` a click waits 300ms for a second one. A single click calls your closure with +`$alone` false, so turn collapse all off. A double-click passes `$alone` true, so open that column +alone and list the others as collapsed. The closure may leave `$alone` out of its parameters. A column that `collapseEmptyColumns()` collapses has no click binding, and a toggle for it never reaches your closure. Flowforge rebuilds the board after your closure runs. Still, pass a value your page changes during a request as a closure, as above, so every read sees the new state. diff --git a/resources/boost/skills/flowforge-development/SKILL.md b/resources/boost/skills/flowforge-development/SKILL.md index 9daa078da..8a240815d 100644 --- a/resources/boost/skills/flowforge-development/SKILL.md +++ b/resources/boost/skills/flowforge-development/SKILL.md @@ -365,7 +365,7 @@ A "Group by" select appears and the choice lives in `?groupBy=`. `lanes()` retur ### Column controls -The host owns the state and Flowforge renders it. `collapsedColumns(fn () => [...])` and `collapseAllColumns(fn () => ...)` collapse columns. `collapsibleColumns(fn (string $columnId, bool $collapsed) => ...)` lets a double-click in a column's empty space, or on a header without a menu, collapse it and a click on its rail expand it. Columns from `collapsedColumns()` or `collapseAllColumns()` expand by click, the latter handing the closure `false`. `columnHeaderMenu(fn (array $column): ?Htmlable => ...)` turns the header into a menu holding the host block above the column actions. It opens over its column, takes the header's clicks, and focuses a `data-autofocus` field on a mouse click. `addColumnUsing(fn (string $name) => ...)` with `addColumnLabel()` and `addColumnPlaceholder()` adds a tile after the last column; throw a `ValidationException` to show a message under its input. Pass any value the page changes during a request as a closure, because the board is built before the action runs. +The host owns the state and Flowforge renders it. `collapsedColumns(fn () => [...])` and `collapseAllColumns(fn () => ...)` collapse columns. `collapsibleColumns(fn (string $columnId, bool $collapsed) => ...)` lets a double-click in a column's empty space, or on a header without a menu, collapse it and a click on its rail expand it. Columns from `collapsedColumns()` or `collapseAllColumns()` expand by click. Under collapse all the closure also gets `bool $alone`: false for a click, true for a double-click. `columnHeaderMenu(fn (array $column): ?Htmlable => ...)` turns the header into a menu holding the host block above the column actions. It opens over its column, takes the header's clicks, and focuses a `data-autofocus` field on a mouse click. `addColumnUsing(fn (string $name) => ...)` with `addColumnLabel()` and `addColumnPlaceholder()` adds a tile after the last column; throw a `ValidationException` to show a message under its input. Pass any value the page changes during a request as a closure, because the board is built before the action runs. ### Styling a Modern Board diff --git a/resources/dist/flowforge-modern.js b/resources/dist/flowforge-modern.js index 850453c51..63fb8a45f 100644 --- a/resources/dist/flowforge-modern.js +++ b/resources/dist/flowforge-modern.js @@ -1 +1 @@ -var A=["--ff-surface","--ff-surface-sunken","--ff-surface-raised","--ff-border","--ff-text","--ff-text-muted","--ff-accent","--ff-accent-tint","--ff-danger","--ff-warning","--ff-radius","--ff-gap","--ff-ease","--ff-duration","--ff-column-width","--ff-tray-bg","--ff-tray-radius","--ff-card-bg","--ff-card-ring","--ff-card-radius","--ff-card-shadow","--ff-card-padding","--ff-drag-tilt","--ff-drag-shadow","--ff-placeholder-border"],f='.ff-column-actions, .fi-dropdown-panel, input, textarea, select, [contenteditable]:not([contenteditable="false"])',h=`.ff-card, .ff-column-header, .ff-add-slot, .ff-add-row, .ff-cards-more, .ff-limit-hint, button, a, ${f}`,m=4,L=e=>{let t=e.querySelector("[data-autofocus]");!t||e.style.display!=="block"||!window.matchMedia("(pointer: fine)").matches||(t.focus({preventScroll:!0}),t.setSelectionRange?.(t.value.length,t.value.length))},p=new WeakSet,c=new WeakSet,C=()=>window.Sortable.active||window.Sortable.dragged;function k(){return{isLoading:{},fullyLoaded:{},dragOverColumn:null,railToggledAt:0,columnMenuPressAt:null,railPressAt:null,dragOverLane:null,dragSource:null,pendingCounts:{},pendingMoves:0,collapsedLanes:{},addingColumn:!1,newColumnName:"",newColumnTouched:!1,addingColumnPending:!1,placeholder:null,stopTrackingPointer:null,init(){this.$wire.$on("kanban-items-loaded",e=>{let{columnId:t,isFullyLoaded:o}=e;o&&(this.fullyLoaded[t]=!0)})},configureSortable(e){if(!e.sortable||e.sortable.options.forceFallback)return;if(C()){this.configureSortableAfterDrag(e);return}let t=window.matchMedia("(prefers-reduced-motion: reduce)").matches;e.sortable.destroy(),e.sortable=window.Sortable.create(e,{draggable:"[x-sortable-item]",handle:"[x-sortable-handle]",dataIdAttr:"x-sortable-item",forceFallback:!0,fallbackTolerance:5,fallbackOnBody:!0,fallbackClass:"",ghostClass:"",delay:150,delayOnTouchOnly:!0,animation:t?0:200,scrollSensitivity:100,scrollSpeed:15,forceAutoScrollFallback:!0,group:{name:e.getAttribute("x-sortable-group"),pull:!0,put:(o,r)=>this.canDrop(o.el,r.el)},onStart:o=>this.startDrag(o),onEnd(o){let{item:r,to:n,oldDraggableIndex:a,newDraggableIndex:l}=o;if(a===l)return;let i=n.querySelectorAll(`:scope > ${this.options.draggable}`)[l-1];i&&n.insertBefore(r,i.nextSibling)}})},configureSortableAfterDrag(e){if(c.has(e))return;c.add(e);let t=()=>{if(C()){requestAnimationFrame(t);return}c.delete(e),e.isConnected&&this.configureSortable(e)};requestAnimationFrame(t)},startDrag(e){this.stopTrackingPointer?.(),this.placeholder=e.item,this.placeholder.setAttribute("data-placeholder",""),this.markGhost(),window.getSelection()?.removeAllRanges(),document.documentElement.classList.add("ff-dragging"),this.dragSource={column:e.from.dataset.columnId,lane:e.from.dataset.laneId??null};let t=o=>this.trackPointer(o);document.addEventListener("pointermove",t,{passive:!0}),document.addEventListener("touchmove",t,{passive:!0}),this.stopTrackingPointer=()=>{document.removeEventListener("pointermove",t),document.removeEventListener("touchmove",t)}},trackPointer(e){if(!window.Sortable.active){this.endDrag();return}this.markGhost();let t=e.touches?.[0]??e,o=document.elementFromPoint(t.clientX,t.clientY),r=o?.closest("[data-column-id]"),n=o?.closest("[data-column-root]");this.dragOverColumn=r?.dataset.columnId??n?.dataset.columnRoot??null,this.dragOverLane=r?.dataset.laneId??null},markGhost(){let e=window.Sortable.ghost;if(!e||e.hasAttribute("data-dragging"))return;e.removeAttribute("data-placeholder"),e.setAttribute("data-dragging",""),e.style.opacity="1";let t=getComputedStyle(this.placeholder);for(let o of A){let r=t.getPropertyValue(o);r!==""&&e.style.setProperty(o,r)}},endDrag(){document.documentElement.classList.remove("ff-dragging"),this.placeholder?.removeAttribute("data-placeholder"),this.placeholder=null,this.stopTrackingPointer?.(),this.stopTrackingPointer=null,this.dragOverColumn=null,this.dragOverLane=null,this.dragSource=null},railPress(e){this.railPressAt={x:e.clientX,y:e.clientY}},toggleColumnCollapse(e,t,o=!1){if(!(e.target.closest(f)||o&&e.detail>1)){if(o){let r=this.railPressAt;if(this.railPressAt=null,r&&Math.hypot(e.clientX-r.x,e.clientY-r.y)>m)return}Date.now()-this.railToggledAt<500||(o&&(this.railToggledAt=Date.now()),this.$wire.toggleBoardColumnCollapse(t))}},collapseFromEmptySpace(e,t){e.target.closest(h)||this.toggleColumnCollapse(e,t)},suppressEmptySpaceSelection(e){e.detail>1&&!e.target.closest(h)&&e.preventDefault()},openNewColumn(){this.addingColumn=!0,this.newColumnTouched=!0,this.$nextTick(()=>{this.$refs.newColumnInput.focus({preventScroll:!0}),requestAnimationFrame(()=>this.$refs.newColumnInput.scrollIntoView({block:"nearest",inline:"nearest"}))})},cancelNewColumn(){this.addingColumn=!1,this.newColumnTouched=!0,this.newColumnName=""},async submitNewColumn(){if(!this.addingColumnPending){this.addingColumnPending=!0,this.newColumnTouched=!0;try{await this.$wire.addBoardColumn(this.newColumnName)}finally{this.addingColumnPending=!1}this.newColumnTouched=!1,this.$root.querySelector(".ff-add-column-error")||this.cancelNewColumn()}},suppressDoubleClickSelection(e){e.detail>1&&!e.target.closest(f)&&e.preventDefault()},initColumnMenu(e){let t=e.closest(".fi-dropdown");if(p.has(t))return;let o=window.Alpine.$data(t),r=o.toggle.bind(o);p.add(t),o.toggle=n=>n?.type==="mousedown"?void 0:r(n)},columnMenuPress(e){this.columnMenuPressAt={x:e.clientX,y:e.clientY}},columnMenuClick(e){let t=this.columnMenuPressAt;if(this.columnMenuPressAt=null,e.detail>1||t&&Math.hypot(e.clientX-t.x,e.clientY-t.y)>m)return;let o=e.currentTarget.closest(".fi-dropdown");window.Alpine.$data(o).toggle(e),requestAnimationFrame(()=>L(o.querySelector(":scope > .fi-dropdown-panel")))},columnDrop(e){return this.dragOverColumn!==e?null:this.isColumnBlocked(e)?"blocked":"active"},cellDrop(e,t){return this.dragOverColumn!==e||this.dragOverLane!==t?null:this.isCellBlocked(e,t)?"blocked":"active"},canDrop(e,t){if(!this.$root.contains(e)||!this.$root.contains(t))return!1;let o=e.dataset.laneId??null,r=t.dataset.laneId??null;return o!==r&&this.$root.dataset.lanesWritable!=="true"?!1:!this.isColumnBlocked(e.dataset.columnId,t.dataset.columnId)},isColumnBlocked(e,t=this.dragSource?.column){if(!e||e===t)return!1;let o=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"]`),r=o?.dataset.columnLimit;return r===void 0||r===""?!1:Number(o.dataset.columnTotal)>=Number(r)},isCellBlocked(e,t){return this.dragSource?t!==this.dragSource.lane&&this.$root.dataset.lanesWritable!=="true"?!0:this.isColumnBlocked(e):!1},displayCount(e,t){let o=this.pendingCounts[e]??t,r=this.dragSource?.column,n=this.dragOverColumn;return!r||!n||r===n||this.isColumnBlocked(n)?o:e===n?o+1:e===r?o-1:o},holdMovedCounts(e,t){if(e===t)return()=>{};let o={[e]:-1,[t]:1},r=!1;for(let[n,a]of Object.entries(o))this.pendingCounts[n]=this.renderedCount(n)+a;return this.pendingMoves++,n=>{if(!r){if(r=!0,n)for(let[a,l]of Object.entries(o))this.pendingCounts[a]-=l;--this.pendingMoves===0&&(this.pendingCounts={})}}},renderedCount(e){let t=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"] .ff-count`);return this.pendingCounts[e]??Number(t?.dataset.total)},handleSortableEnd(e){this.endDrag();let t=e.item,o=e.to,r=e.newDraggableIndex??e.newIndex,n=":scope > [x-sortable-item], :scope > [data-card-id]",a=s=>s.getAttribute("x-sortable-item")||s.getAttribute("data-card-id");if(e.from===o&&e.oldDraggableIndex===e.newDraggableIndex)return;if(r===0){let s=o.querySelector(n);s&&s!==t&&o.insertBefore(t,s)}let l=a(t);if(!l){console.error("Flowforge: Could not determine card ID for move operation");return}let i=o.getAttribute("data-column-id");if(!i){console.error("Flowforge: Target column ID is missing");return}let b=e.from.dataset.laneId??null,w=o.dataset.laneId??null,u=o.querySelectorAll(n),d=Array.prototype.indexOf.call(u,t),S=d>0?a(u[d-1]):null,y=d>=0&&d{this.setCardState(t,!1),g(s===!1),s===!1&&this.revertCard(e)}).catch(()=>{this.setCardState(t,!1),g(!0),this.revertCard(e)})},revertCard({item:e,from:t,oldDraggableIndex:o}){e.remove();let r=t.querySelectorAll(":scope > [x-sortable-item]"),n=r[r.length-1],a=r[o]??(n?n.nextSibling:t.firstChild);t.insertBefore(e,a)},setCardState(e,t){e.toggleAttribute("data-pending",t)},isLaneCollapsed(e){return this.collapsedLanes[e]===!0},toggleLane(e){this.collapsedLanes[e]=!this.isLaneCollapsed(e)},isLoadingColumn(e){return this.isLoading[e]||!1},isColumnFullyLoaded(e){return this.fullyLoaded[e]||!1},handleSmoothScroll(e){this.isLoadingColumn(e)||this.isColumnFullyLoaded(e)||(this.isLoading[e]=!0,this.$wire.loadMoreItems(e).then(()=>setTimeout(()=>this.isLoading[e]=!1,100)).catch(()=>this.isLoading[e]=!1))},handleColumnScroll(e,t){if(this.isColumnFullyLoaded(t))return;let{scrollTop:o,scrollHeight:r,clientHeight:n}=e.target;(o+n)/r>=.8&&!this.isLoadingColumn(t)&&this.handleSmoothScroll(t)}}}export{k as default}; +var A=["--ff-surface","--ff-surface-sunken","--ff-surface-raised","--ff-border","--ff-text","--ff-text-muted","--ff-accent","--ff-accent-tint","--ff-danger","--ff-warning","--ff-radius","--ff-gap","--ff-ease","--ff-duration","--ff-column-width","--ff-tray-bg","--ff-tray-radius","--ff-card-bg","--ff-card-ring","--ff-card-radius","--ff-card-shadow","--ff-card-padding","--ff-drag-tilt","--ff-drag-shadow","--ff-placeholder-border"],c='.ff-column-actions, .fi-dropdown-panel, input, textarea, select, [contenteditable]:not([contenteditable="false"])',m=`.ff-card, .ff-column-header, .ff-add-slot, .ff-add-row, .ff-cards-more, .ff-limit-hint, button, a, ${c}`,f=4,L=300,k=e=>{let t=e.querySelector("[data-autofocus]");!t||e.style.display!=="block"||!window.matchMedia("(pointer: fine)").matches||(t.focus({preventScroll:!0}),t.setSelectionRange?.(t.value.length,t.value.length))},p=new WeakSet,h=new WeakSet,C=()=>window.Sortable.active||window.Sortable.dragged;function D(){return{isLoading:{},fullyLoaded:{},dragOverColumn:null,railToggledAt:0,railClickTimer:null,columnMenuPressAt:null,railPressAt:null,dragOverLane:null,dragSource:null,pendingCounts:{},pendingMoves:0,collapsedLanes:{},addingColumn:!1,newColumnName:"",newColumnTouched:!1,addingColumnPending:!1,placeholder:null,stopTrackingPointer:null,init(){this.$wire.$on("kanban-items-loaded",e=>{let{columnId:t,isFullyLoaded:o}=e;o&&(this.fullyLoaded[t]=!0)})},configureSortable(e){if(!e.sortable||e.sortable.options.forceFallback)return;if(C()){this.configureSortableAfterDrag(e);return}let t=window.matchMedia("(prefers-reduced-motion: reduce)").matches;e.sortable.destroy(),e.sortable=window.Sortable.create(e,{draggable:"[x-sortable-item]",handle:"[x-sortable-handle]",dataIdAttr:"x-sortable-item",forceFallback:!0,fallbackTolerance:5,fallbackOnBody:!0,fallbackClass:"",ghostClass:"",delay:150,delayOnTouchOnly:!0,animation:t?0:200,scrollSensitivity:100,scrollSpeed:15,forceAutoScrollFallback:!0,group:{name:e.getAttribute("x-sortable-group"),pull:!0,put:(o,r)=>this.canDrop(o.el,r.el)},onStart:o=>this.startDrag(o),onEnd(o){let{item:r,to:n,oldDraggableIndex:s,newDraggableIndex:l}=o;if(s===l)return;let i=n.querySelectorAll(`:scope > ${this.options.draggable}`)[l-1];i&&n.insertBefore(r,i.nextSibling)}})},configureSortableAfterDrag(e){if(h.has(e))return;h.add(e);let t=()=>{if(C()){requestAnimationFrame(t);return}h.delete(e),e.isConnected&&this.configureSortable(e)};requestAnimationFrame(t)},startDrag(e){this.stopTrackingPointer?.(),this.placeholder=e.item,this.placeholder.setAttribute("data-placeholder",""),this.markGhost(),window.getSelection()?.removeAllRanges(),document.documentElement.classList.add("ff-dragging"),this.dragSource={column:e.from.dataset.columnId,lane:e.from.dataset.laneId??null};let t=o=>this.trackPointer(o);document.addEventListener("pointermove",t,{passive:!0}),document.addEventListener("touchmove",t,{passive:!0}),this.stopTrackingPointer=()=>{document.removeEventListener("pointermove",t),document.removeEventListener("touchmove",t)}},trackPointer(e){if(!window.Sortable.active){this.endDrag();return}this.markGhost();let t=e.touches?.[0]??e,o=document.elementFromPoint(t.clientX,t.clientY),r=o?.closest("[data-column-id]"),n=o?.closest("[data-column-root]");this.dragOverColumn=r?.dataset.columnId??n?.dataset.columnRoot??null,this.dragOverLane=r?.dataset.laneId??null},markGhost(){let e=window.Sortable.ghost;if(!e||e.hasAttribute("data-dragging"))return;e.removeAttribute("data-placeholder"),e.setAttribute("data-dragging",""),e.style.opacity="1";let t=getComputedStyle(this.placeholder);for(let o of A){let r=t.getPropertyValue(o);r!==""&&e.style.setProperty(o,r)}},endDrag(){document.documentElement.classList.remove("ff-dragging"),this.placeholder?.removeAttribute("data-placeholder"),this.placeholder=null,this.stopTrackingPointer?.(),this.stopTrackingPointer=null,this.dragOverColumn=null,this.dragOverLane=null,this.dragSource=null},railPress(e){this.railPressAt={x:e.clientX,y:e.clientY}},toggleColumnCollapse(e,t,o=!1){if(!(e.target.closest(c)||o&&e.detail>1)){if(o){let r=this.railPressAt;if(this.railPressAt=null,r&&Math.hypot(e.clientX-r.x,e.clientY-r.y)>f)return}Date.now()-this.railToggledAt<500||(o&&(this.railToggledAt=Date.now()),this.$wire.toggleBoardColumnCollapse(t))}},expandFromCollapseAll(e,t){let o=this.railPressAt;if(this.railPressAt=null,e.target.closest(c)||o&&Math.hypot(e.clientX-o.x,e.clientY-o.y)>f)return;let r=e.detail>1;clearTimeout(this.railClickTimer),this.railClickTimer=setTimeout(()=>{this.railToggledAt=Date.now(),this.$wire.toggleBoardColumnCollapse(t,r)},r?0:L)},collapseFromEmptySpace(e,t){e.target.closest(m)||this.toggleColumnCollapse(e,t)},suppressEmptySpaceSelection(e){e.detail>1&&!e.target.closest(m)&&e.preventDefault()},openNewColumn(){this.addingColumn=!0,this.newColumnTouched=!0,this.$nextTick(()=>{this.$refs.newColumnInput.focus({preventScroll:!0}),requestAnimationFrame(()=>this.$refs.newColumnInput.scrollIntoView({block:"nearest",inline:"nearest"}))})},cancelNewColumn(){this.addingColumn=!1,this.newColumnTouched=!0,this.newColumnName=""},async submitNewColumn(){if(!this.addingColumnPending){this.addingColumnPending=!0,this.newColumnTouched=!0;try{await this.$wire.addBoardColumn(this.newColumnName)}finally{this.addingColumnPending=!1}this.newColumnTouched=!1,this.$root.querySelector(".ff-add-column-error")||this.cancelNewColumn()}},suppressDoubleClickSelection(e){e.detail>1&&!e.target.closest(c)&&e.preventDefault()},initColumnMenu(e){let t=e.closest(".fi-dropdown");if(p.has(t))return;let o=window.Alpine.$data(t),r=o.toggle.bind(o);p.add(t),o.toggle=n=>n?.type==="mousedown"?void 0:r(n)},columnMenuPress(e){this.columnMenuPressAt={x:e.clientX,y:e.clientY}},columnMenuClick(e){let t=this.columnMenuPressAt;if(this.columnMenuPressAt=null,e.detail>1||t&&Math.hypot(e.clientX-t.x,e.clientY-t.y)>f)return;let o=e.currentTarget.closest(".fi-dropdown");window.Alpine.$data(o).toggle(e),requestAnimationFrame(()=>k(o.querySelector(":scope > .fi-dropdown-panel")))},columnDrop(e){return this.dragOverColumn!==e?null:this.isColumnBlocked(e)?"blocked":"active"},cellDrop(e,t){return this.dragOverColumn!==e||this.dragOverLane!==t?null:this.isCellBlocked(e,t)?"blocked":"active"},canDrop(e,t){if(!this.$root.contains(e)||!this.$root.contains(t))return!1;let o=e.dataset.laneId??null,r=t.dataset.laneId??null;return o!==r&&this.$root.dataset.lanesWritable!=="true"?!1:!this.isColumnBlocked(e.dataset.columnId,t.dataset.columnId)},isColumnBlocked(e,t=this.dragSource?.column){if(!e||e===t)return!1;let o=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"]`),r=o?.dataset.columnLimit;return r===void 0||r===""?!1:Number(o.dataset.columnTotal)>=Number(r)},isCellBlocked(e,t){return this.dragSource?t!==this.dragSource.lane&&this.$root.dataset.lanesWritable!=="true"?!0:this.isColumnBlocked(e):!1},displayCount(e,t){let o=this.pendingCounts[e]??t,r=this.dragSource?.column,n=this.dragOverColumn;return!r||!n||r===n||this.isColumnBlocked(n)?o:e===n?o+1:e===r?o-1:o},holdMovedCounts(e,t){if(e===t)return()=>{};let o={[e]:-1,[t]:1},r=!1;for(let[n,s]of Object.entries(o))this.pendingCounts[n]=this.renderedCount(n)+s;return this.pendingMoves++,n=>{if(!r){if(r=!0,n)for(let[s,l]of Object.entries(o))this.pendingCounts[s]-=l;--this.pendingMoves===0&&(this.pendingCounts={})}}},renderedCount(e){let t=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"] .ff-count`);return this.pendingCounts[e]??Number(t?.dataset.total)},handleSortableEnd(e){this.endDrag();let t=e.item,o=e.to,r=e.newDraggableIndex??e.newIndex,n=":scope > [x-sortable-item], :scope > [data-card-id]",s=a=>a.getAttribute("x-sortable-item")||a.getAttribute("data-card-id");if(e.from===o&&e.oldDraggableIndex===e.newDraggableIndex)return;if(r===0){let a=o.querySelector(n);a&&a!==t&&o.insertBefore(t,a)}let l=s(t);if(!l){console.error("Flowforge: Could not determine card ID for move operation");return}let i=o.getAttribute("data-column-id");if(!i){console.error("Flowforge: Target column ID is missing");return}let b=e.from.dataset.laneId??null,w=o.dataset.laneId??null,u=o.querySelectorAll(n),d=Array.prototype.indexOf.call(u,t),S=d>0?s(u[d-1]):null,y=d>=0&&d{this.setCardState(t,!1),g(a===!1),a===!1&&this.revertCard(e)}).catch(()=>{this.setCardState(t,!1),g(!0),this.revertCard(e)})},revertCard({item:e,from:t,oldDraggableIndex:o}){e.remove();let r=t.querySelectorAll(":scope > [x-sortable-item]"),n=r[r.length-1],s=r[o]??(n?n.nextSibling:t.firstChild);t.insertBefore(e,s)},setCardState(e,t){e.toggleAttribute("data-pending",t)},isLaneCollapsed(e){return this.collapsedLanes[e]===!0},toggleLane(e){this.collapsedLanes[e]=!this.isLaneCollapsed(e)},isLoadingColumn(e){return this.isLoading[e]||!1},isColumnFullyLoaded(e){return this.fullyLoaded[e]||!1},handleSmoothScroll(e){this.isLoadingColumn(e)||this.isColumnFullyLoaded(e)||(this.isLoading[e]=!0,this.$wire.loadMoreItems(e).then(()=>setTimeout(()=>this.isLoading[e]=!1,100)).catch(()=>this.isLoading[e]=!1))},handleColumnScroll(e,t){if(this.isColumnFullyLoaded(t))return;let{scrollTop:o,scrollHeight:r,clientHeight:n}=e.target;(o+n)/r>=.8&&!this.isLoadingColumn(t)&&this.handleSmoothScroll(t)}}}export{D as default}; diff --git a/resources/js/flowforge-modern.js b/resources/js/flowforge-modern.js index 80857eda0..dcecf3aaf 100644 --- a/resources/js/flowforge-modern.js +++ b/resources/js/flowforge-modern.js @@ -32,6 +32,9 @@ const EMPTY_SPACE_IGNORED = `.ff-card, .ff-column-header, .ff-add-slot, .ff-add- const MENU_DRAG_THRESHOLD = 4; +// A rail under collapse all waits this long, so a second click can claim the column alone. +const DOUBLE_CLICK_WINDOW = 300; + const focusMenuField = (panel) => { const field = panel.querySelector('[data-autofocus]'); @@ -57,6 +60,7 @@ export default function flowforgeModern() { dragOverColumn: null, railToggledAt: 0, + railClickTimer: null, columnMenuPressAt: null, railPressAt: null, dragOverLane: null, @@ -272,6 +276,24 @@ export default function flowforgeModern() { this.$wire.toggleBoardColumnCollapse(columnId); }, + expandFromCollapseAll(event, columnId) { + const press = this.railPressAt; + + this.railPressAt = null; + + if (event.target.closest(HEADER_GESTURE_IGNORED) || (press && Math.hypot(event.clientX - press.x, event.clientY - press.y) > MENU_DRAG_THRESHOLD)) { + return; + } + + const alone = event.detail > 1; + + clearTimeout(this.railClickTimer); + this.railClickTimer = setTimeout(() => { + this.railToggledAt = Date.now(); + this.$wire.toggleBoardColumnCollapse(columnId, alone); + }, alone ? 0 : DOUBLE_CLICK_WINDOW); + }, + collapseFromEmptySpace(event, columnId) { if (!event.target.closest(EMPTY_SPACE_IGNORED)) { this.toggleColumnCollapse(event, columnId); diff --git a/resources/views/modern/livewire/column.blade.php b/resources/views/modern/livewire/column.blade.php index 08bc2b69b..aa1df2990 100644 --- a/resources/views/modern/livewire/column.blade.php +++ b/resources/views/modern/livewire/column.blade.php @@ -22,7 +22,11 @@ class="ff-column" @if ($column['isFull'] ?? false) data-full @endif @if ($isCollapsed) data-collapsed title="{{ $plainLabel }}" @endif @if ($isCollapsed && ($column['canToggleCollapse'] ?? false)) - x-on:click="toggleColumnCollapse($event, @js((string) $columnId), true)" + @if ($column['isCollapsedByAll'] ?? false) + x-on:click="expandFromCollapseAll($event, @js((string) $columnId))" + @else + x-on:click="toggleColumnCollapse($event, @js((string) $columnId), true)" + @endif x-on:pointerdown="railPress($event)" x-on:mousedown="suppressDoubleClickSelection($event)" @endif diff --git a/resources/views/modern/livewire/lanes.blade.php b/resources/views/modern/livewire/lanes.blade.php index c6fbd9fa1..5f805a9f1 100644 --- a/resources/views/modern/livewire/lanes.blade.php +++ b/resources/views/modern/livewire/lanes.blade.php @@ -30,7 +30,11 @@ class="ff-column" @if ($column['isFull'] ?? false) data-full @endif @if ($isCollapsed) data-collapsed title="{{ strip_tags((string) $column['label']) }}" @endif @if ($isCollapsed && ($column['canToggleCollapse'] ?? false)) - x-on:click="toggleColumnCollapse($event, @js((string) $columnId), true)" + @if ($column['isCollapsedByAll'] ?? false) + x-on:click="expandFromCollapseAll($event, @js((string) $columnId))" + @else + x-on:click="toggleColumnCollapse($event, @js((string) $columnId), true)" + @endif x-on:pointerdown="railPress($event)" x-on:mousedown="suppressDoubleClickSelection($event)" @endif diff --git a/src/Board.php b/src/Board.php index f114ec5aa..71c38215c 100644 --- a/src/Board.php +++ b/src/Board.php @@ -142,7 +142,7 @@ public function getViewData(): array } /** - * @return array{collapsed: bool, toggleable: bool} + * @return array{collapsed: bool, toggleable: bool, byAll: bool} */ public function getColumnCollapseState(string $columnId): array { @@ -151,7 +151,7 @@ public function getColumnCollapseState(string $columnId): array /** * @param array $allCounts - * @return Closure(string): array{collapsed: bool, toggleable: bool} + * @return Closure(string): array{collapsed: bool, toggleable: bool, byAll: bool} */ protected function makeCollapseResolver(array $allCounts): Closure { @@ -172,6 +172,7 @@ protected function makeCollapseResolver(array $allCounts): Closure 'toggleable' => $this->isColumnCollapsible() && in_array($columnId, $visible, true) && ! $byEmptyRule, + 'byAll' => $collapseAll, ]; }; } @@ -209,6 +210,7 @@ protected function getColumnViewData(bool $withItems): array 'total' => $total, 'isCollapsed' => $state['collapsed'], 'canToggleCollapse' => $state['toggleable'], + 'isCollapsedByAll' => $state['byAll'], 'summary' => $this->getColumnSummary($column), 'limit' => $limit, 'limitTotal' => $limitTotal, diff --git a/src/Concerns/HasColumnControls.php b/src/Concerns/HasColumnControls.php index 53a155efb..ecd814a0c 100644 --- a/src/Concerns/HasColumnControls.php +++ b/src/Concerns/HasColumnControls.php @@ -80,7 +80,7 @@ public function isColumnCollapsible(): bool return $this->toggleColumnCollapse instanceof Closure; } - public function toggleColumnCollapse(string $columnId): void + public function toggleColumnCollapse(string $columnId, bool $alone = false): void { $state = $this->getColumnCollapseState($columnId); @@ -91,6 +91,7 @@ public function toggleColumnCollapse(string $columnId): void $this->evaluate($this->toggleColumnCollapse, [ 'columnId' => $columnId, 'collapsed' => ! $state['collapsed'], + 'alone' => $alone, ]); } diff --git a/src/Modern/Concerns/InteractsWithBoard.php b/src/Modern/Concerns/InteractsWithBoard.php index 3c8e49d86..bf56b4972 100644 --- a/src/Modern/Concerns/InteractsWithBoard.php +++ b/src/Modern/Concerns/InteractsWithBoard.php @@ -121,9 +121,9 @@ public function getBoardCreateCardAction(string $columnId): ?Action return $action ? $action(['column' => $columnId])->livewire($this) : null; } - public function toggleBoardColumnCollapse(string $columnId): void + public function toggleBoardColumnCollapse(string $columnId, bool $alone = false): void { - $this->getBoard()->toggleColumnCollapse($columnId); + $this->getBoard()->toggleColumnCollapse($columnId, $alone); $this->board = $this->board($this->makeBoard()); } diff --git a/tests/Fixtures/Modern/TestBoard.php b/tests/Fixtures/Modern/TestBoard.php index 35efd27d7..66a1d9017 100644 --- a/tests/Fixtures/Modern/TestBoard.php +++ b/tests/Fixtures/Modern/TestBoard.php @@ -41,6 +41,8 @@ class TestBoard extends BoardPage public array $toggled = []; + public array $toggledAlone = []; + public bool $withAddColumn = false; public array $addedColumns = []; @@ -104,8 +106,9 @@ public function board(Board $board): Board }) ->collapseAllColumns($this->collapseAll) ->collapsibleColumns($this->collapsible - ? function (string $columnId, bool $collapsed): void { + ? function (string $columnId, bool $collapsed, bool $alone): void { $this->toggled[] = [$columnId, $collapsed]; + $this->toggledAlone = $alone ? [...$this->toggledAlone, $columnId] : $this->toggledAlone; $this->collapsedIds = $collapsed ? [...$this->collapsedIds, $columnId] : array_values(array_diff($this->collapsedIds, [$columnId])); diff --git a/tests/Modern/Feature/CollapsedColumnsTest.php b/tests/Modern/Feature/CollapsedColumnsTest.php index eaa156bfd..e4cc8f1b2 100644 --- a/tests/Modern/Feature/CollapsedColumnsTest.php +++ b/tests/Modern/Feature/CollapsedColumnsTest.php @@ -142,9 +142,12 @@ expect($component->html())->toMatch('/]*data-column-root="in_progress"[^>]*data-collapsed[^>]*x-on:click/'); - $component->call('toggleBoardColumnCollapse', 'in_progress'); + $component->call('toggleBoardColumnCollapse', 'in_progress') + ->call('toggleBoardColumnCollapse', 'completed', true); - expect($component->get('toggled'))->toBe([['in_progress', false]]); + expect($component->get('toggled'))->toBe([['in_progress', false], ['completed', false]]) + ->and($component->get('toggledAlone'))->toBe(['completed']) + ->and($component->html())->toMatch('/]*data-column-root="todo"[^>]*x-on:click="expandFromCollapseAll/'); }); test('a toggle shows the new state in the same response for a plain array of ids', function () { From f81c0922d3f145a9ad9a049e0314d208032fdeef Mon Sep 17 00:00:00 2001 From: Manuk Date: Sun, 15 Nov 2026 00:51:34 +0400 Subject: [PATCH 22/34] fix(columns): focus the new column input a frame after it shows --- resources/dist/flowforge-modern.js | 2 +- resources/js/flowforge-modern.js | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/resources/dist/flowforge-modern.js b/resources/dist/flowforge-modern.js index 63fb8a45f..c04d3bcfc 100644 --- a/resources/dist/flowforge-modern.js +++ b/resources/dist/flowforge-modern.js @@ -1 +1 @@ -var A=["--ff-surface","--ff-surface-sunken","--ff-surface-raised","--ff-border","--ff-text","--ff-text-muted","--ff-accent","--ff-accent-tint","--ff-danger","--ff-warning","--ff-radius","--ff-gap","--ff-ease","--ff-duration","--ff-column-width","--ff-tray-bg","--ff-tray-radius","--ff-card-bg","--ff-card-ring","--ff-card-radius","--ff-card-shadow","--ff-card-padding","--ff-drag-tilt","--ff-drag-shadow","--ff-placeholder-border"],c='.ff-column-actions, .fi-dropdown-panel, input, textarea, select, [contenteditable]:not([contenteditable="false"])',m=`.ff-card, .ff-column-header, .ff-add-slot, .ff-add-row, .ff-cards-more, .ff-limit-hint, button, a, ${c}`,f=4,L=300,k=e=>{let t=e.querySelector("[data-autofocus]");!t||e.style.display!=="block"||!window.matchMedia("(pointer: fine)").matches||(t.focus({preventScroll:!0}),t.setSelectionRange?.(t.value.length,t.value.length))},p=new WeakSet,h=new WeakSet,C=()=>window.Sortable.active||window.Sortable.dragged;function D(){return{isLoading:{},fullyLoaded:{},dragOverColumn:null,railToggledAt:0,railClickTimer:null,columnMenuPressAt:null,railPressAt:null,dragOverLane:null,dragSource:null,pendingCounts:{},pendingMoves:0,collapsedLanes:{},addingColumn:!1,newColumnName:"",newColumnTouched:!1,addingColumnPending:!1,placeholder:null,stopTrackingPointer:null,init(){this.$wire.$on("kanban-items-loaded",e=>{let{columnId:t,isFullyLoaded:o}=e;o&&(this.fullyLoaded[t]=!0)})},configureSortable(e){if(!e.sortable||e.sortable.options.forceFallback)return;if(C()){this.configureSortableAfterDrag(e);return}let t=window.matchMedia("(prefers-reduced-motion: reduce)").matches;e.sortable.destroy(),e.sortable=window.Sortable.create(e,{draggable:"[x-sortable-item]",handle:"[x-sortable-handle]",dataIdAttr:"x-sortable-item",forceFallback:!0,fallbackTolerance:5,fallbackOnBody:!0,fallbackClass:"",ghostClass:"",delay:150,delayOnTouchOnly:!0,animation:t?0:200,scrollSensitivity:100,scrollSpeed:15,forceAutoScrollFallback:!0,group:{name:e.getAttribute("x-sortable-group"),pull:!0,put:(o,r)=>this.canDrop(o.el,r.el)},onStart:o=>this.startDrag(o),onEnd(o){let{item:r,to:n,oldDraggableIndex:s,newDraggableIndex:l}=o;if(s===l)return;let i=n.querySelectorAll(`:scope > ${this.options.draggable}`)[l-1];i&&n.insertBefore(r,i.nextSibling)}})},configureSortableAfterDrag(e){if(h.has(e))return;h.add(e);let t=()=>{if(C()){requestAnimationFrame(t);return}h.delete(e),e.isConnected&&this.configureSortable(e)};requestAnimationFrame(t)},startDrag(e){this.stopTrackingPointer?.(),this.placeholder=e.item,this.placeholder.setAttribute("data-placeholder",""),this.markGhost(),window.getSelection()?.removeAllRanges(),document.documentElement.classList.add("ff-dragging"),this.dragSource={column:e.from.dataset.columnId,lane:e.from.dataset.laneId??null};let t=o=>this.trackPointer(o);document.addEventListener("pointermove",t,{passive:!0}),document.addEventListener("touchmove",t,{passive:!0}),this.stopTrackingPointer=()=>{document.removeEventListener("pointermove",t),document.removeEventListener("touchmove",t)}},trackPointer(e){if(!window.Sortable.active){this.endDrag();return}this.markGhost();let t=e.touches?.[0]??e,o=document.elementFromPoint(t.clientX,t.clientY),r=o?.closest("[data-column-id]"),n=o?.closest("[data-column-root]");this.dragOverColumn=r?.dataset.columnId??n?.dataset.columnRoot??null,this.dragOverLane=r?.dataset.laneId??null},markGhost(){let e=window.Sortable.ghost;if(!e||e.hasAttribute("data-dragging"))return;e.removeAttribute("data-placeholder"),e.setAttribute("data-dragging",""),e.style.opacity="1";let t=getComputedStyle(this.placeholder);for(let o of A){let r=t.getPropertyValue(o);r!==""&&e.style.setProperty(o,r)}},endDrag(){document.documentElement.classList.remove("ff-dragging"),this.placeholder?.removeAttribute("data-placeholder"),this.placeholder=null,this.stopTrackingPointer?.(),this.stopTrackingPointer=null,this.dragOverColumn=null,this.dragOverLane=null,this.dragSource=null},railPress(e){this.railPressAt={x:e.clientX,y:e.clientY}},toggleColumnCollapse(e,t,o=!1){if(!(e.target.closest(c)||o&&e.detail>1)){if(o){let r=this.railPressAt;if(this.railPressAt=null,r&&Math.hypot(e.clientX-r.x,e.clientY-r.y)>f)return}Date.now()-this.railToggledAt<500||(o&&(this.railToggledAt=Date.now()),this.$wire.toggleBoardColumnCollapse(t))}},expandFromCollapseAll(e,t){let o=this.railPressAt;if(this.railPressAt=null,e.target.closest(c)||o&&Math.hypot(e.clientX-o.x,e.clientY-o.y)>f)return;let r=e.detail>1;clearTimeout(this.railClickTimer),this.railClickTimer=setTimeout(()=>{this.railToggledAt=Date.now(),this.$wire.toggleBoardColumnCollapse(t,r)},r?0:L)},collapseFromEmptySpace(e,t){e.target.closest(m)||this.toggleColumnCollapse(e,t)},suppressEmptySpaceSelection(e){e.detail>1&&!e.target.closest(m)&&e.preventDefault()},openNewColumn(){this.addingColumn=!0,this.newColumnTouched=!0,this.$nextTick(()=>{this.$refs.newColumnInput.focus({preventScroll:!0}),requestAnimationFrame(()=>this.$refs.newColumnInput.scrollIntoView({block:"nearest",inline:"nearest"}))})},cancelNewColumn(){this.addingColumn=!1,this.newColumnTouched=!0,this.newColumnName=""},async submitNewColumn(){if(!this.addingColumnPending){this.addingColumnPending=!0,this.newColumnTouched=!0;try{await this.$wire.addBoardColumn(this.newColumnName)}finally{this.addingColumnPending=!1}this.newColumnTouched=!1,this.$root.querySelector(".ff-add-column-error")||this.cancelNewColumn()}},suppressDoubleClickSelection(e){e.detail>1&&!e.target.closest(c)&&e.preventDefault()},initColumnMenu(e){let t=e.closest(".fi-dropdown");if(p.has(t))return;let o=window.Alpine.$data(t),r=o.toggle.bind(o);p.add(t),o.toggle=n=>n?.type==="mousedown"?void 0:r(n)},columnMenuPress(e){this.columnMenuPressAt={x:e.clientX,y:e.clientY}},columnMenuClick(e){let t=this.columnMenuPressAt;if(this.columnMenuPressAt=null,e.detail>1||t&&Math.hypot(e.clientX-t.x,e.clientY-t.y)>f)return;let o=e.currentTarget.closest(".fi-dropdown");window.Alpine.$data(o).toggle(e),requestAnimationFrame(()=>k(o.querySelector(":scope > .fi-dropdown-panel")))},columnDrop(e){return this.dragOverColumn!==e?null:this.isColumnBlocked(e)?"blocked":"active"},cellDrop(e,t){return this.dragOverColumn!==e||this.dragOverLane!==t?null:this.isCellBlocked(e,t)?"blocked":"active"},canDrop(e,t){if(!this.$root.contains(e)||!this.$root.contains(t))return!1;let o=e.dataset.laneId??null,r=t.dataset.laneId??null;return o!==r&&this.$root.dataset.lanesWritable!=="true"?!1:!this.isColumnBlocked(e.dataset.columnId,t.dataset.columnId)},isColumnBlocked(e,t=this.dragSource?.column){if(!e||e===t)return!1;let o=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"]`),r=o?.dataset.columnLimit;return r===void 0||r===""?!1:Number(o.dataset.columnTotal)>=Number(r)},isCellBlocked(e,t){return this.dragSource?t!==this.dragSource.lane&&this.$root.dataset.lanesWritable!=="true"?!0:this.isColumnBlocked(e):!1},displayCount(e,t){let o=this.pendingCounts[e]??t,r=this.dragSource?.column,n=this.dragOverColumn;return!r||!n||r===n||this.isColumnBlocked(n)?o:e===n?o+1:e===r?o-1:o},holdMovedCounts(e,t){if(e===t)return()=>{};let o={[e]:-1,[t]:1},r=!1;for(let[n,s]of Object.entries(o))this.pendingCounts[n]=this.renderedCount(n)+s;return this.pendingMoves++,n=>{if(!r){if(r=!0,n)for(let[s,l]of Object.entries(o))this.pendingCounts[s]-=l;--this.pendingMoves===0&&(this.pendingCounts={})}}},renderedCount(e){let t=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"] .ff-count`);return this.pendingCounts[e]??Number(t?.dataset.total)},handleSortableEnd(e){this.endDrag();let t=e.item,o=e.to,r=e.newDraggableIndex??e.newIndex,n=":scope > [x-sortable-item], :scope > [data-card-id]",s=a=>a.getAttribute("x-sortable-item")||a.getAttribute("data-card-id");if(e.from===o&&e.oldDraggableIndex===e.newDraggableIndex)return;if(r===0){let a=o.querySelector(n);a&&a!==t&&o.insertBefore(t,a)}let l=s(t);if(!l){console.error("Flowforge: Could not determine card ID for move operation");return}let i=o.getAttribute("data-column-id");if(!i){console.error("Flowforge: Target column ID is missing");return}let b=e.from.dataset.laneId??null,w=o.dataset.laneId??null,u=o.querySelectorAll(n),d=Array.prototype.indexOf.call(u,t),S=d>0?s(u[d-1]):null,y=d>=0&&d{this.setCardState(t,!1),g(a===!1),a===!1&&this.revertCard(e)}).catch(()=>{this.setCardState(t,!1),g(!0),this.revertCard(e)})},revertCard({item:e,from:t,oldDraggableIndex:o}){e.remove();let r=t.querySelectorAll(":scope > [x-sortable-item]"),n=r[r.length-1],s=r[o]??(n?n.nextSibling:t.firstChild);t.insertBefore(e,s)},setCardState(e,t){e.toggleAttribute("data-pending",t)},isLaneCollapsed(e){return this.collapsedLanes[e]===!0},toggleLane(e){this.collapsedLanes[e]=!this.isLaneCollapsed(e)},isLoadingColumn(e){return this.isLoading[e]||!1},isColumnFullyLoaded(e){return this.fullyLoaded[e]||!1},handleSmoothScroll(e){this.isLoadingColumn(e)||this.isColumnFullyLoaded(e)||(this.isLoading[e]=!0,this.$wire.loadMoreItems(e).then(()=>setTimeout(()=>this.isLoading[e]=!1,100)).catch(()=>this.isLoading[e]=!1))},handleColumnScroll(e,t){if(this.isColumnFullyLoaded(t))return;let{scrollTop:o,scrollHeight:r,clientHeight:n}=e.target;(o+n)/r>=.8&&!this.isLoadingColumn(t)&&this.handleSmoothScroll(t)}}}export{D as default}; +var A=["--ff-surface","--ff-surface-sunken","--ff-surface-raised","--ff-border","--ff-text","--ff-text-muted","--ff-accent","--ff-accent-tint","--ff-danger","--ff-warning","--ff-radius","--ff-gap","--ff-ease","--ff-duration","--ff-column-width","--ff-tray-bg","--ff-tray-radius","--ff-card-bg","--ff-card-ring","--ff-card-radius","--ff-card-shadow","--ff-card-padding","--ff-drag-tilt","--ff-drag-shadow","--ff-placeholder-border"],c='.ff-column-actions, .fi-dropdown-panel, input, textarea, select, [contenteditable]:not([contenteditable="false"])',m=`.ff-card, .ff-column-header, .ff-add-slot, .ff-add-row, .ff-cards-more, .ff-limit-hint, button, a, ${c}`,f=4,L=300,k=e=>{let t=e.querySelector("[data-autofocus]");!t||e.style.display!=="block"||!window.matchMedia("(pointer: fine)").matches||(t.focus({preventScroll:!0}),t.setSelectionRange?.(t.value.length,t.value.length))},p=new WeakSet,h=new WeakSet,C=()=>window.Sortable.active||window.Sortable.dragged;function D(){return{isLoading:{},fullyLoaded:{},dragOverColumn:null,railToggledAt:0,railClickTimer:null,columnMenuPressAt:null,railPressAt:null,dragOverLane:null,dragSource:null,pendingCounts:{},pendingMoves:0,collapsedLanes:{},addingColumn:!1,newColumnName:"",newColumnTouched:!1,addingColumnPending:!1,placeholder:null,stopTrackingPointer:null,init(){this.$wire.$on("kanban-items-loaded",e=>{let{columnId:t,isFullyLoaded:o}=e;o&&(this.fullyLoaded[t]=!0)})},configureSortable(e){if(!e.sortable||e.sortable.options.forceFallback)return;if(C()){this.configureSortableAfterDrag(e);return}let t=window.matchMedia("(prefers-reduced-motion: reduce)").matches;e.sortable.destroy(),e.sortable=window.Sortable.create(e,{draggable:"[x-sortable-item]",handle:"[x-sortable-handle]",dataIdAttr:"x-sortable-item",forceFallback:!0,fallbackTolerance:5,fallbackOnBody:!0,fallbackClass:"",ghostClass:"",delay:150,delayOnTouchOnly:!0,animation:t?0:200,scrollSensitivity:100,scrollSpeed:15,forceAutoScrollFallback:!0,group:{name:e.getAttribute("x-sortable-group"),pull:!0,put:(o,r)=>this.canDrop(o.el,r.el)},onStart:o=>this.startDrag(o),onEnd(o){let{item:r,to:n,oldDraggableIndex:s,newDraggableIndex:l}=o;if(s===l)return;let i=n.querySelectorAll(`:scope > ${this.options.draggable}`)[l-1];i&&n.insertBefore(r,i.nextSibling)}})},configureSortableAfterDrag(e){if(h.has(e))return;h.add(e);let t=()=>{if(C()){requestAnimationFrame(t);return}h.delete(e),e.isConnected&&this.configureSortable(e)};requestAnimationFrame(t)},startDrag(e){this.stopTrackingPointer?.(),this.placeholder=e.item,this.placeholder.setAttribute("data-placeholder",""),this.markGhost(),window.getSelection()?.removeAllRanges(),document.documentElement.classList.add("ff-dragging"),this.dragSource={column:e.from.dataset.columnId,lane:e.from.dataset.laneId??null};let t=o=>this.trackPointer(o);document.addEventListener("pointermove",t,{passive:!0}),document.addEventListener("touchmove",t,{passive:!0}),this.stopTrackingPointer=()=>{document.removeEventListener("pointermove",t),document.removeEventListener("touchmove",t)}},trackPointer(e){if(!window.Sortable.active){this.endDrag();return}this.markGhost();let t=e.touches?.[0]??e,o=document.elementFromPoint(t.clientX,t.clientY),r=o?.closest("[data-column-id]"),n=o?.closest("[data-column-root]");this.dragOverColumn=r?.dataset.columnId??n?.dataset.columnRoot??null,this.dragOverLane=r?.dataset.laneId??null},markGhost(){let e=window.Sortable.ghost;if(!e||e.hasAttribute("data-dragging"))return;e.removeAttribute("data-placeholder"),e.setAttribute("data-dragging",""),e.style.opacity="1";let t=getComputedStyle(this.placeholder);for(let o of A){let r=t.getPropertyValue(o);r!==""&&e.style.setProperty(o,r)}},endDrag(){document.documentElement.classList.remove("ff-dragging"),this.placeholder?.removeAttribute("data-placeholder"),this.placeholder=null,this.stopTrackingPointer?.(),this.stopTrackingPointer=null,this.dragOverColumn=null,this.dragOverLane=null,this.dragSource=null},railPress(e){this.railPressAt={x:e.clientX,y:e.clientY}},toggleColumnCollapse(e,t,o=!1){if(!(e.target.closest(c)||o&&e.detail>1)){if(o){let r=this.railPressAt;if(this.railPressAt=null,r&&Math.hypot(e.clientX-r.x,e.clientY-r.y)>f)return}Date.now()-this.railToggledAt<500||(o&&(this.railToggledAt=Date.now()),this.$wire.toggleBoardColumnCollapse(t))}},expandFromCollapseAll(e,t){let o=this.railPressAt;if(this.railPressAt=null,e.target.closest(c)||o&&Math.hypot(e.clientX-o.x,e.clientY-o.y)>f)return;let r=e.detail>1;clearTimeout(this.railClickTimer),this.railClickTimer=setTimeout(()=>{this.railToggledAt=Date.now(),this.$wire.toggleBoardColumnCollapse(t,r)},r?0:L)},collapseFromEmptySpace(e,t){e.target.closest(m)||this.toggleColumnCollapse(e,t)},suppressEmptySpaceSelection(e){e.detail>1&&!e.target.closest(m)&&e.preventDefault()},openNewColumn(){this.addingColumn=!0,this.newColumnTouched=!0,this.$nextTick(()=>requestAnimationFrame(()=>{this.$refs.newColumnInput.focus({preventScroll:!0}),this.$refs.newColumnInput.scrollIntoView({block:"nearest",inline:"nearest"})}))},cancelNewColumn(){this.addingColumn=!1,this.newColumnTouched=!0,this.newColumnName=""},async submitNewColumn(){if(!this.addingColumnPending){this.addingColumnPending=!0,this.newColumnTouched=!0;try{await this.$wire.addBoardColumn(this.newColumnName)}finally{this.addingColumnPending=!1}this.newColumnTouched=!1,this.$root.querySelector(".ff-add-column-error")||this.cancelNewColumn()}},suppressDoubleClickSelection(e){e.detail>1&&!e.target.closest(c)&&e.preventDefault()},initColumnMenu(e){let t=e.closest(".fi-dropdown");if(p.has(t))return;let o=window.Alpine.$data(t),r=o.toggle.bind(o);p.add(t),o.toggle=n=>n?.type==="mousedown"?void 0:r(n)},columnMenuPress(e){this.columnMenuPressAt={x:e.clientX,y:e.clientY}},columnMenuClick(e){let t=this.columnMenuPressAt;if(this.columnMenuPressAt=null,e.detail>1||t&&Math.hypot(e.clientX-t.x,e.clientY-t.y)>f)return;let o=e.currentTarget.closest(".fi-dropdown");window.Alpine.$data(o).toggle(e),requestAnimationFrame(()=>k(o.querySelector(":scope > .fi-dropdown-panel")))},columnDrop(e){return this.dragOverColumn!==e?null:this.isColumnBlocked(e)?"blocked":"active"},cellDrop(e,t){return this.dragOverColumn!==e||this.dragOverLane!==t?null:this.isCellBlocked(e,t)?"blocked":"active"},canDrop(e,t){if(!this.$root.contains(e)||!this.$root.contains(t))return!1;let o=e.dataset.laneId??null,r=t.dataset.laneId??null;return o!==r&&this.$root.dataset.lanesWritable!=="true"?!1:!this.isColumnBlocked(e.dataset.columnId,t.dataset.columnId)},isColumnBlocked(e,t=this.dragSource?.column){if(!e||e===t)return!1;let o=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"]`),r=o?.dataset.columnLimit;return r===void 0||r===""?!1:Number(o.dataset.columnTotal)>=Number(r)},isCellBlocked(e,t){return this.dragSource?t!==this.dragSource.lane&&this.$root.dataset.lanesWritable!=="true"?!0:this.isColumnBlocked(e):!1},displayCount(e,t){let o=this.pendingCounts[e]??t,r=this.dragSource?.column,n=this.dragOverColumn;return!r||!n||r===n||this.isColumnBlocked(n)?o:e===n?o+1:e===r?o-1:o},holdMovedCounts(e,t){if(e===t)return()=>{};let o={[e]:-1,[t]:1},r=!1;for(let[n,s]of Object.entries(o))this.pendingCounts[n]=this.renderedCount(n)+s;return this.pendingMoves++,n=>{if(!r){if(r=!0,n)for(let[s,l]of Object.entries(o))this.pendingCounts[s]-=l;--this.pendingMoves===0&&(this.pendingCounts={})}}},renderedCount(e){let t=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"] .ff-count`);return this.pendingCounts[e]??Number(t?.dataset.total)},handleSortableEnd(e){this.endDrag();let t=e.item,o=e.to,r=e.newDraggableIndex??e.newIndex,n=":scope > [x-sortable-item], :scope > [data-card-id]",s=a=>a.getAttribute("x-sortable-item")||a.getAttribute("data-card-id");if(e.from===o&&e.oldDraggableIndex===e.newDraggableIndex)return;if(r===0){let a=o.querySelector(n);a&&a!==t&&o.insertBefore(t,a)}let l=s(t);if(!l){console.error("Flowforge: Could not determine card ID for move operation");return}let i=o.getAttribute("data-column-id");if(!i){console.error("Flowforge: Target column ID is missing");return}let b=e.from.dataset.laneId??null,w=o.dataset.laneId??null,u=o.querySelectorAll(n),d=Array.prototype.indexOf.call(u,t),S=d>0?s(u[d-1]):null,y=d>=0&&d{this.setCardState(t,!1),g(a===!1),a===!1&&this.revertCard(e)}).catch(()=>{this.setCardState(t,!1),g(!0),this.revertCard(e)})},revertCard({item:e,from:t,oldDraggableIndex:o}){e.remove();let r=t.querySelectorAll(":scope > [x-sortable-item]"),n=r[r.length-1],s=r[o]??(n?n.nextSibling:t.firstChild);t.insertBefore(e,s)},setCardState(e,t){e.toggleAttribute("data-pending",t)},isLaneCollapsed(e){return this.collapsedLanes[e]===!0},toggleLane(e){this.collapsedLanes[e]=!this.isLaneCollapsed(e)},isLoadingColumn(e){return this.isLoading[e]||!1},isColumnFullyLoaded(e){return this.fullyLoaded[e]||!1},handleSmoothScroll(e){this.isLoadingColumn(e)||this.isColumnFullyLoaded(e)||(this.isLoading[e]=!0,this.$wire.loadMoreItems(e).then(()=>setTimeout(()=>this.isLoading[e]=!1,100)).catch(()=>this.isLoading[e]=!1))},handleColumnScroll(e,t){if(this.isColumnFullyLoaded(t))return;let{scrollTop:o,scrollHeight:r,clientHeight:n}=e.target;(o+n)/r>=.8&&!this.isLoadingColumn(t)&&this.handleSmoothScroll(t)}}}export{D as default}; diff --git a/resources/js/flowforge-modern.js b/resources/js/flowforge-modern.js index dcecf3aaf..4f2f245b0 100644 --- a/resources/js/flowforge-modern.js +++ b/resources/js/flowforge-modern.js @@ -309,10 +309,11 @@ export default function flowforgeModern() { openNewColumn() { this.addingColumn = true; this.newColumnTouched = true; - this.$nextTick(() => { + // WebKit ignores a focus on the next tick, right after the ghost column shows. One frame later it takes it. + this.$nextTick(() => requestAnimationFrame(() => { this.$refs.newColumnInput.focus({ preventScroll: true }); - requestAnimationFrame(() => this.$refs.newColumnInput.scrollIntoView({ block: 'nearest', inline: 'nearest' })); - }); + this.$refs.newColumnInput.scrollIntoView({ block: 'nearest', inline: 'nearest' }); + })); }, cancelNewColumn() { From bff100090dc37c1deb02accafdf186ae3a88d88e Mon Sep 17 00:00:00 2001 From: Manuk Date: Sun, 15 Nov 2026 00:56:28 +0400 Subject: [PATCH 23/34] feat(columns): pick a color for a new column from the host palette --- docs/content/2.essentials/2.customization.md | 14 +++++- .../skills/flowforge-development/SKILL.md | 2 +- resources/css/flowforge-modern.css | 44 ++++++++++++++++++- resources/dist/flowforge-modern.js | 2 +- resources/js/flowforge-modern.js | 15 ++++++- resources/lang/de/flowforge.php | 1 + resources/lang/en/flowforge.php | 1 + resources/lang/es/flowforge.php | 1 + resources/lang/nl/flowforge.php | 1 + resources/views/modern/index.blade.php | 2 +- .../modern/livewire/add-column.blade.php | 33 +++++++++++++- .../views/modern/livewire/lanes.blade.php | 2 +- src/Board.php | 6 +++ src/Concerns/HasColumnControls.php | 28 +++++++++++- src/Modern/Concerns/InteractsWithBoard.php | 4 +- tests/Fixtures/Modern/TestBoard.php | 8 +++- tests/Modern/Feature/AddColumnTest.php | 12 +++++ 17 files changed, 161 insertions(+), 15 deletions(-) diff --git a/docs/content/2.essentials/2.customization.md b/docs/content/2.essentials/2.customization.md index 41bef19f1..f5686acfd 100644 --- a/docs/content/2.essentials/2.customization.md +++ b/docs/content/2.essentials/2.customization.md @@ -364,8 +364,9 @@ buttons still grabs the header. ### Add a column from the board -`addColumnUsing()` adds a dashed tile after the last column. A click on it swaps in a name -input. Enter submits and Escape cancels. Flowforge keeps no columns. It passes the trimmed name to +`addColumnUsing()` adds a tile after the last column. A click on it opens a column-width ghost +column with a name form at its top, focused. Enter submits. Escape or a click outside the form +cancels. Flowforge keeps no columns. It passes the trimmed name to your closure and rebuilds the board once the closure returns, so a `columns()` list that reads your state shows the new column in the same response: @@ -390,6 +391,15 @@ message under the input. `addColumnLabel()` sets the tooltip and the input label setting it. With a grouping active, the tile is an extra track in the header row only, and every lane cell keeps its column. +`addColumnColors()` turns the form's dot into a color picker. Pass the palette as color values +keyed to their labels. The picked color reaches your closure as `$color`, and a value outside the +palette or no pick arrives as `null`: + +```php +->addColumnUsing(fn (string $name, ?string $color) => $this->addStage($name, $color ?? 'gray')) +->addColumnColors(['#ff5454' => 'Red', '#266df0' => 'Blue']) +``` + ## Search and Filtering Enable powerful search and filtering capabilities: diff --git a/resources/boost/skills/flowforge-development/SKILL.md b/resources/boost/skills/flowforge-development/SKILL.md index 8a240815d..4cb8ccbd5 100644 --- a/resources/boost/skills/flowforge-development/SKILL.md +++ b/resources/boost/skills/flowforge-development/SKILL.md @@ -365,7 +365,7 @@ A "Group by" select appears and the choice lives in `?groupBy=`. `lanes()` retur ### Column controls -The host owns the state and Flowforge renders it. `collapsedColumns(fn () => [...])` and `collapseAllColumns(fn () => ...)` collapse columns. `collapsibleColumns(fn (string $columnId, bool $collapsed) => ...)` lets a double-click in a column's empty space, or on a header without a menu, collapse it and a click on its rail expand it. Columns from `collapsedColumns()` or `collapseAllColumns()` expand by click. Under collapse all the closure also gets `bool $alone`: false for a click, true for a double-click. `columnHeaderMenu(fn (array $column): ?Htmlable => ...)` turns the header into a menu holding the host block above the column actions. It opens over its column, takes the header's clicks, and focuses a `data-autofocus` field on a mouse click. `addColumnUsing(fn (string $name) => ...)` with `addColumnLabel()` and `addColumnPlaceholder()` adds a tile after the last column; throw a `ValidationException` to show a message under its input. Pass any value the page changes during a request as a closure, because the board is built before the action runs. +The host owns the state and Flowforge renders it. `collapsedColumns(fn () => [...])` and `collapseAllColumns(fn () => ...)` collapse columns. `collapsibleColumns(fn (string $columnId, bool $collapsed) => ...)` lets a double-click in a column's empty space, or on a header without a menu, collapse it and a click on its rail expand it. Columns from `collapsedColumns()` or `collapseAllColumns()` expand by click. Under collapse all the closure also gets `bool $alone`: false for a click, true for a double-click. `columnHeaderMenu(fn (array $column): ?Htmlable => ...)` turns the header into a menu holding the host block above the column actions. It opens over its column, takes the header's clicks, and focuses a `data-autofocus` field on a mouse click. `addColumnUsing(fn (string $name, ?string $color) => ...)` with `addColumnLabel()`, `addColumnPlaceholder()` and an optional `addColumnColors([value => label])` palette adds a tile after the last column; throw a `ValidationException` to show a message under its input. Pass any value the page changes during a request as a closure, because the board is built before the action runs. ### Styling a Modern Board diff --git a/resources/css/flowforge-modern.css b/resources/css/flowforge-modern.css index 742baf968..00981154d 100644 --- a/resources/css/flowforge-modern.css +++ b/resources/css/flowforge-modern.css @@ -749,6 +749,7 @@ } .ff-add-column-field { + position: relative; display: flex; align-items: center; gap: 0.625rem; @@ -771,10 +772,51 @@ flex-shrink: 0; width: 0.875rem; height: 0.875rem; - background-color: var(--gray-400); + background-color: var(--color-500, var(--gray-400)); border-radius: 9999px; } + .ff-add-column-swatches { + position: absolute; + inset-block-start: 100%; + inset-inline-start: 0.625rem; + z-index: 30; + display: grid; + grid-template-columns: repeat(4, 1.5rem); + gap: 0.5rem; + margin-block-start: -0.375rem; + padding: 0.5rem; + background-color: var(--ff-surface-raised, #fff); + border-radius: 0.75rem; + box-shadow: + 0 0 0 1px color-mix(in oklab, var(--gray-950) 5%, transparent), + 0 10px 15px -3px rgb(0 0 0 / 0.1), + 0 4px 6px -4px rgb(0 0 0 / 0.1); + } + + :where(.dark) .ff-add-column-swatches { + background-color: var(--ff-surface-raised, var(--gray-900)); + box-shadow: + 0 0 0 1px color-mix(in oklab, #fff 10%, transparent), + 0 10px 15px -3px rgb(0 0 0 / 0.3); + } + + .ff-add-column-swatch { + --_tint: color-mix(in oklab, var(--color-500) 18%, #fff); + width: 1.5rem; + height: 1.5rem; + background-color: var(--color-500); + border-radius: 0.375rem; + } + + :where(.dark) .ff-add-column-swatch { + --_tint: color-mix(in oklab, var(--color-500) 30%, var(--gray-900)); + } + + .ff-add-column-swatch[aria-pressed="true"] { + box-shadow: inset 0 0 0 1.5px var(--_tint), 0 0 0 1.5px var(--_tint), 0 0 0 2.5px var(--color-500); + } + .ff-add-column-input { flex: 1 1 auto; min-width: 0; diff --git a/resources/dist/flowforge-modern.js b/resources/dist/flowforge-modern.js index c04d3bcfc..259367a61 100644 --- a/resources/dist/flowforge-modern.js +++ b/resources/dist/flowforge-modern.js @@ -1 +1 @@ -var A=["--ff-surface","--ff-surface-sunken","--ff-surface-raised","--ff-border","--ff-text","--ff-text-muted","--ff-accent","--ff-accent-tint","--ff-danger","--ff-warning","--ff-radius","--ff-gap","--ff-ease","--ff-duration","--ff-column-width","--ff-tray-bg","--ff-tray-radius","--ff-card-bg","--ff-card-ring","--ff-card-radius","--ff-card-shadow","--ff-card-padding","--ff-drag-tilt","--ff-drag-shadow","--ff-placeholder-border"],c='.ff-column-actions, .fi-dropdown-panel, input, textarea, select, [contenteditable]:not([contenteditable="false"])',m=`.ff-card, .ff-column-header, .ff-add-slot, .ff-add-row, .ff-cards-more, .ff-limit-hint, button, a, ${c}`,f=4,L=300,k=e=>{let t=e.querySelector("[data-autofocus]");!t||e.style.display!=="block"||!window.matchMedia("(pointer: fine)").matches||(t.focus({preventScroll:!0}),t.setSelectionRange?.(t.value.length,t.value.length))},p=new WeakSet,h=new WeakSet,C=()=>window.Sortable.active||window.Sortable.dragged;function D(){return{isLoading:{},fullyLoaded:{},dragOverColumn:null,railToggledAt:0,railClickTimer:null,columnMenuPressAt:null,railPressAt:null,dragOverLane:null,dragSource:null,pendingCounts:{},pendingMoves:0,collapsedLanes:{},addingColumn:!1,newColumnName:"",newColumnTouched:!1,addingColumnPending:!1,placeholder:null,stopTrackingPointer:null,init(){this.$wire.$on("kanban-items-loaded",e=>{let{columnId:t,isFullyLoaded:o}=e;o&&(this.fullyLoaded[t]=!0)})},configureSortable(e){if(!e.sortable||e.sortable.options.forceFallback)return;if(C()){this.configureSortableAfterDrag(e);return}let t=window.matchMedia("(prefers-reduced-motion: reduce)").matches;e.sortable.destroy(),e.sortable=window.Sortable.create(e,{draggable:"[x-sortable-item]",handle:"[x-sortable-handle]",dataIdAttr:"x-sortable-item",forceFallback:!0,fallbackTolerance:5,fallbackOnBody:!0,fallbackClass:"",ghostClass:"",delay:150,delayOnTouchOnly:!0,animation:t?0:200,scrollSensitivity:100,scrollSpeed:15,forceAutoScrollFallback:!0,group:{name:e.getAttribute("x-sortable-group"),pull:!0,put:(o,r)=>this.canDrop(o.el,r.el)},onStart:o=>this.startDrag(o),onEnd(o){let{item:r,to:n,oldDraggableIndex:s,newDraggableIndex:l}=o;if(s===l)return;let i=n.querySelectorAll(`:scope > ${this.options.draggable}`)[l-1];i&&n.insertBefore(r,i.nextSibling)}})},configureSortableAfterDrag(e){if(h.has(e))return;h.add(e);let t=()=>{if(C()){requestAnimationFrame(t);return}h.delete(e),e.isConnected&&this.configureSortable(e)};requestAnimationFrame(t)},startDrag(e){this.stopTrackingPointer?.(),this.placeholder=e.item,this.placeholder.setAttribute("data-placeholder",""),this.markGhost(),window.getSelection()?.removeAllRanges(),document.documentElement.classList.add("ff-dragging"),this.dragSource={column:e.from.dataset.columnId,lane:e.from.dataset.laneId??null};let t=o=>this.trackPointer(o);document.addEventListener("pointermove",t,{passive:!0}),document.addEventListener("touchmove",t,{passive:!0}),this.stopTrackingPointer=()=>{document.removeEventListener("pointermove",t),document.removeEventListener("touchmove",t)}},trackPointer(e){if(!window.Sortable.active){this.endDrag();return}this.markGhost();let t=e.touches?.[0]??e,o=document.elementFromPoint(t.clientX,t.clientY),r=o?.closest("[data-column-id]"),n=o?.closest("[data-column-root]");this.dragOverColumn=r?.dataset.columnId??n?.dataset.columnRoot??null,this.dragOverLane=r?.dataset.laneId??null},markGhost(){let e=window.Sortable.ghost;if(!e||e.hasAttribute("data-dragging"))return;e.removeAttribute("data-placeholder"),e.setAttribute("data-dragging",""),e.style.opacity="1";let t=getComputedStyle(this.placeholder);for(let o of A){let r=t.getPropertyValue(o);r!==""&&e.style.setProperty(o,r)}},endDrag(){document.documentElement.classList.remove("ff-dragging"),this.placeholder?.removeAttribute("data-placeholder"),this.placeholder=null,this.stopTrackingPointer?.(),this.stopTrackingPointer=null,this.dragOverColumn=null,this.dragOverLane=null,this.dragSource=null},railPress(e){this.railPressAt={x:e.clientX,y:e.clientY}},toggleColumnCollapse(e,t,o=!1){if(!(e.target.closest(c)||o&&e.detail>1)){if(o){let r=this.railPressAt;if(this.railPressAt=null,r&&Math.hypot(e.clientX-r.x,e.clientY-r.y)>f)return}Date.now()-this.railToggledAt<500||(o&&(this.railToggledAt=Date.now()),this.$wire.toggleBoardColumnCollapse(t))}},expandFromCollapseAll(e,t){let o=this.railPressAt;if(this.railPressAt=null,e.target.closest(c)||o&&Math.hypot(e.clientX-o.x,e.clientY-o.y)>f)return;let r=e.detail>1;clearTimeout(this.railClickTimer),this.railClickTimer=setTimeout(()=>{this.railToggledAt=Date.now(),this.$wire.toggleBoardColumnCollapse(t,r)},r?0:L)},collapseFromEmptySpace(e,t){e.target.closest(m)||this.toggleColumnCollapse(e,t)},suppressEmptySpaceSelection(e){e.detail>1&&!e.target.closest(m)&&e.preventDefault()},openNewColumn(){this.addingColumn=!0,this.newColumnTouched=!0,this.$nextTick(()=>requestAnimationFrame(()=>{this.$refs.newColumnInput.focus({preventScroll:!0}),this.$refs.newColumnInput.scrollIntoView({block:"nearest",inline:"nearest"})}))},cancelNewColumn(){this.addingColumn=!1,this.newColumnTouched=!0,this.newColumnName=""},async submitNewColumn(){if(!this.addingColumnPending){this.addingColumnPending=!0,this.newColumnTouched=!0;try{await this.$wire.addBoardColumn(this.newColumnName)}finally{this.addingColumnPending=!1}this.newColumnTouched=!1,this.$root.querySelector(".ff-add-column-error")||this.cancelNewColumn()}},suppressDoubleClickSelection(e){e.detail>1&&!e.target.closest(c)&&e.preventDefault()},initColumnMenu(e){let t=e.closest(".fi-dropdown");if(p.has(t))return;let o=window.Alpine.$data(t),r=o.toggle.bind(o);p.add(t),o.toggle=n=>n?.type==="mousedown"?void 0:r(n)},columnMenuPress(e){this.columnMenuPressAt={x:e.clientX,y:e.clientY}},columnMenuClick(e){let t=this.columnMenuPressAt;if(this.columnMenuPressAt=null,e.detail>1||t&&Math.hypot(e.clientX-t.x,e.clientY-t.y)>f)return;let o=e.currentTarget.closest(".fi-dropdown");window.Alpine.$data(o).toggle(e),requestAnimationFrame(()=>k(o.querySelector(":scope > .fi-dropdown-panel")))},columnDrop(e){return this.dragOverColumn!==e?null:this.isColumnBlocked(e)?"blocked":"active"},cellDrop(e,t){return this.dragOverColumn!==e||this.dragOverLane!==t?null:this.isCellBlocked(e,t)?"blocked":"active"},canDrop(e,t){if(!this.$root.contains(e)||!this.$root.contains(t))return!1;let o=e.dataset.laneId??null,r=t.dataset.laneId??null;return o!==r&&this.$root.dataset.lanesWritable!=="true"?!1:!this.isColumnBlocked(e.dataset.columnId,t.dataset.columnId)},isColumnBlocked(e,t=this.dragSource?.column){if(!e||e===t)return!1;let o=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"]`),r=o?.dataset.columnLimit;return r===void 0||r===""?!1:Number(o.dataset.columnTotal)>=Number(r)},isCellBlocked(e,t){return this.dragSource?t!==this.dragSource.lane&&this.$root.dataset.lanesWritable!=="true"?!0:this.isColumnBlocked(e):!1},displayCount(e,t){let o=this.pendingCounts[e]??t,r=this.dragSource?.column,n=this.dragOverColumn;return!r||!n||r===n||this.isColumnBlocked(n)?o:e===n?o+1:e===r?o-1:o},holdMovedCounts(e,t){if(e===t)return()=>{};let o={[e]:-1,[t]:1},r=!1;for(let[n,s]of Object.entries(o))this.pendingCounts[n]=this.renderedCount(n)+s;return this.pendingMoves++,n=>{if(!r){if(r=!0,n)for(let[s,l]of Object.entries(o))this.pendingCounts[s]-=l;--this.pendingMoves===0&&(this.pendingCounts={})}}},renderedCount(e){let t=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"] .ff-count`);return this.pendingCounts[e]??Number(t?.dataset.total)},handleSortableEnd(e){this.endDrag();let t=e.item,o=e.to,r=e.newDraggableIndex??e.newIndex,n=":scope > [x-sortable-item], :scope > [data-card-id]",s=a=>a.getAttribute("x-sortable-item")||a.getAttribute("data-card-id");if(e.from===o&&e.oldDraggableIndex===e.newDraggableIndex)return;if(r===0){let a=o.querySelector(n);a&&a!==t&&o.insertBefore(t,a)}let l=s(t);if(!l){console.error("Flowforge: Could not determine card ID for move operation");return}let i=o.getAttribute("data-column-id");if(!i){console.error("Flowforge: Target column ID is missing");return}let b=e.from.dataset.laneId??null,w=o.dataset.laneId??null,u=o.querySelectorAll(n),d=Array.prototype.indexOf.call(u,t),S=d>0?s(u[d-1]):null,y=d>=0&&d{this.setCardState(t,!1),g(a===!1),a===!1&&this.revertCard(e)}).catch(()=>{this.setCardState(t,!1),g(!0),this.revertCard(e)})},revertCard({item:e,from:t,oldDraggableIndex:o}){e.remove();let r=t.querySelectorAll(":scope > [x-sortable-item]"),n=r[r.length-1],s=r[o]??(n?n.nextSibling:t.firstChild);t.insertBefore(e,s)},setCardState(e,t){e.toggleAttribute("data-pending",t)},isLaneCollapsed(e){return this.collapsedLanes[e]===!0},toggleLane(e){this.collapsedLanes[e]=!this.isLaneCollapsed(e)},isLoadingColumn(e){return this.isLoading[e]||!1},isColumnFullyLoaded(e){return this.fullyLoaded[e]||!1},handleSmoothScroll(e){this.isLoadingColumn(e)||this.isColumnFullyLoaded(e)||(this.isLoading[e]=!0,this.$wire.loadMoreItems(e).then(()=>setTimeout(()=>this.isLoading[e]=!1,100)).catch(()=>this.isLoading[e]=!1))},handleColumnScroll(e,t){if(this.isColumnFullyLoaded(t))return;let{scrollTop:o,scrollHeight:r,clientHeight:n}=e.target;(o+n)/r>=.8&&!this.isLoadingColumn(t)&&this.handleSmoothScroll(t)}}}export{D as default}; +var A=["--ff-surface","--ff-surface-sunken","--ff-surface-raised","--ff-border","--ff-text","--ff-text-muted","--ff-accent","--ff-accent-tint","--ff-danger","--ff-warning","--ff-radius","--ff-gap","--ff-ease","--ff-duration","--ff-column-width","--ff-tray-bg","--ff-tray-radius","--ff-card-bg","--ff-card-ring","--ff-card-radius","--ff-card-shadow","--ff-card-padding","--ff-drag-tilt","--ff-drag-shadow","--ff-placeholder-border"],c='.ff-column-actions, .fi-dropdown-panel, input, textarea, select, [contenteditable]:not([contenteditable="false"])',m=`.ff-card, .ff-column-header, .ff-add-slot, .ff-add-row, .ff-cards-more, .ff-limit-hint, button, a, ${c}`,f=4,L=300,k=e=>{let t=e.querySelector("[data-autofocus]");!t||e.style.display!=="block"||!window.matchMedia("(pointer: fine)").matches||(t.focus({preventScroll:!0}),t.setSelectionRange?.(t.value.length,t.value.length))},p=new WeakSet,h=new WeakSet,C=()=>window.Sortable.active||window.Sortable.dragged;function D(){return{isLoading:{},fullyLoaded:{},dragOverColumn:null,railToggledAt:0,railClickTimer:null,columnMenuPressAt:null,railPressAt:null,dragOverLane:null,dragSource:null,pendingCounts:{},pendingMoves:0,collapsedLanes:{},addingColumn:!1,newColumnName:"",newColumnColor:null,newColumnDotStyle:"",choosingNewColumnColor:!1,newColumnTouched:!1,addingColumnPending:!1,placeholder:null,stopTrackingPointer:null,init(){this.$wire.$on("kanban-items-loaded",e=>{let{columnId:t,isFullyLoaded:o}=e;o&&(this.fullyLoaded[t]=!0)})},configureSortable(e){if(!e.sortable||e.sortable.options.forceFallback)return;if(C()){this.configureSortableAfterDrag(e);return}let t=window.matchMedia("(prefers-reduced-motion: reduce)").matches;e.sortable.destroy(),e.sortable=window.Sortable.create(e,{draggable:"[x-sortable-item]",handle:"[x-sortable-handle]",dataIdAttr:"x-sortable-item",forceFallback:!0,fallbackTolerance:5,fallbackOnBody:!0,fallbackClass:"",ghostClass:"",delay:150,delayOnTouchOnly:!0,animation:t?0:200,scrollSensitivity:100,scrollSpeed:15,forceAutoScrollFallback:!0,group:{name:e.getAttribute("x-sortable-group"),pull:!0,put:(o,n)=>this.canDrop(o.el,n.el)},onStart:o=>this.startDrag(o),onEnd(o){let{item:n,to:r,oldDraggableIndex:s,newDraggableIndex:a}=o;if(s===a)return;let i=r.querySelectorAll(`:scope > ${this.options.draggable}`)[a-1];i&&r.insertBefore(n,i.nextSibling)}})},configureSortableAfterDrag(e){if(h.has(e))return;h.add(e);let t=()=>{if(C()){requestAnimationFrame(t);return}h.delete(e),e.isConnected&&this.configureSortable(e)};requestAnimationFrame(t)},startDrag(e){this.stopTrackingPointer?.(),this.placeholder=e.item,this.placeholder.setAttribute("data-placeholder",""),this.markGhost(),window.getSelection()?.removeAllRanges(),document.documentElement.classList.add("ff-dragging"),this.dragSource={column:e.from.dataset.columnId,lane:e.from.dataset.laneId??null};let t=o=>this.trackPointer(o);document.addEventListener("pointermove",t,{passive:!0}),document.addEventListener("touchmove",t,{passive:!0}),this.stopTrackingPointer=()=>{document.removeEventListener("pointermove",t),document.removeEventListener("touchmove",t)}},trackPointer(e){if(!window.Sortable.active){this.endDrag();return}this.markGhost();let t=e.touches?.[0]??e,o=document.elementFromPoint(t.clientX,t.clientY),n=o?.closest("[data-column-id]"),r=o?.closest("[data-column-root]");this.dragOverColumn=n?.dataset.columnId??r?.dataset.columnRoot??null,this.dragOverLane=n?.dataset.laneId??null},markGhost(){let e=window.Sortable.ghost;if(!e||e.hasAttribute("data-dragging"))return;e.removeAttribute("data-placeholder"),e.setAttribute("data-dragging",""),e.style.opacity="1";let t=getComputedStyle(this.placeholder);for(let o of A){let n=t.getPropertyValue(o);n!==""&&e.style.setProperty(o,n)}},endDrag(){document.documentElement.classList.remove("ff-dragging"),this.placeholder?.removeAttribute("data-placeholder"),this.placeholder=null,this.stopTrackingPointer?.(),this.stopTrackingPointer=null,this.dragOverColumn=null,this.dragOverLane=null,this.dragSource=null},railPress(e){this.railPressAt={x:e.clientX,y:e.clientY}},toggleColumnCollapse(e,t,o=!1){if(!(e.target.closest(c)||o&&e.detail>1)){if(o){let n=this.railPressAt;if(this.railPressAt=null,n&&Math.hypot(e.clientX-n.x,e.clientY-n.y)>f)return}Date.now()-this.railToggledAt<500||(o&&(this.railToggledAt=Date.now()),this.$wire.toggleBoardColumnCollapse(t))}},expandFromCollapseAll(e,t){let o=this.railPressAt;if(this.railPressAt=null,e.target.closest(c)||o&&Math.hypot(e.clientX-o.x,e.clientY-o.y)>f)return;let n=e.detail>1;clearTimeout(this.railClickTimer),this.railClickTimer=setTimeout(()=>{this.railToggledAt=Date.now(),this.$wire.toggleBoardColumnCollapse(t,n)},n?0:L)},collapseFromEmptySpace(e,t){e.target.closest(m)||this.toggleColumnCollapse(e,t)},suppressEmptySpaceSelection(e){e.detail>1&&!e.target.closest(m)&&e.preventDefault()},openNewColumn(){this.addingColumn=!0,this.newColumnTouched=!0,this.$nextTick(()=>requestAnimationFrame(()=>{this.$refs.newColumnInput.focus({preventScroll:!0}),this.$refs.newColumnInput.scrollIntoView({block:"nearest",inline:"nearest"})}))},cancelNewColumn(){this.addingColumn=!1,this.newColumnTouched=!0,this.newColumnName="",this.newColumnColor=null,this.newColumnDotStyle="",this.choosingNewColumnColor=!1},pickNewColumnColor(e,t){this.newColumnColor=e,this.newColumnDotStyle=t,this.choosingNewColumnColor=!1,this.$refs.newColumnInput.focus({preventScroll:!0})},async submitNewColumn(){if(!this.addingColumnPending){this.addingColumnPending=!0,this.newColumnTouched=!0;try{await this.$wire.addBoardColumn(this.newColumnName,this.newColumnColor)}finally{this.addingColumnPending=!1}this.newColumnTouched=!1,this.$root.querySelector(".ff-add-column-error")||this.cancelNewColumn()}},suppressDoubleClickSelection(e){e.detail>1&&!e.target.closest(c)&&e.preventDefault()},initColumnMenu(e){let t=e.closest(".fi-dropdown");if(p.has(t))return;let o=window.Alpine.$data(t),n=o.toggle.bind(o);p.add(t),o.toggle=r=>r?.type==="mousedown"?void 0:n(r)},columnMenuPress(e){this.columnMenuPressAt={x:e.clientX,y:e.clientY}},columnMenuClick(e){let t=this.columnMenuPressAt;if(this.columnMenuPressAt=null,e.detail>1||t&&Math.hypot(e.clientX-t.x,e.clientY-t.y)>f)return;let o=e.currentTarget.closest(".fi-dropdown");window.Alpine.$data(o).toggle(e),requestAnimationFrame(()=>k(o.querySelector(":scope > .fi-dropdown-panel")))},columnDrop(e){return this.dragOverColumn!==e?null:this.isColumnBlocked(e)?"blocked":"active"},cellDrop(e,t){return this.dragOverColumn!==e||this.dragOverLane!==t?null:this.isCellBlocked(e,t)?"blocked":"active"},canDrop(e,t){if(!this.$root.contains(e)||!this.$root.contains(t))return!1;let o=e.dataset.laneId??null,n=t.dataset.laneId??null;return o!==n&&this.$root.dataset.lanesWritable!=="true"?!1:!this.isColumnBlocked(e.dataset.columnId,t.dataset.columnId)},isColumnBlocked(e,t=this.dragSource?.column){if(!e||e===t)return!1;let o=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"]`),n=o?.dataset.columnLimit;return n===void 0||n===""?!1:Number(o.dataset.columnTotal)>=Number(n)},isCellBlocked(e,t){return this.dragSource?t!==this.dragSource.lane&&this.$root.dataset.lanesWritable!=="true"?!0:this.isColumnBlocked(e):!1},displayCount(e,t){let o=this.pendingCounts[e]??t,n=this.dragSource?.column,r=this.dragOverColumn;return!n||!r||n===r||this.isColumnBlocked(r)?o:e===r?o+1:e===n?o-1:o},holdMovedCounts(e,t){if(e===t)return()=>{};let o={[e]:-1,[t]:1},n=!1;for(let[r,s]of Object.entries(o))this.pendingCounts[r]=this.renderedCount(r)+s;return this.pendingMoves++,r=>{if(!n){if(n=!0,r)for(let[s,a]of Object.entries(o))this.pendingCounts[s]-=a;--this.pendingMoves===0&&(this.pendingCounts={})}}},renderedCount(e){let t=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"] .ff-count`);return this.pendingCounts[e]??Number(t?.dataset.total)},handleSortableEnd(e){this.endDrag();let t=e.item,o=e.to,n=e.newDraggableIndex??e.newIndex,r=":scope > [x-sortable-item], :scope > [data-card-id]",s=l=>l.getAttribute("x-sortable-item")||l.getAttribute("data-card-id");if(e.from===o&&e.oldDraggableIndex===e.newDraggableIndex)return;if(n===0){let l=o.querySelector(r);l&&l!==t&&o.insertBefore(t,l)}let a=s(t);if(!a){console.error("Flowforge: Could not determine card ID for move operation");return}let i=o.getAttribute("data-column-id");if(!i){console.error("Flowforge: Target column ID is missing");return}let w=e.from.dataset.laneId??null,b=o.dataset.laneId??null,u=o.querySelectorAll(r),d=Array.prototype.indexOf.call(u,t),S=d>0?s(u[d-1]):null,y=d>=0&&d{this.setCardState(t,!1),g(l===!1),l===!1&&this.revertCard(e)}).catch(()=>{this.setCardState(t,!1),g(!0),this.revertCard(e)})},revertCard({item:e,from:t,oldDraggableIndex:o}){e.remove();let n=t.querySelectorAll(":scope > [x-sortable-item]"),r=n[n.length-1],s=n[o]??(r?r.nextSibling:t.firstChild);t.insertBefore(e,s)},setCardState(e,t){e.toggleAttribute("data-pending",t)},isLaneCollapsed(e){return this.collapsedLanes[e]===!0},toggleLane(e){this.collapsedLanes[e]=!this.isLaneCollapsed(e)},isLoadingColumn(e){return this.isLoading[e]||!1},isColumnFullyLoaded(e){return this.fullyLoaded[e]||!1},handleSmoothScroll(e){this.isLoadingColumn(e)||this.isColumnFullyLoaded(e)||(this.isLoading[e]=!0,this.$wire.loadMoreItems(e).then(()=>setTimeout(()=>this.isLoading[e]=!1,100)).catch(()=>this.isLoading[e]=!1))},handleColumnScroll(e,t){if(this.isColumnFullyLoaded(t))return;let{scrollTop:o,scrollHeight:n,clientHeight:r}=e.target;(o+r)/n>=.8&&!this.isLoadingColumn(t)&&this.handleSmoothScroll(t)}}}export{D as default}; diff --git a/resources/js/flowforge-modern.js b/resources/js/flowforge-modern.js index 4f2f245b0..f68f19e92 100644 --- a/resources/js/flowforge-modern.js +++ b/resources/js/flowforge-modern.js @@ -70,6 +70,9 @@ export default function flowforgeModern() { collapsedLanes: {}, addingColumn: false, newColumnName: '', + newColumnColor: null, + newColumnDotStyle: '', + choosingNewColumnColor: false, newColumnTouched: false, addingColumnPending: false, placeholder: null, @@ -320,6 +323,16 @@ export default function flowforgeModern() { this.addingColumn = false; this.newColumnTouched = true; this.newColumnName = ''; + this.newColumnColor = null; + this.newColumnDotStyle = ''; + this.choosingNewColumnColor = false; + }, + + pickNewColumnColor(color, style) { + this.newColumnColor = color; + this.newColumnDotStyle = style; + this.choosingNewColumnColor = false; + this.$refs.newColumnInput.focus({ preventScroll: true }); }, async submitNewColumn() { @@ -331,7 +344,7 @@ export default function flowforgeModern() { this.newColumnTouched = true; try { - await this.$wire.addBoardColumn(this.newColumnName); + await this.$wire.addBoardColumn(this.newColumnName, this.newColumnColor); } finally { this.addingColumnPending = false; } diff --git a/resources/lang/de/flowforge.php b/resources/lang/de/flowforge.php index 6d4130e99..4078bae83 100644 --- a/resources/lang/de/flowforge.php +++ b/resources/lang/de/flowforge.php @@ -24,6 +24,7 @@ 'add_column' => 'Spalte hinzufügen', 'column_name_required' => 'Gib einen Namen ein.', 'column_name' => 'Spaltenname', + 'column_color' => 'Spaltenfarbe', 'show_more_cards' => ':count weitere anzeigen', 'lane_write_failed' => 'Die Karte konnte nicht in diese Bahn verschoben werden.', ]; diff --git a/resources/lang/en/flowforge.php b/resources/lang/en/flowforge.php index 6e105e58b..801c7d78c 100644 --- a/resources/lang/en/flowforge.php +++ b/resources/lang/en/flowforge.php @@ -24,6 +24,7 @@ 'add_column' => 'Add column', 'column_name_required' => 'Enter a name.', 'column_name' => 'Column name', + 'column_color' => 'Column color', 'show_more_cards' => 'Show :count more', 'lane_write_failed' => 'The card could not be moved to that lane.', ]; diff --git a/resources/lang/es/flowforge.php b/resources/lang/es/flowforge.php index d5cedcedb..7184875ac 100644 --- a/resources/lang/es/flowforge.php +++ b/resources/lang/es/flowforge.php @@ -24,6 +24,7 @@ 'add_column' => 'Añadir columna', 'column_name_required' => 'Introduce un nombre.', 'column_name' => 'Nombre de la columna', + 'column_color' => 'Color de la columna', 'show_more_cards' => 'Mostrar :count más', 'lane_write_failed' => 'No se pudo mover la tarjeta a ese carril.', ]; diff --git a/resources/lang/nl/flowforge.php b/resources/lang/nl/flowforge.php index dae036678..ab6546dd8 100644 --- a/resources/lang/nl/flowforge.php +++ b/resources/lang/nl/flowforge.php @@ -24,6 +24,7 @@ 'add_column' => 'Kolom toevoegen', 'column_name_required' => 'Voer een naam in.', 'column_name' => 'Kolomnaam', + 'column_color' => 'Kolomkleur', 'show_more_cards' => ':count meer tonen', 'lane_write_failed' => 'De kaart kon niet naar die baan worden verplaatst.', ]; diff --git a/resources/views/modern/index.blade.php b/resources/views/modern/index.blade.php index 9691e65d2..99c1dd76d 100644 --- a/resources/views/modern/index.blade.php +++ b/resources/views/modern/index.blade.php @@ -41,7 +41,7 @@ class="ff-board" @endforeach @if ($config['canAddColumns'] ?? false) - + @endif
@endif diff --git a/resources/views/modern/livewire/add-column.blade.php b/resources/views/modern/livewire/add-column.blade.php index 35c3b5601..4c75cd4e6 100644 --- a/resources/views/modern/livewire/add-column.blade.php +++ b/resources/views/modern/livewire/add-column.blade.php @@ -1,4 +1,4 @@ -@props(['label', 'placeholder']) +@props(['label', 'placeholder', 'colors' => []]) @php use Filament\Support\Enums\IconSize; @@ -12,7 +12,36 @@ class="ff-add-column-form" x-on:click.outside="cancelNewColumn()" >
- + @if ($colors) + + +
+ @foreach ($colors as $color) + + @endforeach +
+ @else + + @endif + @endif
diff --git a/src/Board.php b/src/Board.php index 71c38215c..6cfb17a17 100644 --- a/src/Board.php +++ b/src/Board.php @@ -19,6 +19,7 @@ use Relaticle\Flowforge\Concerns\HasColumnSummaries; use Relaticle\Flowforge\Concerns\InteractsWithKanbanQuery; use Relaticle\Flowforge\Contracts\HasBoard; +use Relaticle\Flowforge\Support\ColorResolver; class Board extends ViewComponent { @@ -132,6 +133,11 @@ public function getViewData(): array 'canAddColumns' => $this->canAddColumns(), 'addColumnLabel' => $this->getAddColumnLabel(), 'addColumnPlaceholder' => $this->getAddColumnPlaceholder(), + 'addColumnColors' => array_map( + fn (string $value, string $label): array => ['value' => $value, 'label' => $label, 'style' => ColorResolver::dotStyle($value)], + array_keys($this->getAddColumnColors()), + $this->getAddColumnColors(), + ), 'collapseEmptyColumns' => $grouping === null && $this->collapsesEmptyColumns() && array_sum(array_column($columns, 'total')) > 0, diff --git a/src/Concerns/HasColumnControls.php b/src/Concerns/HasColumnControls.php index ecd814a0c..287aa5fa7 100644 --- a/src/Concerns/HasColumnControls.php +++ b/src/Concerns/HasColumnControls.php @@ -27,6 +27,9 @@ trait HasColumnControls protected string | Closure | null $addColumnPlaceholder = null; + /** @var array|Closure|null */ + protected array | Closure | null $addColumnColors = null; + /** * @param array|Closure $columnIds */ @@ -140,6 +143,24 @@ public function addColumnPlaceholder(string | Closure | null $placeholder): stat return $this; } + /** + * @param array|Closure|null $colors + */ + public function addColumnColors(array | Closure | null $colors): static + { + $this->addColumnColors = $colors; + + return $this; + } + + /** + * @return array + */ + public function getAddColumnColors(): array + { + return $this->evaluate($this->addColumnColors) ?? []; + } + public function canAddColumns(): bool { return $this->addColumn instanceof Closure; @@ -159,12 +180,15 @@ public function getAddColumnPlaceholder(): string return filled($placeholder) ? (string) $placeholder : __('flowforge::flowforge.column_name'); } - public function addColumn(string $name): void + public function addColumn(string $name, ?string $color = null): void { if (! $this->addColumn instanceof Closure) { return; } - $this->evaluate($this->addColumn, ['name' => $name]); + $this->evaluate($this->addColumn, [ + 'name' => $name, + 'color' => array_key_exists((string) $color, $this->getAddColumnColors()) ? $color : null, + ]); } } diff --git a/src/Modern/Concerns/InteractsWithBoard.php b/src/Modern/Concerns/InteractsWithBoard.php index bf56b4972..233445ef0 100644 --- a/src/Modern/Concerns/InteractsWithBoard.php +++ b/src/Modern/Concerns/InteractsWithBoard.php @@ -127,7 +127,7 @@ public function toggleBoardColumnCollapse(string $columnId, bool $alone = false) $this->board = $this->board($this->makeBoard()); } - public function addBoardColumn(string $name): void + public function addBoardColumn(string $name, ?string $color = null): void { $name = trim($name); @@ -138,7 +138,7 @@ public function addBoardColumn(string $name): void } try { - $this->getBoard()->addColumn($name); + $this->getBoard()->addColumn($name, $color); } catch (ValidationException $exception) { $this->addError('boardNewColumn', (string) collect($exception->errors())->flatten()->first()); diff --git a/tests/Fixtures/Modern/TestBoard.php b/tests/Fixtures/Modern/TestBoard.php index 66a1d9017..4d9f923c9 100644 --- a/tests/Fixtures/Modern/TestBoard.php +++ b/tests/Fixtures/Modern/TestBoard.php @@ -47,6 +47,10 @@ class TestBoard extends BoardPage public array $addedColumns = []; + public array $addedColumnColors = []; + + public bool $withAddColumnColors = false; + public ?string $rejectColumnName = null; public ?string $addColumnTitle = null; @@ -115,6 +119,7 @@ public function board(Board $board): Board } : null) ->addColumnUsing($this->withAddColumn ? $this->addColumnClosure(...) : null) + ->addColumnColors($this->withAddColumnColors ? ['#ff5454' => 'Red', 'blue' => 'Blue'] : null) ->addColumnLabel($this->addColumnTitle) ->addColumnPlaceholder($this->addColumnHint) ->headerToolbar($this->withHeaderToolbar) @@ -162,13 +167,14 @@ public function board(Board $board): Board ]); } - protected function addColumnClosure(string $name): void + protected function addColumnClosure(string $name, ?string $color): void { if ($name === $this->rejectColumnName) { throw ValidationException::withMessages(['name' => 'Taken']); } $this->addedColumns[] = $name; + $this->addedColumnColors[] = $color; } protected function authorizeCardMove(Model $card, string $targetColumnId, ?string $toLaneId = null): void diff --git a/tests/Modern/Feature/AddColumnTest.php b/tests/Modern/Feature/AddColumnTest.php index 9b0d34a65..147e3dc77 100644 --- a/tests/Modern/Feature/AddColumnTest.php +++ b/tests/Modern/Feature/AddColumnTest.php @@ -68,6 +68,18 @@ function headTracks(string $html, string $property): string ->assertSet('addedColumns', ['Won']); }); + test('a color from the host palette reaches the host, and any other color arrives as null', function () { + $component = Livewire::test(TestBoard::class, ['withAddColumn' => true, 'withAddColumnColors' => true]); + + expect($component->html())->toContain('aria-label="Red"')->toContain('style="--color-500:#ff5454"'); + + $component->call('addBoardColumn', 'Won', '#ff5454') + ->call('addBoardColumn', 'Lost', '#000000') + ->call('addBoardColumn', 'Paused'); + + expect($component->get('addedColumnColors'))->toBe(['#ff5454', null, null]); + }); + test('the board shows the new column in the same response', function () { Livewire::test(TestBoard::class, ['withAddColumn' => true]) ->call('addBoardColumn', 'Won') From 25ba3042b5188f9ba8054759265a776e67fa3d3e Mon Sep 17 00:00:00 2001 From: Manuk Date: Sun, 15 Nov 2026 02:45:23 +0400 Subject: [PATCH 24/34] fix(columns): scroll a new column into view and open its form on the default color --- docs/content/2.essentials/2.customization.md | 8 +++++-- resources/dist/flowforge-modern.js | 2 +- resources/js/flowforge-modern.js | 17 ++++++++++---- resources/views/modern/index.blade.php | 2 +- .../modern/livewire/add-column.blade.php | 6 +++-- .../views/modern/livewire/lanes.blade.php | 2 +- src/Board.php | 1 + src/Concerns/HasColumnControls.php | 16 ++++++++++++++ tests/Browser/ModernBoardTest.php | 22 +++++++++++++++++++ tests/Fixtures/Modern/TestBoard.php | 3 +++ tests/Modern/Feature/AddColumnTest.php | 7 ++++++ 11 files changed, 75 insertions(+), 11 deletions(-) diff --git a/docs/content/2.essentials/2.customization.md b/docs/content/2.essentials/2.customization.md index f5686acfd..8d1305e78 100644 --- a/docs/content/2.essentials/2.customization.md +++ b/docs/content/2.essentials/2.customization.md @@ -393,13 +393,17 @@ cell keeps its column. `addColumnColors()` turns the form's dot into a color picker. Pass the palette as color values keyed to their labels. The picked color reaches your closure as `$color`, and a value outside the -palette or no pick arrives as `null`: +palette or no pick arrives as `null`. `addColumnDefaultColor()` names the palette color the form +opens on, so the dot and the grid show it selected. Leaving it unpicked still sends `null`: ```php ->addColumnUsing(fn (string $name, ?string $color) => $this->addStage($name, $color ?? 'gray')) -->addColumnColors(['#ff5454' => 'Red', '#266df0' => 'Blue']) +->addColumnColors(['#ff5454' => 'Red', '#266df0' => 'Blue', '#a2a4a7' => 'Gray']) +->addColumnDefaultColor('#a2a4a7') ``` +Opening the form scrolls the board so the new column and the tile both show. + ## Search and Filtering Enable powerful search and filtering capabilities: diff --git a/resources/dist/flowforge-modern.js b/resources/dist/flowforge-modern.js index 259367a61..cbe4a3b3a 100644 --- a/resources/dist/flowforge-modern.js +++ b/resources/dist/flowforge-modern.js @@ -1 +1 @@ -var A=["--ff-surface","--ff-surface-sunken","--ff-surface-raised","--ff-border","--ff-text","--ff-text-muted","--ff-accent","--ff-accent-tint","--ff-danger","--ff-warning","--ff-radius","--ff-gap","--ff-ease","--ff-duration","--ff-column-width","--ff-tray-bg","--ff-tray-radius","--ff-card-bg","--ff-card-ring","--ff-card-radius","--ff-card-shadow","--ff-card-padding","--ff-drag-tilt","--ff-drag-shadow","--ff-placeholder-border"],c='.ff-column-actions, .fi-dropdown-panel, input, textarea, select, [contenteditable]:not([contenteditable="false"])',m=`.ff-card, .ff-column-header, .ff-add-slot, .ff-add-row, .ff-cards-more, .ff-limit-hint, button, a, ${c}`,f=4,L=300,k=e=>{let t=e.querySelector("[data-autofocus]");!t||e.style.display!=="block"||!window.matchMedia("(pointer: fine)").matches||(t.focus({preventScroll:!0}),t.setSelectionRange?.(t.value.length,t.value.length))},p=new WeakSet,h=new WeakSet,C=()=>window.Sortable.active||window.Sortable.dragged;function D(){return{isLoading:{},fullyLoaded:{},dragOverColumn:null,railToggledAt:0,railClickTimer:null,columnMenuPressAt:null,railPressAt:null,dragOverLane:null,dragSource:null,pendingCounts:{},pendingMoves:0,collapsedLanes:{},addingColumn:!1,newColumnName:"",newColumnColor:null,newColumnDotStyle:"",choosingNewColumnColor:!1,newColumnTouched:!1,addingColumnPending:!1,placeholder:null,stopTrackingPointer:null,init(){this.$wire.$on("kanban-items-loaded",e=>{let{columnId:t,isFullyLoaded:o}=e;o&&(this.fullyLoaded[t]=!0)})},configureSortable(e){if(!e.sortable||e.sortable.options.forceFallback)return;if(C()){this.configureSortableAfterDrag(e);return}let t=window.matchMedia("(prefers-reduced-motion: reduce)").matches;e.sortable.destroy(),e.sortable=window.Sortable.create(e,{draggable:"[x-sortable-item]",handle:"[x-sortable-handle]",dataIdAttr:"x-sortable-item",forceFallback:!0,fallbackTolerance:5,fallbackOnBody:!0,fallbackClass:"",ghostClass:"",delay:150,delayOnTouchOnly:!0,animation:t?0:200,scrollSensitivity:100,scrollSpeed:15,forceAutoScrollFallback:!0,group:{name:e.getAttribute("x-sortable-group"),pull:!0,put:(o,n)=>this.canDrop(o.el,n.el)},onStart:o=>this.startDrag(o),onEnd(o){let{item:n,to:r,oldDraggableIndex:s,newDraggableIndex:a}=o;if(s===a)return;let i=r.querySelectorAll(`:scope > ${this.options.draggable}`)[a-1];i&&r.insertBefore(n,i.nextSibling)}})},configureSortableAfterDrag(e){if(h.has(e))return;h.add(e);let t=()=>{if(C()){requestAnimationFrame(t);return}h.delete(e),e.isConnected&&this.configureSortable(e)};requestAnimationFrame(t)},startDrag(e){this.stopTrackingPointer?.(),this.placeholder=e.item,this.placeholder.setAttribute("data-placeholder",""),this.markGhost(),window.getSelection()?.removeAllRanges(),document.documentElement.classList.add("ff-dragging"),this.dragSource={column:e.from.dataset.columnId,lane:e.from.dataset.laneId??null};let t=o=>this.trackPointer(o);document.addEventListener("pointermove",t,{passive:!0}),document.addEventListener("touchmove",t,{passive:!0}),this.stopTrackingPointer=()=>{document.removeEventListener("pointermove",t),document.removeEventListener("touchmove",t)}},trackPointer(e){if(!window.Sortable.active){this.endDrag();return}this.markGhost();let t=e.touches?.[0]??e,o=document.elementFromPoint(t.clientX,t.clientY),n=o?.closest("[data-column-id]"),r=o?.closest("[data-column-root]");this.dragOverColumn=n?.dataset.columnId??r?.dataset.columnRoot??null,this.dragOverLane=n?.dataset.laneId??null},markGhost(){let e=window.Sortable.ghost;if(!e||e.hasAttribute("data-dragging"))return;e.removeAttribute("data-placeholder"),e.setAttribute("data-dragging",""),e.style.opacity="1";let t=getComputedStyle(this.placeholder);for(let o of A){let n=t.getPropertyValue(o);n!==""&&e.style.setProperty(o,n)}},endDrag(){document.documentElement.classList.remove("ff-dragging"),this.placeholder?.removeAttribute("data-placeholder"),this.placeholder=null,this.stopTrackingPointer?.(),this.stopTrackingPointer=null,this.dragOverColumn=null,this.dragOverLane=null,this.dragSource=null},railPress(e){this.railPressAt={x:e.clientX,y:e.clientY}},toggleColumnCollapse(e,t,o=!1){if(!(e.target.closest(c)||o&&e.detail>1)){if(o){let n=this.railPressAt;if(this.railPressAt=null,n&&Math.hypot(e.clientX-n.x,e.clientY-n.y)>f)return}Date.now()-this.railToggledAt<500||(o&&(this.railToggledAt=Date.now()),this.$wire.toggleBoardColumnCollapse(t))}},expandFromCollapseAll(e,t){let o=this.railPressAt;if(this.railPressAt=null,e.target.closest(c)||o&&Math.hypot(e.clientX-o.x,e.clientY-o.y)>f)return;let n=e.detail>1;clearTimeout(this.railClickTimer),this.railClickTimer=setTimeout(()=>{this.railToggledAt=Date.now(),this.$wire.toggleBoardColumnCollapse(t,n)},n?0:L)},collapseFromEmptySpace(e,t){e.target.closest(m)||this.toggleColumnCollapse(e,t)},suppressEmptySpaceSelection(e){e.detail>1&&!e.target.closest(m)&&e.preventDefault()},openNewColumn(){this.addingColumn=!0,this.newColumnTouched=!0,this.$nextTick(()=>requestAnimationFrame(()=>{this.$refs.newColumnInput.focus({preventScroll:!0}),this.$refs.newColumnInput.scrollIntoView({block:"nearest",inline:"nearest"})}))},cancelNewColumn(){this.addingColumn=!1,this.newColumnTouched=!0,this.newColumnName="",this.newColumnColor=null,this.newColumnDotStyle="",this.choosingNewColumnColor=!1},pickNewColumnColor(e,t){this.newColumnColor=e,this.newColumnDotStyle=t,this.choosingNewColumnColor=!1,this.$refs.newColumnInput.focus({preventScroll:!0})},async submitNewColumn(){if(!this.addingColumnPending){this.addingColumnPending=!0,this.newColumnTouched=!0;try{await this.$wire.addBoardColumn(this.newColumnName,this.newColumnColor)}finally{this.addingColumnPending=!1}this.newColumnTouched=!1,this.$root.querySelector(".ff-add-column-error")||this.cancelNewColumn()}},suppressDoubleClickSelection(e){e.detail>1&&!e.target.closest(c)&&e.preventDefault()},initColumnMenu(e){let t=e.closest(".fi-dropdown");if(p.has(t))return;let o=window.Alpine.$data(t),n=o.toggle.bind(o);p.add(t),o.toggle=r=>r?.type==="mousedown"?void 0:n(r)},columnMenuPress(e){this.columnMenuPressAt={x:e.clientX,y:e.clientY}},columnMenuClick(e){let t=this.columnMenuPressAt;if(this.columnMenuPressAt=null,e.detail>1||t&&Math.hypot(e.clientX-t.x,e.clientY-t.y)>f)return;let o=e.currentTarget.closest(".fi-dropdown");window.Alpine.$data(o).toggle(e),requestAnimationFrame(()=>k(o.querySelector(":scope > .fi-dropdown-panel")))},columnDrop(e){return this.dragOverColumn!==e?null:this.isColumnBlocked(e)?"blocked":"active"},cellDrop(e,t){return this.dragOverColumn!==e||this.dragOverLane!==t?null:this.isCellBlocked(e,t)?"blocked":"active"},canDrop(e,t){if(!this.$root.contains(e)||!this.$root.contains(t))return!1;let o=e.dataset.laneId??null,n=t.dataset.laneId??null;return o!==n&&this.$root.dataset.lanesWritable!=="true"?!1:!this.isColumnBlocked(e.dataset.columnId,t.dataset.columnId)},isColumnBlocked(e,t=this.dragSource?.column){if(!e||e===t)return!1;let o=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"]`),n=o?.dataset.columnLimit;return n===void 0||n===""?!1:Number(o.dataset.columnTotal)>=Number(n)},isCellBlocked(e,t){return this.dragSource?t!==this.dragSource.lane&&this.$root.dataset.lanesWritable!=="true"?!0:this.isColumnBlocked(e):!1},displayCount(e,t){let o=this.pendingCounts[e]??t,n=this.dragSource?.column,r=this.dragOverColumn;return!n||!r||n===r||this.isColumnBlocked(r)?o:e===r?o+1:e===n?o-1:o},holdMovedCounts(e,t){if(e===t)return()=>{};let o={[e]:-1,[t]:1},n=!1;for(let[r,s]of Object.entries(o))this.pendingCounts[r]=this.renderedCount(r)+s;return this.pendingMoves++,r=>{if(!n){if(n=!0,r)for(let[s,a]of Object.entries(o))this.pendingCounts[s]-=a;--this.pendingMoves===0&&(this.pendingCounts={})}}},renderedCount(e){let t=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"] .ff-count`);return this.pendingCounts[e]??Number(t?.dataset.total)},handleSortableEnd(e){this.endDrag();let t=e.item,o=e.to,n=e.newDraggableIndex??e.newIndex,r=":scope > [x-sortable-item], :scope > [data-card-id]",s=l=>l.getAttribute("x-sortable-item")||l.getAttribute("data-card-id");if(e.from===o&&e.oldDraggableIndex===e.newDraggableIndex)return;if(n===0){let l=o.querySelector(r);l&&l!==t&&o.insertBefore(t,l)}let a=s(t);if(!a){console.error("Flowforge: Could not determine card ID for move operation");return}let i=o.getAttribute("data-column-id");if(!i){console.error("Flowforge: Target column ID is missing");return}let w=e.from.dataset.laneId??null,b=o.dataset.laneId??null,u=o.querySelectorAll(r),d=Array.prototype.indexOf.call(u,t),S=d>0?s(u[d-1]):null,y=d>=0&&d{this.setCardState(t,!1),g(l===!1),l===!1&&this.revertCard(e)}).catch(()=>{this.setCardState(t,!1),g(!0),this.revertCard(e)})},revertCard({item:e,from:t,oldDraggableIndex:o}){e.remove();let n=t.querySelectorAll(":scope > [x-sortable-item]"),r=n[n.length-1],s=n[o]??(r?r.nextSibling:t.firstChild);t.insertBefore(e,s)},setCardState(e,t){e.toggleAttribute("data-pending",t)},isLaneCollapsed(e){return this.collapsedLanes[e]===!0},toggleLane(e){this.collapsedLanes[e]=!this.isLaneCollapsed(e)},isLoadingColumn(e){return this.isLoading[e]||!1},isColumnFullyLoaded(e){return this.fullyLoaded[e]||!1},handleSmoothScroll(e){this.isLoadingColumn(e)||this.isColumnFullyLoaded(e)||(this.isLoading[e]=!0,this.$wire.loadMoreItems(e).then(()=>setTimeout(()=>this.isLoading[e]=!1,100)).catch(()=>this.isLoading[e]=!1))},handleColumnScroll(e,t){if(this.isColumnFullyLoaded(t))return;let{scrollTop:o,scrollHeight:n,clientHeight:r}=e.target;(o+r)/n>=.8&&!this.isLoadingColumn(t)&&this.handleSmoothScroll(t)}}}export{D as default}; +var A=["--ff-surface","--ff-surface-sunken","--ff-surface-raised","--ff-border","--ff-text","--ff-text-muted","--ff-accent","--ff-accent-tint","--ff-danger","--ff-warning","--ff-radius","--ff-gap","--ff-ease","--ff-duration","--ff-column-width","--ff-tray-bg","--ff-tray-radius","--ff-card-bg","--ff-card-ring","--ff-card-radius","--ff-card-shadow","--ff-card-padding","--ff-drag-tilt","--ff-drag-shadow","--ff-placeholder-border"],c='.ff-column-actions, .fi-dropdown-panel, input, textarea, select, [contenteditable]:not([contenteditable="false"])',m=`.ff-card, .ff-column-header, .ff-add-slot, .ff-add-row, .ff-cards-more, .ff-limit-hint, button, a, ${c}`,f=4,k=300,L=e=>{let t=e.querySelector("[data-autofocus]");!t||e.style.display!=="block"||!window.matchMedia("(pointer: fine)").matches||(t.focus({preventScroll:!0}),t.setSelectionRange?.(t.value.length,t.value.length))},C=new WeakSet,h=new WeakSet,p=()=>window.Sortable.active||window.Sortable.dragged;function D(){return{isLoading:{},fullyLoaded:{},dragOverColumn:null,railToggledAt:0,railClickTimer:null,columnMenuPressAt:null,railPressAt:null,dragOverLane:null,dragSource:null,pendingCounts:{},pendingMoves:0,collapsedLanes:{},addingColumn:!1,newColumnName:"",newColumnColor:null,newColumnDotStyle:"",newColumnColorPicked:!1,choosingNewColumnColor:!1,newColumnTouched:!1,addingColumnPending:!1,placeholder:null,stopTrackingPointer:null,init(){this.$wire.$on("kanban-items-loaded",e=>{let{columnId:t,isFullyLoaded:o}=e;o&&(this.fullyLoaded[t]=!0)})},configureSortable(e){if(!e.sortable||e.sortable.options.forceFallback)return;if(p()){this.configureSortableAfterDrag(e);return}let t=window.matchMedia("(prefers-reduced-motion: reduce)").matches;e.sortable.destroy(),e.sortable=window.Sortable.create(e,{draggable:"[x-sortable-item]",handle:"[x-sortable-handle]",dataIdAttr:"x-sortable-item",forceFallback:!0,fallbackTolerance:5,fallbackOnBody:!0,fallbackClass:"",ghostClass:"",delay:150,delayOnTouchOnly:!0,animation:t?0:200,scrollSensitivity:100,scrollSpeed:15,forceAutoScrollFallback:!0,group:{name:e.getAttribute("x-sortable-group"),pull:!0,put:(o,n)=>this.canDrop(o.el,n.el)},onStart:o=>this.startDrag(o),onEnd(o){let{item:n,to:r,oldDraggableIndex:l,newDraggableIndex:a}=o;if(l===a)return;let i=r.querySelectorAll(`:scope > ${this.options.draggable}`)[a-1];i&&r.insertBefore(n,i.nextSibling)}})},configureSortableAfterDrag(e){if(h.has(e))return;h.add(e);let t=()=>{if(p()){requestAnimationFrame(t);return}h.delete(e),e.isConnected&&this.configureSortable(e)};requestAnimationFrame(t)},startDrag(e){this.stopTrackingPointer?.(),this.placeholder=e.item,this.placeholder.setAttribute("data-placeholder",""),this.markGhost(),window.getSelection()?.removeAllRanges(),document.documentElement.classList.add("ff-dragging"),this.dragSource={column:e.from.dataset.columnId,lane:e.from.dataset.laneId??null};let t=o=>this.trackPointer(o);document.addEventListener("pointermove",t,{passive:!0}),document.addEventListener("touchmove",t,{passive:!0}),this.stopTrackingPointer=()=>{document.removeEventListener("pointermove",t),document.removeEventListener("touchmove",t)}},trackPointer(e){if(!window.Sortable.active){this.endDrag();return}this.markGhost();let t=e.touches?.[0]??e,o=document.elementFromPoint(t.clientX,t.clientY),n=o?.closest("[data-column-id]"),r=o?.closest("[data-column-root]");this.dragOverColumn=n?.dataset.columnId??r?.dataset.columnRoot??null,this.dragOverLane=n?.dataset.laneId??null},markGhost(){let e=window.Sortable.ghost;if(!e||e.hasAttribute("data-dragging"))return;e.removeAttribute("data-placeholder"),e.setAttribute("data-dragging",""),e.style.opacity="1";let t=getComputedStyle(this.placeholder);for(let o of A){let n=t.getPropertyValue(o);n!==""&&e.style.setProperty(o,n)}},endDrag(){document.documentElement.classList.remove("ff-dragging"),this.placeholder?.removeAttribute("data-placeholder"),this.placeholder=null,this.stopTrackingPointer?.(),this.stopTrackingPointer=null,this.dragOverColumn=null,this.dragOverLane=null,this.dragSource=null},railPress(e){this.railPressAt={x:e.clientX,y:e.clientY}},toggleColumnCollapse(e,t,o=!1){if(!(e.target.closest(c)||o&&e.detail>1)){if(o){let n=this.railPressAt;if(this.railPressAt=null,n&&Math.hypot(e.clientX-n.x,e.clientY-n.y)>f)return}Date.now()-this.railToggledAt<500||(o&&(this.railToggledAt=Date.now()),this.$wire.toggleBoardColumnCollapse(t))}},expandFromCollapseAll(e,t){let o=this.railPressAt;if(this.railPressAt=null,e.target.closest(c)||o&&Math.hypot(e.clientX-o.x,e.clientY-o.y)>f)return;let n=e.detail>1;clearTimeout(this.railClickTimer),this.railClickTimer=setTimeout(()=>{this.railToggledAt=Date.now(),this.$wire.toggleBoardColumnCollapse(t,n)},n?0:k)},collapseFromEmptySpace(e,t){e.target.closest(m)||this.toggleColumnCollapse(e,t)},suppressEmptySpaceSelection(e){e.detail>1&&!e.target.closest(m)&&e.preventDefault()},openNewColumn(e=null,t=""){this.addingColumn=!0,this.newColumnTouched=!0,this.newColumnColor=e,this.newColumnDotStyle=t,this.newColumnColorPicked=!1,this.$nextTick(()=>requestAnimationFrame(()=>{let o=this.$refs.newColumnInput,n=o.closest(".ff-add-column"),r=n.closest(".ff-lanes-heads")?o.closest(".ff-add-column-ghost"):n;o.focus({preventScroll:!0}),r.scrollIntoView({block:"nearest",inline:"end"})}))},cancelNewColumn(){this.addingColumn=!1,this.newColumnTouched=!0,this.newColumnName="",this.newColumnColor=null,this.newColumnDotStyle="",this.choosingNewColumnColor=!1},pickNewColumnColor(e,t){this.newColumnColorPicked=!0,this.newColumnColor=e,this.newColumnDotStyle=t,this.choosingNewColumnColor=!1,this.$refs.newColumnInput.focus({preventScroll:!0})},async submitNewColumn(){if(!this.addingColumnPending){this.addingColumnPending=!0,this.newColumnTouched=!0;try{await this.$wire.addBoardColumn(this.newColumnName,this.newColumnColorPicked?this.newColumnColor:null)}finally{this.addingColumnPending=!1}this.newColumnTouched=!1,this.$root.querySelector(".ff-add-column-error")||this.cancelNewColumn()}},suppressDoubleClickSelection(e){e.detail>1&&!e.target.closest(c)&&e.preventDefault()},initColumnMenu(e){let t=e.closest(".fi-dropdown");if(C.has(t))return;let o=window.Alpine.$data(t),n=o.toggle.bind(o);C.add(t),o.toggle=r=>r?.type==="mousedown"?void 0:n(r)},columnMenuPress(e){this.columnMenuPressAt={x:e.clientX,y:e.clientY}},columnMenuClick(e){let t=this.columnMenuPressAt;if(this.columnMenuPressAt=null,e.detail>1||t&&Math.hypot(e.clientX-t.x,e.clientY-t.y)>f)return;let o=e.currentTarget.closest(".fi-dropdown");window.Alpine.$data(o).toggle(e),requestAnimationFrame(()=>L(o.querySelector(":scope > .fi-dropdown-panel")))},columnDrop(e){return this.dragOverColumn!==e?null:this.isColumnBlocked(e)?"blocked":"active"},cellDrop(e,t){return this.dragOverColumn!==e||this.dragOverLane!==t?null:this.isCellBlocked(e,t)?"blocked":"active"},canDrop(e,t){if(!this.$root.contains(e)||!this.$root.contains(t))return!1;let o=e.dataset.laneId??null,n=t.dataset.laneId??null;return o!==n&&this.$root.dataset.lanesWritable!=="true"?!1:!this.isColumnBlocked(e.dataset.columnId,t.dataset.columnId)},isColumnBlocked(e,t=this.dragSource?.column){if(!e||e===t)return!1;let o=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"]`),n=o?.dataset.columnLimit;return n===void 0||n===""?!1:Number(o.dataset.columnTotal)>=Number(n)},isCellBlocked(e,t){return this.dragSource?t!==this.dragSource.lane&&this.$root.dataset.lanesWritable!=="true"?!0:this.isColumnBlocked(e):!1},displayCount(e,t){let o=this.pendingCounts[e]??t,n=this.dragSource?.column,r=this.dragOverColumn;return!n||!r||n===r||this.isColumnBlocked(r)?o:e===r?o+1:e===n?o-1:o},holdMovedCounts(e,t){if(e===t)return()=>{};let o={[e]:-1,[t]:1},n=!1;for(let[r,l]of Object.entries(o))this.pendingCounts[r]=this.renderedCount(r)+l;return this.pendingMoves++,r=>{if(!n){if(n=!0,r)for(let[l,a]of Object.entries(o))this.pendingCounts[l]-=a;--this.pendingMoves===0&&(this.pendingCounts={})}}},renderedCount(e){let t=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"] .ff-count`);return this.pendingCounts[e]??Number(t?.dataset.total)},handleSortableEnd(e){this.endDrag();let t=e.item,o=e.to,n=e.newDraggableIndex??e.newIndex,r=":scope > [x-sortable-item], :scope > [data-card-id]",l=s=>s.getAttribute("x-sortable-item")||s.getAttribute("data-card-id");if(e.from===o&&e.oldDraggableIndex===e.newDraggableIndex)return;if(n===0){let s=o.querySelector(r);s&&s!==t&&o.insertBefore(t,s)}let a=l(t);if(!a){console.error("Flowforge: Could not determine card ID for move operation");return}let i=o.getAttribute("data-column-id");if(!i){console.error("Flowforge: Target column ID is missing");return}let w=e.from.dataset.laneId??null,b=o.dataset.laneId??null,u=o.querySelectorAll(r),d=Array.prototype.indexOf.call(u,t),S=d>0?l(u[d-1]):null,y=d>=0&&d{this.setCardState(t,!1),g(s===!1),s===!1&&this.revertCard(e)}).catch(()=>{this.setCardState(t,!1),g(!0),this.revertCard(e)})},revertCard({item:e,from:t,oldDraggableIndex:o}){e.remove();let n=t.querySelectorAll(":scope > [x-sortable-item]"),r=n[n.length-1],l=n[o]??(r?r.nextSibling:t.firstChild);t.insertBefore(e,l)},setCardState(e,t){e.toggleAttribute("data-pending",t)},isLaneCollapsed(e){return this.collapsedLanes[e]===!0},toggleLane(e){this.collapsedLanes[e]=!this.isLaneCollapsed(e)},isLoadingColumn(e){return this.isLoading[e]||!1},isColumnFullyLoaded(e){return this.fullyLoaded[e]||!1},handleSmoothScroll(e){this.isLoadingColumn(e)||this.isColumnFullyLoaded(e)||(this.isLoading[e]=!0,this.$wire.loadMoreItems(e).then(()=>setTimeout(()=>this.isLoading[e]=!1,100)).catch(()=>this.isLoading[e]=!1))},handleColumnScroll(e,t){if(this.isColumnFullyLoaded(t))return;let{scrollTop:o,scrollHeight:n,clientHeight:r}=e.target;(o+r)/n>=.8&&!this.isLoadingColumn(t)&&this.handleSmoothScroll(t)}}}export{D as default}; diff --git a/resources/js/flowforge-modern.js b/resources/js/flowforge-modern.js index f68f19e92..7901f4eca 100644 --- a/resources/js/flowforge-modern.js +++ b/resources/js/flowforge-modern.js @@ -72,6 +72,7 @@ export default function flowforgeModern() { newColumnName: '', newColumnColor: null, newColumnDotStyle: '', + newColumnColorPicked: false, choosingNewColumnColor: false, newColumnTouched: false, addingColumnPending: false, @@ -309,13 +310,20 @@ export default function flowforgeModern() { } }, - openNewColumn() { + openNewColumn(defaultColor = null, defaultStyle = '') { this.addingColumn = true; this.newColumnTouched = true; + this.newColumnColor = defaultColor; + this.newColumnDotStyle = defaultStyle; + this.newColumnColorPicked = false; // WebKit ignores a focus on the next tick, right after the ghost column shows. One frame later it takes it. this.$nextTick(() => requestAnimationFrame(() => { - this.$refs.newColumnInput.focus({ preventScroll: true }); - this.$refs.newColumnInput.scrollIntoView({ block: 'nearest', inline: 'nearest' }); + const input = this.$refs.newColumnInput; + const addColumn = input.closest('.ff-add-column'); + const shown = addColumn.closest('.ff-lanes-heads') ? input.closest('.ff-add-column-ghost') : addColumn; + + input.focus({ preventScroll: true }); + shown.scrollIntoView({ block: 'nearest', inline: 'end' }); })); }, @@ -329,6 +337,7 @@ export default function flowforgeModern() { }, pickNewColumnColor(color, style) { + this.newColumnColorPicked = true; this.newColumnColor = color; this.newColumnDotStyle = style; this.choosingNewColumnColor = false; @@ -344,7 +353,7 @@ export default function flowforgeModern() { this.newColumnTouched = true; try { - await this.$wire.addBoardColumn(this.newColumnName, this.newColumnColor); + await this.$wire.addBoardColumn(this.newColumnName, this.newColumnColorPicked ? this.newColumnColor : null); } finally { this.addingColumnPending = false; } diff --git a/resources/views/modern/index.blade.php b/resources/views/modern/index.blade.php index 99c1dd76d..dcdd55001 100644 --- a/resources/views/modern/index.blade.php +++ b/resources/views/modern/index.blade.php @@ -41,7 +41,7 @@ class="ff-board" @endforeach @if ($config['canAddColumns'] ?? false) - + @endif
@endif diff --git a/resources/views/modern/livewire/add-column.blade.php b/resources/views/modern/livewire/add-column.blade.php index 4c75cd4e6..ddeef933d 100644 --- a/resources/views/modern/livewire/add-column.blade.php +++ b/resources/views/modern/livewire/add-column.blade.php @@ -1,7 +1,9 @@ -@props(['label', 'placeholder', 'colors' => []]) +@props(['label', 'placeholder', 'colors' => [], 'defaultColor' => null]) @php use Filament\Support\Enums\IconSize; + + $defaultStyle = collect($colors)->firstWhere('value', $defaultColor)['style'] ?? ''; @endphp
@@ -66,7 +68,7 @@ class="ff-add-column-input" class="ff-add-column-button" title="{{ $label }}" aria-label="{{ $label }}" - x-on:click="openNewColumn()" + x-on:click="openNewColumn(@js($defaultColor), @js($defaultStyle))" > diff --git a/resources/views/modern/livewire/lanes.blade.php b/resources/views/modern/livewire/lanes.blade.php index abdf43967..c669778de 100644 --- a/resources/views/modern/livewire/lanes.blade.php +++ b/resources/views/modern/livewire/lanes.blade.php @@ -46,7 +46,7 @@ class="ff-column" @endforeach @if ($canAddColumns) - + @endif
diff --git a/src/Board.php b/src/Board.php index 6cfb17a17..b7b7f9021 100644 --- a/src/Board.php +++ b/src/Board.php @@ -138,6 +138,7 @@ public function getViewData(): array array_keys($this->getAddColumnColors()), $this->getAddColumnColors(), ), + 'addColumnDefaultColor' => $this->getAddColumnDefaultColor(), 'collapseEmptyColumns' => $grouping === null && $this->collapsesEmptyColumns() && array_sum(array_column($columns, 'total')) > 0, diff --git a/src/Concerns/HasColumnControls.php b/src/Concerns/HasColumnControls.php index 287aa5fa7..e026b62fe 100644 --- a/src/Concerns/HasColumnControls.php +++ b/src/Concerns/HasColumnControls.php @@ -30,6 +30,8 @@ trait HasColumnControls /** @var array|Closure|null */ protected array | Closure | null $addColumnColors = null; + protected string | Closure | null $addColumnDefaultColor = null; + /** * @param array|Closure $columnIds */ @@ -161,6 +163,20 @@ public function getAddColumnColors(): array return $this->evaluate($this->addColumnColors) ?? []; } + public function addColumnDefaultColor(string | Closure | null $color): static + { + $this->addColumnDefaultColor = $color; + + return $this; + } + + public function getAddColumnDefaultColor(): ?string + { + $color = $this->evaluate($this->addColumnDefaultColor); + + return is_string($color) && array_key_exists($color, $this->getAddColumnColors()) ? $color : null; + } + public function canAddColumns(): bool { return $this->addColumn instanceof Closure; diff --git a/tests/Browser/ModernBoardTest.php b/tests/Browser/ModernBoardTest.php index 13b53de7d..a35bd4062 100644 --- a/tests/Browser/ModernBoardTest.php +++ b/tests/Browser/ModernBoardTest.php @@ -1188,6 +1188,27 @@ function boardTraySampler(int $budgetMilliseconds): string expect($page->script($reachable))->toBeTrue(); }); +test('opening the add column form scrolls the new column and the tile into the board', function () { + boardSeed(); + $page = boardPage('/modern/test-add-column-board'); + $pointer = Pointer::on($page); + + $page->script("document.querySelector('.ff-columns').style.width = '700px'"); + $page->script("const columns = document.querySelector('.ff-columns'); columns.scrollLeft = columns.scrollWidth"); + $pointer->click('.ff-add-column-button'); + $pointer->untilScript("document.activeElement === document.querySelector('.ff-add-column-input')"); + + expect($page->script(<<<'JS' + (() => { + const board = document.querySelector('.ff-columns').getBoundingClientRect(); + const ghost = document.querySelector('.ff-add-column-ghost').getBoundingClientRect(); + const tile = document.querySelector('.ff-add-column-button').getBoundingClientRect(); + + return ghost.left >= board.left - 0.5 && tile.right <= board.right + 0.5; + })() + JS))->toBeTrue(); +}); + test('the add column form opens as a column before the tile and an outside click closes it', function () { boardSeed(); $page = boardPage('/modern/test-add-column-board'); @@ -1209,6 +1230,7 @@ function boardTraySampler(int $budgetMilliseconds): string expect($geometry)->toBe([true, true, true, 'visible']); $page->script("document.querySelector('.ff-add-column-input').value = 'Draft'"); + $page->script("document.querySelector('.ff-columns').scrollLeft = 0"); $pointer->click('[data-column-root="todo"] .ff-column-title'); $pointer->untilScript("getComputedStyle(document.querySelector('.ff-add-column-ghost')).display === 'none'"); }); diff --git a/tests/Fixtures/Modern/TestBoard.php b/tests/Fixtures/Modern/TestBoard.php index 4d9f923c9..9333ac047 100644 --- a/tests/Fixtures/Modern/TestBoard.php +++ b/tests/Fixtures/Modern/TestBoard.php @@ -51,6 +51,8 @@ class TestBoard extends BoardPage public bool $withAddColumnColors = false; + public ?string $addColumnDefault = null; + public ?string $rejectColumnName = null; public ?string $addColumnTitle = null; @@ -120,6 +122,7 @@ public function board(Board $board): Board : null) ->addColumnUsing($this->withAddColumn ? $this->addColumnClosure(...) : null) ->addColumnColors($this->withAddColumnColors ? ['#ff5454' => 'Red', 'blue' => 'Blue'] : null) + ->addColumnDefaultColor($this->addColumnDefault) ->addColumnLabel($this->addColumnTitle) ->addColumnPlaceholder($this->addColumnHint) ->headerToolbar($this->withHeaderToolbar) diff --git a/tests/Modern/Feature/AddColumnTest.php b/tests/Modern/Feature/AddColumnTest.php index 147e3dc77..90f112f8c 100644 --- a/tests/Modern/Feature/AddColumnTest.php +++ b/tests/Modern/Feature/AddColumnTest.php @@ -80,6 +80,13 @@ function headTracks(string $html, string $property): string expect($component->get('addedColumnColors'))->toBe(['#ff5454', null, null]); }); + test('the form opens on the default color when it is in the palette', function () { + $board = fn (string $default) => Livewire::test(TestBoard::class, ['withAddColumn' => true, 'withAddColumnColors' => true, 'addColumnDefault' => $default])->instance()->getBoard(); + + expect($board('blue')->getAddColumnDefaultColor())->toBe('blue') + ->and($board('#000000')->getAddColumnDefaultColor())->toBeNull(); + }); + test('the board shows the new column in the same response', function () { Livewire::test(TestBoard::class, ['withAddColumn' => true]) ->call('addBoardColumn', 'Won') From 18dbc197cf96700a6c6c06c9f7e1e21a665ff419 Mon Sep 17 00:00:00 2001 From: Manuk Date: Sun, 15 Nov 2026 02:50:34 +0400 Subject: [PATCH 25/34] fix(columns): scroll the board to its end when a new column opens --- docs/content/2.essentials/2.customization.md | 2 +- resources/dist/flowforge-modern.js | 2 +- resources/js/flowforge-modern.js | 6 +++--- tests/Browser/ModernBoardTest.php | 10 +++++++++- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/docs/content/2.essentials/2.customization.md b/docs/content/2.essentials/2.customization.md index 8d1305e78..06497541f 100644 --- a/docs/content/2.essentials/2.customization.md +++ b/docs/content/2.essentials/2.customization.md @@ -402,7 +402,7 @@ opens on, so the dot and the grid show it selected. Leaving it unpicked still se ->addColumnDefaultColor('#a2a4a7') ``` -Opening the form scrolls the board so the new column and the tile both show. +Opening the form scrolls the board to its end, so the new column and the tile both show. ## Search and Filtering diff --git a/resources/dist/flowforge-modern.js b/resources/dist/flowforge-modern.js index cbe4a3b3a..3def65616 100644 --- a/resources/dist/flowforge-modern.js +++ b/resources/dist/flowforge-modern.js @@ -1 +1 @@ -var A=["--ff-surface","--ff-surface-sunken","--ff-surface-raised","--ff-border","--ff-text","--ff-text-muted","--ff-accent","--ff-accent-tint","--ff-danger","--ff-warning","--ff-radius","--ff-gap","--ff-ease","--ff-duration","--ff-column-width","--ff-tray-bg","--ff-tray-radius","--ff-card-bg","--ff-card-ring","--ff-card-radius","--ff-card-shadow","--ff-card-padding","--ff-drag-tilt","--ff-drag-shadow","--ff-placeholder-border"],c='.ff-column-actions, .fi-dropdown-panel, input, textarea, select, [contenteditable]:not([contenteditable="false"])',m=`.ff-card, .ff-column-header, .ff-add-slot, .ff-add-row, .ff-cards-more, .ff-limit-hint, button, a, ${c}`,f=4,k=300,L=e=>{let t=e.querySelector("[data-autofocus]");!t||e.style.display!=="block"||!window.matchMedia("(pointer: fine)").matches||(t.focus({preventScroll:!0}),t.setSelectionRange?.(t.value.length,t.value.length))},C=new WeakSet,h=new WeakSet,p=()=>window.Sortable.active||window.Sortable.dragged;function D(){return{isLoading:{},fullyLoaded:{},dragOverColumn:null,railToggledAt:0,railClickTimer:null,columnMenuPressAt:null,railPressAt:null,dragOverLane:null,dragSource:null,pendingCounts:{},pendingMoves:0,collapsedLanes:{},addingColumn:!1,newColumnName:"",newColumnColor:null,newColumnDotStyle:"",newColumnColorPicked:!1,choosingNewColumnColor:!1,newColumnTouched:!1,addingColumnPending:!1,placeholder:null,stopTrackingPointer:null,init(){this.$wire.$on("kanban-items-loaded",e=>{let{columnId:t,isFullyLoaded:o}=e;o&&(this.fullyLoaded[t]=!0)})},configureSortable(e){if(!e.sortable||e.sortable.options.forceFallback)return;if(p()){this.configureSortableAfterDrag(e);return}let t=window.matchMedia("(prefers-reduced-motion: reduce)").matches;e.sortable.destroy(),e.sortable=window.Sortable.create(e,{draggable:"[x-sortable-item]",handle:"[x-sortable-handle]",dataIdAttr:"x-sortable-item",forceFallback:!0,fallbackTolerance:5,fallbackOnBody:!0,fallbackClass:"",ghostClass:"",delay:150,delayOnTouchOnly:!0,animation:t?0:200,scrollSensitivity:100,scrollSpeed:15,forceAutoScrollFallback:!0,group:{name:e.getAttribute("x-sortable-group"),pull:!0,put:(o,n)=>this.canDrop(o.el,n.el)},onStart:o=>this.startDrag(o),onEnd(o){let{item:n,to:r,oldDraggableIndex:l,newDraggableIndex:a}=o;if(l===a)return;let i=r.querySelectorAll(`:scope > ${this.options.draggable}`)[a-1];i&&r.insertBefore(n,i.nextSibling)}})},configureSortableAfterDrag(e){if(h.has(e))return;h.add(e);let t=()=>{if(p()){requestAnimationFrame(t);return}h.delete(e),e.isConnected&&this.configureSortable(e)};requestAnimationFrame(t)},startDrag(e){this.stopTrackingPointer?.(),this.placeholder=e.item,this.placeholder.setAttribute("data-placeholder",""),this.markGhost(),window.getSelection()?.removeAllRanges(),document.documentElement.classList.add("ff-dragging"),this.dragSource={column:e.from.dataset.columnId,lane:e.from.dataset.laneId??null};let t=o=>this.trackPointer(o);document.addEventListener("pointermove",t,{passive:!0}),document.addEventListener("touchmove",t,{passive:!0}),this.stopTrackingPointer=()=>{document.removeEventListener("pointermove",t),document.removeEventListener("touchmove",t)}},trackPointer(e){if(!window.Sortable.active){this.endDrag();return}this.markGhost();let t=e.touches?.[0]??e,o=document.elementFromPoint(t.clientX,t.clientY),n=o?.closest("[data-column-id]"),r=o?.closest("[data-column-root]");this.dragOverColumn=n?.dataset.columnId??r?.dataset.columnRoot??null,this.dragOverLane=n?.dataset.laneId??null},markGhost(){let e=window.Sortable.ghost;if(!e||e.hasAttribute("data-dragging"))return;e.removeAttribute("data-placeholder"),e.setAttribute("data-dragging",""),e.style.opacity="1";let t=getComputedStyle(this.placeholder);for(let o of A){let n=t.getPropertyValue(o);n!==""&&e.style.setProperty(o,n)}},endDrag(){document.documentElement.classList.remove("ff-dragging"),this.placeholder?.removeAttribute("data-placeholder"),this.placeholder=null,this.stopTrackingPointer?.(),this.stopTrackingPointer=null,this.dragOverColumn=null,this.dragOverLane=null,this.dragSource=null},railPress(e){this.railPressAt={x:e.clientX,y:e.clientY}},toggleColumnCollapse(e,t,o=!1){if(!(e.target.closest(c)||o&&e.detail>1)){if(o){let n=this.railPressAt;if(this.railPressAt=null,n&&Math.hypot(e.clientX-n.x,e.clientY-n.y)>f)return}Date.now()-this.railToggledAt<500||(o&&(this.railToggledAt=Date.now()),this.$wire.toggleBoardColumnCollapse(t))}},expandFromCollapseAll(e,t){let o=this.railPressAt;if(this.railPressAt=null,e.target.closest(c)||o&&Math.hypot(e.clientX-o.x,e.clientY-o.y)>f)return;let n=e.detail>1;clearTimeout(this.railClickTimer),this.railClickTimer=setTimeout(()=>{this.railToggledAt=Date.now(),this.$wire.toggleBoardColumnCollapse(t,n)},n?0:k)},collapseFromEmptySpace(e,t){e.target.closest(m)||this.toggleColumnCollapse(e,t)},suppressEmptySpaceSelection(e){e.detail>1&&!e.target.closest(m)&&e.preventDefault()},openNewColumn(e=null,t=""){this.addingColumn=!0,this.newColumnTouched=!0,this.newColumnColor=e,this.newColumnDotStyle=t,this.newColumnColorPicked=!1,this.$nextTick(()=>requestAnimationFrame(()=>{let o=this.$refs.newColumnInput,n=o.closest(".ff-add-column"),r=n.closest(".ff-lanes-heads")?o.closest(".ff-add-column-ghost"):n;o.focus({preventScroll:!0}),r.scrollIntoView({block:"nearest",inline:"end"})}))},cancelNewColumn(){this.addingColumn=!1,this.newColumnTouched=!0,this.newColumnName="",this.newColumnColor=null,this.newColumnDotStyle="",this.choosingNewColumnColor=!1},pickNewColumnColor(e,t){this.newColumnColorPicked=!0,this.newColumnColor=e,this.newColumnDotStyle=t,this.choosingNewColumnColor=!1,this.$refs.newColumnInput.focus({preventScroll:!0})},async submitNewColumn(){if(!this.addingColumnPending){this.addingColumnPending=!0,this.newColumnTouched=!0;try{await this.$wire.addBoardColumn(this.newColumnName,this.newColumnColorPicked?this.newColumnColor:null)}finally{this.addingColumnPending=!1}this.newColumnTouched=!1,this.$root.querySelector(".ff-add-column-error")||this.cancelNewColumn()}},suppressDoubleClickSelection(e){e.detail>1&&!e.target.closest(c)&&e.preventDefault()},initColumnMenu(e){let t=e.closest(".fi-dropdown");if(C.has(t))return;let o=window.Alpine.$data(t),n=o.toggle.bind(o);C.add(t),o.toggle=r=>r?.type==="mousedown"?void 0:n(r)},columnMenuPress(e){this.columnMenuPressAt={x:e.clientX,y:e.clientY}},columnMenuClick(e){let t=this.columnMenuPressAt;if(this.columnMenuPressAt=null,e.detail>1||t&&Math.hypot(e.clientX-t.x,e.clientY-t.y)>f)return;let o=e.currentTarget.closest(".fi-dropdown");window.Alpine.$data(o).toggle(e),requestAnimationFrame(()=>L(o.querySelector(":scope > .fi-dropdown-panel")))},columnDrop(e){return this.dragOverColumn!==e?null:this.isColumnBlocked(e)?"blocked":"active"},cellDrop(e,t){return this.dragOverColumn!==e||this.dragOverLane!==t?null:this.isCellBlocked(e,t)?"blocked":"active"},canDrop(e,t){if(!this.$root.contains(e)||!this.$root.contains(t))return!1;let o=e.dataset.laneId??null,n=t.dataset.laneId??null;return o!==n&&this.$root.dataset.lanesWritable!=="true"?!1:!this.isColumnBlocked(e.dataset.columnId,t.dataset.columnId)},isColumnBlocked(e,t=this.dragSource?.column){if(!e||e===t)return!1;let o=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"]`),n=o?.dataset.columnLimit;return n===void 0||n===""?!1:Number(o.dataset.columnTotal)>=Number(n)},isCellBlocked(e,t){return this.dragSource?t!==this.dragSource.lane&&this.$root.dataset.lanesWritable!=="true"?!0:this.isColumnBlocked(e):!1},displayCount(e,t){let o=this.pendingCounts[e]??t,n=this.dragSource?.column,r=this.dragOverColumn;return!n||!r||n===r||this.isColumnBlocked(r)?o:e===r?o+1:e===n?o-1:o},holdMovedCounts(e,t){if(e===t)return()=>{};let o={[e]:-1,[t]:1},n=!1;for(let[r,l]of Object.entries(o))this.pendingCounts[r]=this.renderedCount(r)+l;return this.pendingMoves++,r=>{if(!n){if(n=!0,r)for(let[l,a]of Object.entries(o))this.pendingCounts[l]-=a;--this.pendingMoves===0&&(this.pendingCounts={})}}},renderedCount(e){let t=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"] .ff-count`);return this.pendingCounts[e]??Number(t?.dataset.total)},handleSortableEnd(e){this.endDrag();let t=e.item,o=e.to,n=e.newDraggableIndex??e.newIndex,r=":scope > [x-sortable-item], :scope > [data-card-id]",l=s=>s.getAttribute("x-sortable-item")||s.getAttribute("data-card-id");if(e.from===o&&e.oldDraggableIndex===e.newDraggableIndex)return;if(n===0){let s=o.querySelector(r);s&&s!==t&&o.insertBefore(t,s)}let a=l(t);if(!a){console.error("Flowforge: Could not determine card ID for move operation");return}let i=o.getAttribute("data-column-id");if(!i){console.error("Flowforge: Target column ID is missing");return}let w=e.from.dataset.laneId??null,b=o.dataset.laneId??null,u=o.querySelectorAll(r),d=Array.prototype.indexOf.call(u,t),S=d>0?l(u[d-1]):null,y=d>=0&&d{this.setCardState(t,!1),g(s===!1),s===!1&&this.revertCard(e)}).catch(()=>{this.setCardState(t,!1),g(!0),this.revertCard(e)})},revertCard({item:e,from:t,oldDraggableIndex:o}){e.remove();let n=t.querySelectorAll(":scope > [x-sortable-item]"),r=n[n.length-1],l=n[o]??(r?r.nextSibling:t.firstChild);t.insertBefore(e,l)},setCardState(e,t){e.toggleAttribute("data-pending",t)},isLaneCollapsed(e){return this.collapsedLanes[e]===!0},toggleLane(e){this.collapsedLanes[e]=!this.isLaneCollapsed(e)},isLoadingColumn(e){return this.isLoading[e]||!1},isColumnFullyLoaded(e){return this.fullyLoaded[e]||!1},handleSmoothScroll(e){this.isLoadingColumn(e)||this.isColumnFullyLoaded(e)||(this.isLoading[e]=!0,this.$wire.loadMoreItems(e).then(()=>setTimeout(()=>this.isLoading[e]=!1,100)).catch(()=>this.isLoading[e]=!1))},handleColumnScroll(e,t){if(this.isColumnFullyLoaded(t))return;let{scrollTop:o,scrollHeight:n,clientHeight:r}=e.target;(o+r)/n>=.8&&!this.isLoadingColumn(t)&&this.handleSmoothScroll(t)}}}export{D as default}; +var A=["--ff-surface","--ff-surface-sunken","--ff-surface-raised","--ff-border","--ff-text","--ff-text-muted","--ff-accent","--ff-accent-tint","--ff-danger","--ff-warning","--ff-radius","--ff-gap","--ff-ease","--ff-duration","--ff-column-width","--ff-tray-bg","--ff-tray-radius","--ff-card-bg","--ff-card-ring","--ff-card-radius","--ff-card-shadow","--ff-card-padding","--ff-drag-tilt","--ff-drag-shadow","--ff-placeholder-border"],c='.ff-column-actions, .fi-dropdown-panel, input, textarea, select, [contenteditable]:not([contenteditable="false"])',m=`.ff-card, .ff-column-header, .ff-add-slot, .ff-add-row, .ff-cards-more, .ff-limit-hint, button, a, ${c}`,f=4,k=300,L=e=>{let t=e.querySelector("[data-autofocus]");!t||e.style.display!=="block"||!window.matchMedia("(pointer: fine)").matches||(t.focus({preventScroll:!0}),t.setSelectionRange?.(t.value.length,t.value.length))},C=new WeakSet,h=new WeakSet,p=()=>window.Sortable.active||window.Sortable.dragged;function D(){return{isLoading:{},fullyLoaded:{},dragOverColumn:null,railToggledAt:0,railClickTimer:null,columnMenuPressAt:null,railPressAt:null,dragOverLane:null,dragSource:null,pendingCounts:{},pendingMoves:0,collapsedLanes:{},addingColumn:!1,newColumnName:"",newColumnColor:null,newColumnDotStyle:"",newColumnColorPicked:!1,choosingNewColumnColor:!1,newColumnTouched:!1,addingColumnPending:!1,placeholder:null,stopTrackingPointer:null,init(){this.$wire.$on("kanban-items-loaded",e=>{let{columnId:t,isFullyLoaded:o}=e;o&&(this.fullyLoaded[t]=!0)})},configureSortable(e){if(!e.sortable||e.sortable.options.forceFallback)return;if(p()){this.configureSortableAfterDrag(e);return}let t=window.matchMedia("(prefers-reduced-motion: reduce)").matches;e.sortable.destroy(),e.sortable=window.Sortable.create(e,{draggable:"[x-sortable-item]",handle:"[x-sortable-handle]",dataIdAttr:"x-sortable-item",forceFallback:!0,fallbackTolerance:5,fallbackOnBody:!0,fallbackClass:"",ghostClass:"",delay:150,delayOnTouchOnly:!0,animation:t?0:200,scrollSensitivity:100,scrollSpeed:15,forceAutoScrollFallback:!0,group:{name:e.getAttribute("x-sortable-group"),pull:!0,put:(o,n)=>this.canDrop(o.el,n.el)},onStart:o=>this.startDrag(o),onEnd(o){let{item:n,to:r,oldDraggableIndex:l,newDraggableIndex:a}=o;if(l===a)return;let i=r.querySelectorAll(`:scope > ${this.options.draggable}`)[a-1];i&&r.insertBefore(n,i.nextSibling)}})},configureSortableAfterDrag(e){if(h.has(e))return;h.add(e);let t=()=>{if(p()){requestAnimationFrame(t);return}h.delete(e),e.isConnected&&this.configureSortable(e)};requestAnimationFrame(t)},startDrag(e){this.stopTrackingPointer?.(),this.placeholder=e.item,this.placeholder.setAttribute("data-placeholder",""),this.markGhost(),window.getSelection()?.removeAllRanges(),document.documentElement.classList.add("ff-dragging"),this.dragSource={column:e.from.dataset.columnId,lane:e.from.dataset.laneId??null};let t=o=>this.trackPointer(o);document.addEventListener("pointermove",t,{passive:!0}),document.addEventListener("touchmove",t,{passive:!0}),this.stopTrackingPointer=()=>{document.removeEventListener("pointermove",t),document.removeEventListener("touchmove",t)}},trackPointer(e){if(!window.Sortable.active){this.endDrag();return}this.markGhost();let t=e.touches?.[0]??e,o=document.elementFromPoint(t.clientX,t.clientY),n=o?.closest("[data-column-id]"),r=o?.closest("[data-column-root]");this.dragOverColumn=n?.dataset.columnId??r?.dataset.columnRoot??null,this.dragOverLane=n?.dataset.laneId??null},markGhost(){let e=window.Sortable.ghost;if(!e||e.hasAttribute("data-dragging"))return;e.removeAttribute("data-placeholder"),e.setAttribute("data-dragging",""),e.style.opacity="1";let t=getComputedStyle(this.placeholder);for(let o of A){let n=t.getPropertyValue(o);n!==""&&e.style.setProperty(o,n)}},endDrag(){document.documentElement.classList.remove("ff-dragging"),this.placeholder?.removeAttribute("data-placeholder"),this.placeholder=null,this.stopTrackingPointer?.(),this.stopTrackingPointer=null,this.dragOverColumn=null,this.dragOverLane=null,this.dragSource=null},railPress(e){this.railPressAt={x:e.clientX,y:e.clientY}},toggleColumnCollapse(e,t,o=!1){if(!(e.target.closest(c)||o&&e.detail>1)){if(o){let n=this.railPressAt;if(this.railPressAt=null,n&&Math.hypot(e.clientX-n.x,e.clientY-n.y)>f)return}Date.now()-this.railToggledAt<500||(o&&(this.railToggledAt=Date.now()),this.$wire.toggleBoardColumnCollapse(t))}},expandFromCollapseAll(e,t){let o=this.railPressAt;if(this.railPressAt=null,e.target.closest(c)||o&&Math.hypot(e.clientX-o.x,e.clientY-o.y)>f)return;let n=e.detail>1;clearTimeout(this.railClickTimer),this.railClickTimer=setTimeout(()=>{this.railToggledAt=Date.now(),this.$wire.toggleBoardColumnCollapse(t,n)},n?0:k)},collapseFromEmptySpace(e,t){e.target.closest(m)||this.toggleColumnCollapse(e,t)},suppressEmptySpaceSelection(e){e.detail>1&&!e.target.closest(m)&&e.preventDefault()},openNewColumn(e=null,t=""){this.addingColumn=!0,this.newColumnTouched=!0,this.newColumnColor=e,this.newColumnDotStyle=t,this.newColumnColorPicked=!1,this.$nextTick(()=>requestAnimationFrame(()=>{let o=this.$refs.newColumnInput,n=o.closest(".ff-columns, .ff-lanes");o.focus({preventScroll:!0}),n?.scrollTo({left:n.scrollWidth}),o.closest(".ff-add-column-ghost").scrollIntoView({block:"nearest"})}))},cancelNewColumn(){this.addingColumn=!1,this.newColumnTouched=!0,this.newColumnName="",this.newColumnColor=null,this.newColumnDotStyle="",this.choosingNewColumnColor=!1},pickNewColumnColor(e,t){this.newColumnColorPicked=!0,this.newColumnColor=e,this.newColumnDotStyle=t,this.choosingNewColumnColor=!1,this.$refs.newColumnInput.focus({preventScroll:!0})},async submitNewColumn(){if(!this.addingColumnPending){this.addingColumnPending=!0,this.newColumnTouched=!0;try{await this.$wire.addBoardColumn(this.newColumnName,this.newColumnColorPicked?this.newColumnColor:null)}finally{this.addingColumnPending=!1}this.newColumnTouched=!1,this.$root.querySelector(".ff-add-column-error")||this.cancelNewColumn()}},suppressDoubleClickSelection(e){e.detail>1&&!e.target.closest(c)&&e.preventDefault()},initColumnMenu(e){let t=e.closest(".fi-dropdown");if(C.has(t))return;let o=window.Alpine.$data(t),n=o.toggle.bind(o);C.add(t),o.toggle=r=>r?.type==="mousedown"?void 0:n(r)},columnMenuPress(e){this.columnMenuPressAt={x:e.clientX,y:e.clientY}},columnMenuClick(e){let t=this.columnMenuPressAt;if(this.columnMenuPressAt=null,e.detail>1||t&&Math.hypot(e.clientX-t.x,e.clientY-t.y)>f)return;let o=e.currentTarget.closest(".fi-dropdown");window.Alpine.$data(o).toggle(e),requestAnimationFrame(()=>L(o.querySelector(":scope > .fi-dropdown-panel")))},columnDrop(e){return this.dragOverColumn!==e?null:this.isColumnBlocked(e)?"blocked":"active"},cellDrop(e,t){return this.dragOverColumn!==e||this.dragOverLane!==t?null:this.isCellBlocked(e,t)?"blocked":"active"},canDrop(e,t){if(!this.$root.contains(e)||!this.$root.contains(t))return!1;let o=e.dataset.laneId??null,n=t.dataset.laneId??null;return o!==n&&this.$root.dataset.lanesWritable!=="true"?!1:!this.isColumnBlocked(e.dataset.columnId,t.dataset.columnId)},isColumnBlocked(e,t=this.dragSource?.column){if(!e||e===t)return!1;let o=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"]`),n=o?.dataset.columnLimit;return n===void 0||n===""?!1:Number(o.dataset.columnTotal)>=Number(n)},isCellBlocked(e,t){return this.dragSource?t!==this.dragSource.lane&&this.$root.dataset.lanesWritable!=="true"?!0:this.isColumnBlocked(e):!1},displayCount(e,t){let o=this.pendingCounts[e]??t,n=this.dragSource?.column,r=this.dragOverColumn;return!n||!r||n===r||this.isColumnBlocked(r)?o:e===r?o+1:e===n?o-1:o},holdMovedCounts(e,t){if(e===t)return()=>{};let o={[e]:-1,[t]:1},n=!1;for(let[r,l]of Object.entries(o))this.pendingCounts[r]=this.renderedCount(r)+l;return this.pendingMoves++,r=>{if(!n){if(n=!0,r)for(let[l,a]of Object.entries(o))this.pendingCounts[l]-=a;--this.pendingMoves===0&&(this.pendingCounts={})}}},renderedCount(e){let t=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"] .ff-count`);return this.pendingCounts[e]??Number(t?.dataset.total)},handleSortableEnd(e){this.endDrag();let t=e.item,o=e.to,n=e.newDraggableIndex??e.newIndex,r=":scope > [x-sortable-item], :scope > [data-card-id]",l=s=>s.getAttribute("x-sortable-item")||s.getAttribute("data-card-id");if(e.from===o&&e.oldDraggableIndex===e.newDraggableIndex)return;if(n===0){let s=o.querySelector(r);s&&s!==t&&o.insertBefore(t,s)}let a=l(t);if(!a){console.error("Flowforge: Could not determine card ID for move operation");return}let i=o.getAttribute("data-column-id");if(!i){console.error("Flowforge: Target column ID is missing");return}let w=e.from.dataset.laneId??null,b=o.dataset.laneId??null,u=o.querySelectorAll(r),d=Array.prototype.indexOf.call(u,t),S=d>0?l(u[d-1]):null,y=d>=0&&d{this.setCardState(t,!1),g(s===!1),s===!1&&this.revertCard(e)}).catch(()=>{this.setCardState(t,!1),g(!0),this.revertCard(e)})},revertCard({item:e,from:t,oldDraggableIndex:o}){e.remove();let n=t.querySelectorAll(":scope > [x-sortable-item]"),r=n[n.length-1],l=n[o]??(r?r.nextSibling:t.firstChild);t.insertBefore(e,l)},setCardState(e,t){e.toggleAttribute("data-pending",t)},isLaneCollapsed(e){return this.collapsedLanes[e]===!0},toggleLane(e){this.collapsedLanes[e]=!this.isLaneCollapsed(e)},isLoadingColumn(e){return this.isLoading[e]||!1},isColumnFullyLoaded(e){return this.fullyLoaded[e]||!1},handleSmoothScroll(e){this.isLoadingColumn(e)||this.isColumnFullyLoaded(e)||(this.isLoading[e]=!0,this.$wire.loadMoreItems(e).then(()=>setTimeout(()=>this.isLoading[e]=!1,100)).catch(()=>this.isLoading[e]=!1))},handleColumnScroll(e,t){if(this.isColumnFullyLoaded(t))return;let{scrollTop:o,scrollHeight:n,clientHeight:r}=e.target;(o+r)/n>=.8&&!this.isLoadingColumn(t)&&this.handleSmoothScroll(t)}}}export{D as default}; diff --git a/resources/js/flowforge-modern.js b/resources/js/flowforge-modern.js index 7901f4eca..4b9dd6fc2 100644 --- a/resources/js/flowforge-modern.js +++ b/resources/js/flowforge-modern.js @@ -319,11 +319,11 @@ export default function flowforgeModern() { // WebKit ignores a focus on the next tick, right after the ghost column shows. One frame later it takes it. this.$nextTick(() => requestAnimationFrame(() => { const input = this.$refs.newColumnInput; - const addColumn = input.closest('.ff-add-column'); - const shown = addColumn.closest('.ff-lanes-heads') ? input.closest('.ff-add-column-ghost') : addColumn; + const board = input.closest('.ff-columns, .ff-lanes'); input.focus({ preventScroll: true }); - shown.scrollIntoView({ block: 'nearest', inline: 'end' }); + board?.scrollTo({ left: board.scrollWidth }); + input.closest('.ff-add-column-ghost').scrollIntoView({ block: 'nearest' }); })); }, diff --git a/tests/Browser/ModernBoardTest.php b/tests/Browser/ModernBoardTest.php index a35bd4062..0785b2cc7 100644 --- a/tests/Browser/ModernBoardTest.php +++ b/tests/Browser/ModernBoardTest.php @@ -1179,6 +1179,12 @@ function boardTraySampler(int $budgetMilliseconds): string $reachable = <<<'JS' (() => { + const lanes = document.querySelector('.ff-lanes'); + + if (Math.abs(lanes.scrollLeft - (lanes.scrollWidth - lanes.clientWidth)) >= 1) { + return false; + } + const input = document.querySelector('.ff-add-column-input').getBoundingClientRect(); return document.elementFromPoint(input.left + input.width / 2, input.top + input.height / 2) === document.querySelector('.ff-add-column-input'); @@ -1204,7 +1210,9 @@ function boardTraySampler(int $budgetMilliseconds): string const ghost = document.querySelector('.ff-add-column-ghost').getBoundingClientRect(); const tile = document.querySelector('.ff-add-column-button').getBoundingClientRect(); - return ghost.left >= board.left - 0.5 && tile.right <= board.right + 0.5; + const columns = document.querySelector('.ff-columns'); + + return ghost.left >= board.left - 0.5 && tile.right <= board.right + 0.5 && Math.abs(columns.scrollLeft - (columns.scrollWidth - columns.clientWidth)) < 1; })() JS))->toBeTrue(); }); From 55d6ce4bdc926acbefea74d2dca2ba91aaf0c672 Mon Sep 17 00:00:00 2001 From: Manuk Date: Sun, 15 Nov 2026 04:03:32 +0400 Subject: [PATCH 26/34] feat(columns): resolve every board icon through a Filament icon alias --- .../views/livewire/empty-column.blade.php | 3 ++- .../components/grouping-picker.blade.php | 5 +++-- .../modern/livewire/add-card-row.blade.php | 2 +- .../modern/livewire/add-column.blade.php | 2 +- .../modern/livewire/column-header.blade.php | 4 +++- .../views/modern/livewire/lanes.blade.php | 2 +- src/View/FlowforgeIconAlias.php | 22 +++++++++++++++++++ tests/Modern/Feature/AddColumnTest.php | 12 ++++++++++ 8 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 src/View/FlowforgeIconAlias.php diff --git a/resources/views/livewire/empty-column.blade.php b/resources/views/livewire/empty-column.blade.php index 98ee49035..ced187a2a 100644 --- a/resources/views/livewire/empty-column.blade.php +++ b/resources/views/livewire/empty-column.blade.php @@ -2,7 +2,8 @@

diff --git a/resources/views/modern/components/grouping-picker.blade.php b/resources/views/modern/components/grouping-picker.blade.php index 5f1a738ba..b76212571 100644 --- a/resources/views/modern/components/grouping-picker.blade.php +++ b/resources/views/modern/components/grouping-picker.blade.php @@ -20,13 +20,14 @@ color="gray" size="sm" icon="heroicon-o-queue-list" + :icon-alias="\Relaticle\Flowforge\View\FlowforgeIconAlias::GROUPING_TRIGGER" :aria-label="$activeLabel ? __('flowforge::flowforge.group_by') . ': ' . $activeLabel : __('flowforge::flowforge.group_by')" :data-grouped="$activeLabel !== null" class="ff-grouping-trigger" > {{ $activeLabel ?? __('flowforge::flowforge.group_by') }} - + @@ -52,7 +53,7 @@ class="ff-grouping-option" @if ($isActive) - + @endif diff --git a/resources/views/modern/livewire/add-card-row.blade.php b/resources/views/modern/livewire/add-card-row.blade.php index 86e3474d6..f9d751fd0 100644 --- a/resources/views/modern/livewire/add-card-row.blade.php +++ b/resources/views/modern/livewire/add-card-row.blade.php @@ -17,7 +17,7 @@ class="ff-add-row" @disabled($isDisabled) @if ($disabled) title="{{ __('flowforge::flowforge.limit_reached') }}" @endif > - + {{ __('flowforge::flowforge.add_card', ['card' => $cardLabel]) }} @endif diff --git a/resources/views/modern/livewire/add-column.blade.php b/resources/views/modern/livewire/add-column.blade.php index ddeef933d..fd98f4de7 100644 --- a/resources/views/modern/livewire/add-column.blade.php +++ b/resources/views/modern/livewire/add-column.blade.php @@ -70,6 +70,6 @@ class="ff-add-column-button" aria-label="{{ $label }}" x-on:click="openNewColumn(@js($defaultColor), @js($defaultStyle))" > - +

diff --git a/resources/views/modern/livewire/column-header.blade.php b/resources/views/modern/livewire/column-header.blade.php index c22421438..5a6f56669 100644 --- a/resources/views/modern/livewire/column-header.blade.php +++ b/resources/views/modern/livewire/column-header.blade.php @@ -3,6 +3,8 @@ @php use Filament\Actions\Action; use Filament\Actions\ActionGroup; + use Filament\Support\Facades\FilamentIcon; + use Relaticle\Flowforge\View\FlowforgeIconAlias; $actions = array_values(array_filter($this->getBoardColumnActions($columnId), fn (Action | ActionGroup $action): bool => $action->isVisible())); $menuBlock = $isCollapsed ? null : $this->getBoard()->getColumnHeaderMenuBlock($column); @@ -11,7 +13,7 @@ $createAction = $this->getBoardCreateCardAction($columnId) ?->getClone() ->iconButton() - ->icon('heroicon-m-plus') + ->icon(FilamentIcon::resolve(FlowforgeIconAlias::ADD_CARD) ?? 'heroicon-m-plus') ->label(__('flowforge::flowforge.add_card', ['card' => $this->getBoard()->getCardLabel()])) ->disabled($column['isFull'] ?? false); diff --git a/resources/views/modern/livewire/lanes.blade.php b/resources/views/modern/livewire/lanes.blade.php index c669778de..a5f836261 100644 --- a/resources/views/modern/livewire/lanes.blade.php +++ b/resources/views/modern/livewire/lanes.blade.php @@ -70,7 +70,7 @@ class="ff-lane-toggle" aria-labelledby="{{ $laneTitleId }}" x-bind:aria-expanded="! isLaneCollapsed(@js($laneKey))" > - + @if ($lane['avatar']) diff --git a/src/View/FlowforgeIconAlias.php b/src/View/FlowforgeIconAlias.php new file mode 100644 index 000000000..c3f506bc0 --- /dev/null +++ b/src/View/FlowforgeIconAlias.php @@ -0,0 +1,22 @@ +assertSeeHtml('title="Add stage"'); }); + test('the tile draws the icon the host maps to its alias', function () { + preg_match('/ d="([^"]+)"/', svg('heroicon-m-star')->toHtml(), $star); + + FilamentIcon::register([FlowforgeIconAlias::ADD_COLUMN => 'heroicon-m-star']); + + $html = Livewire::test(TestBoard::class, ['withAddColumn' => true])->html(); + + expect($html)->toContain($star[1]); + }); + test('the input placeholder defaults to the column name text', function () { Livewire::test(TestBoard::class, ['withAddColumn' => true]) ->assertSeeHtml('placeholder="' . __('flowforge::flowforge.column_name') . '"'); From 877fa911ff44a0aea0a16fa151f663de8d042367 Mon Sep 17 00:00:00 2001 From: Manuk Date: Sun, 15 Nov 2026 04:07:18 +0400 Subject: [PATCH 27/34] fix(columns): name the header controls with a tooltip instead of a native title --- resources/views/modern/livewire/add-card-row.blade.php | 2 +- resources/views/modern/livewire/add-column.blade.php | 2 +- .../views/modern/livewire/column-header.blade.php | 5 +---- tests/Modern/Feature/AddColumnTest.php | 4 ++-- tests/Modern/Feature/ColumnLimitTest.php | 10 +++++++++- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/resources/views/modern/livewire/add-card-row.blade.php b/resources/views/modern/livewire/add-card-row.blade.php index f9d751fd0..263442067 100644 --- a/resources/views/modern/livewire/add-card-row.blade.php +++ b/resources/views/modern/livewire/add-card-row.blade.php @@ -15,7 +15,7 @@ class="ff-add-row" wire:click="mountAction(@js($createAction->getName()), @js(['column' => (string) $columnId]))" @disabled($isDisabled) - @if ($disabled) title="{{ __('flowforge::flowforge.limit_reached') }}" @endif + @if ($disabled) x-tooltip="{ content: @js(__('flowforge::flowforge.limit_reached')), theme: $store.theme }" @endif > {{ __('flowforge::flowforge.add_card', ['card' => $cardLabel]) }} diff --git a/resources/views/modern/livewire/add-column.blade.php b/resources/views/modern/livewire/add-column.blade.php index fd98f4de7..03758be84 100644 --- a/resources/views/modern/livewire/add-column.blade.php +++ b/resources/views/modern/livewire/add-column.blade.php @@ -66,7 +66,7 @@ class="ff-add-column-input" + @endforeach +
diff --git a/resources/views/modern/index.blade.php b/resources/views/modern/index.blade.php index dcdd55001..18d834c45 100644 --- a/resources/views/modern/index.blade.php +++ b/resources/views/modern/index.blade.php @@ -41,7 +41,7 @@ class="ff-board" @endforeach @if ($config['canAddColumns'] ?? false) - + @endif
@endif diff --git a/resources/views/modern/livewire/add-column.blade.php b/resources/views/modern/livewire/add-column.blade.php index 03758be84..ca76d25f8 100644 --- a/resources/views/modern/livewire/add-column.blade.php +++ b/resources/views/modern/livewire/add-column.blade.php @@ -1,4 +1,4 @@ -@props(['label', 'placeholder', 'colors' => [], 'defaultColor' => null]) +@props(['label', 'placeholder', 'colors' => [], 'defaultColor' => null, 'colorLabel' => null]) @php use Filament\Support\Enums\IconSize; @@ -18,29 +18,23 @@ class="ff-add-column-form" -
- @foreach ($colors as $color) - - @endforeach -
+ /> @else @endif diff --git a/resources/views/modern/livewire/lanes.blade.php b/resources/views/modern/livewire/lanes.blade.php index a5f836261..beedca001 100644 --- a/resources/views/modern/livewire/lanes.blade.php +++ b/resources/views/modern/livewire/lanes.blade.php @@ -46,7 +46,7 @@ class="ff-column" @endforeach @if ($canAddColumns) - + @endif
diff --git a/src/Board.php b/src/Board.php index b7b7f9021..9c11fb9ff 100644 --- a/src/Board.php +++ b/src/Board.php @@ -133,6 +133,7 @@ public function getViewData(): array 'canAddColumns' => $this->canAddColumns(), 'addColumnLabel' => $this->getAddColumnLabel(), 'addColumnPlaceholder' => $this->getAddColumnPlaceholder(), + 'addColumnColorLabel' => $this->getAddColumnColorLabel(), 'addColumnColors' => array_map( fn (string $value, string $label): array => ['value' => $value, 'label' => $label, 'style' => ColorResolver::dotStyle($value)], array_keys($this->getAddColumnColors()), diff --git a/src/Concerns/HasColumnControls.php b/src/Concerns/HasColumnControls.php index e026b62fe..6a3196592 100644 --- a/src/Concerns/HasColumnControls.php +++ b/src/Concerns/HasColumnControls.php @@ -27,6 +27,8 @@ trait HasColumnControls protected string | Closure | null $addColumnPlaceholder = null; + protected string | Closure | null $addColumnColorLabel = null; + /** @var array|Closure|null */ protected array | Closure | null $addColumnColors = null; @@ -145,6 +147,20 @@ public function addColumnPlaceholder(string | Closure | null $placeholder): stat return $this; } + public function addColumnColorLabel(string | Closure | null $label): static + { + $this->addColumnColorLabel = $label; + + return $this; + } + + public function getAddColumnColorLabel(): string + { + $label = $this->evaluate($this->addColumnColorLabel); + + return filled($label) ? (string) $label : __('flowforge::flowforge.set_column_color'); + } + /** * @param array|Closure|null $colors */ diff --git a/src/FlowforgeServiceProvider.php b/src/FlowforgeServiceProvider.php index 5bd6b75a1..d55d92c75 100644 --- a/src/FlowforgeServiceProvider.php +++ b/src/FlowforgeServiceProvider.php @@ -134,6 +134,7 @@ private function registerBladeComponents(): void Blade::component('flowforge::modern.livewire.add-column', 'flowforge::modern.add-column'); Blade::component('flowforge::modern.livewire.lanes', 'flowforge::modern.lanes'); Blade::component('flowforge::modern.components.grouping-picker', 'flowforge::modern.grouping-picker'); + Blade::component('flowforge::modern.components.color-swatches', 'flowforge::modern.color-swatches'); } protected function getAssetPackageName(): ?string diff --git a/tests/Browser/ModernBoardTest.php b/tests/Browser/ModernBoardTest.php index 0785b2cc7..a32997561 100644 --- a/tests/Browser/ModernBoardTest.php +++ b/tests/Browser/ModernBoardTest.php @@ -1158,6 +1158,33 @@ function boardTraySampler(int $budgetMilliseconds): string ->and(abs($box[2]))->toBeLessThan(1.5); }); +test('the add column swatches move by arrow keys, pick with enter and close with escape back on the dot', function () { + boardSeed(); + $page = boardPage('/modern/test-add-column-colors-board'); + $pointer = Pointer::on($page); + + $pointer->click('.ff-add-column-button'); + $pointer->untilScript("document.activeElement === document.querySelector('.ff-add-column-input')"); + $pointer->click('.ff-add-column-dot'); + $pointer->untilScript("document.activeElement?.getAttribute('role') === 'radio'"); + + $page->keys('.ff-swatch[tabindex="0"]', 'ArrowRight'); + $pointer->untilScript("document.activeElement.dataset.swatch === 'blue'"); + $page->keys('.ff-swatch[tabindex="0"]', 'Enter'); + $pointer->untilScript("document.querySelector('.ff-swatches').offsetParent === null"); + + expect($page->script("document.querySelector('.ff-add-column-dot').style.getPropertyValue('--color-500')"))->not->toBe('') + ->and($page->script("document.querySelector('.ff-swatch[data-swatch=\"blue\"]').getAttribute('aria-checked')"))->toBe('true'); + + $pointer->click('.ff-add-column-dot'); + $pointer->untilScript("document.activeElement?.getAttribute('role') === 'radio'"); + $page->keys('.ff-swatch[tabindex="0"]', 'Escape'); + $pointer->untilScript("document.querySelector('.ff-swatches').offsetParent === null"); + + expect($page->script('document.activeElement === document.querySelector(".ff-add-column-dot")'))->toBeTrue() + ->and($page->script("document.querySelector('.ff-add-column-ghost').offsetParent !== null"))->toBeTrue(); +}); + test('the add column tile sits in the lane heads and its form opens on top of the lanes', function () { boardSeed('high'); $page = boardPage('/modern/test-add-column-grouped-board?groupBy=priority'); diff --git a/tests/Fixtures/Modern/ModernPanelProvider.php b/tests/Fixtures/Modern/ModernPanelProvider.php index 26751e6a0..89dbdf216 100644 --- a/tests/Fixtures/Modern/ModernPanelProvider.php +++ b/tests/Fixtures/Modern/ModernPanelProvider.php @@ -29,6 +29,7 @@ public function panel(Panel $panel): Panel ->pages([ TestBoard::class, TestAddColumnBoard::class, + TestAddColumnColorsBoard::class, TestAddColumnGroupedBoard::class, TestBrowserBoard::class, TestClassicBoard::class, diff --git a/tests/Fixtures/Modern/TestAddColumnColorsBoard.php b/tests/Fixtures/Modern/TestAddColumnColorsBoard.php new file mode 100644 index 000000000..16dc7e6f2 --- /dev/null +++ b/tests/Fixtures/Modern/TestAddColumnColorsBoard.php @@ -0,0 +1,12 @@ +addColumnDefaultColor($this->addColumnDefault) ->addColumnLabel($this->addColumnTitle) ->addColumnPlaceholder($this->addColumnHint) + ->addColumnColorLabel($this->addColumnColorLabel) ->headerToolbar($this->withHeaderToolbar) ->columnActions(match (true) { $this->withHeaderMenu => [Action::make('archiveColumn')->label('Archive column')->action(function (): void {})], diff --git a/tests/Modern/Feature/AddColumnTest.php b/tests/Modern/Feature/AddColumnTest.php index cdd019ed7..e5d4a44b1 100644 --- a/tests/Modern/Feature/AddColumnTest.php +++ b/tests/Modern/Feature/AddColumnTest.php @@ -83,7 +83,7 @@ function headTracks(string $html, string $property): string test('a color from the host palette reaches the host, and any other color arrives as null', function () { $component = Livewire::test(TestBoard::class, ['withAddColumn' => true, 'withAddColumnColors' => true]); - expect($component->html())->toContain('aria-label="Red"')->toContain('style="--color-500:#ff5454"'); + expect($component->html())->toContain('aria-label="Set color to Red"')->toContain('style="--color-500:#ff5454"'); $component->call('addBoardColumn', 'Won', '#ff5454') ->call('addBoardColumn', 'Lost', '#000000') @@ -92,6 +92,22 @@ function headTracks(string $html, string $property): string expect($component->get('addedColumnColors'))->toBe(['#ff5454', null, null]); }); + test('the palette is a radio group of labelled swatches with one tab stop', function () { + $html = Livewire::test(TestBoard::class, ['withAddColumn' => true, 'withAddColumnColors' => true])->html(); + + expect($html)->toContain('role="radiogroup"') + ->and(substr_count($html, 'role="radio"'))->toBe(2) + ->and(substr_count($html, 'class="ff-swatch"'))->toBe(2) + ->and(substr_count($html, 'tabindex="0"'))->toBeGreaterThanOrEqual(1) + ->and($html)->not->toContain('aria-pressed'); + }); + + test('the host sets the swatch label', function () { + $html = Livewire::test(TestBoard::class, ['withAddColumn' => true, 'withAddColumnColors' => true, 'addColumnColorLabel' => 'Use :color'])->html(); + + expect($html)->toContain('aria-label="Use Red"')->not->toContain('Set color to'); + }); + test('the form opens on the default color when it is in the palette', function () { $board = fn (string $default) => Livewire::test(TestBoard::class, ['withAddColumn' => true, 'withAddColumnColors' => true, 'addColumnDefault' => $default])->instance()->getBoard(); From 078955718efe339407e5044bd5cceec5eb834145 Mon Sep 17 00:00:00 2001 From: Manuk Date: Sun, 15 Nov 2026 04:18:17 +0400 Subject: [PATCH 30/34] feat(columns): make a collapsed rail a keyboard operable button --- resources/lang/de/flowforge.php | 1 + resources/lang/en/flowforge.php | 1 + resources/lang/es/flowforge.php | 1 + resources/lang/nl/flowforge.php | 1 + .../views/modern/livewire/column.blade.php | 12 ++++++++- .../views/modern/livewire/lanes.blade.php | 17 ++++++++++-- tests/Browser/ModernBoardTest.php | 27 +++++++++++++++++++ tests/Modern/Feature/CollapsedColumnsTest.php | 11 ++++++++ tests/Modern/Feature/ColumnLayoutTest.php | 5 ++-- 9 files changed, 71 insertions(+), 5 deletions(-) diff --git a/resources/lang/de/flowforge.php b/resources/lang/de/flowforge.php index e955d1c2f..1f2768416 100644 --- a/resources/lang/de/flowforge.php +++ b/resources/lang/de/flowforge.php @@ -25,6 +25,7 @@ 'column_name_required' => 'Gib einen Namen ein.', 'column_name' => 'Spaltenname', 'column_color' => 'Spaltenfarbe', + 'expand_column' => ':column erweitern', 'set_column_color' => 'Farbe auf :color setzen', 'show_more_cards' => ':count weitere anzeigen', 'lane_write_failed' => 'Die Karte konnte nicht in diese Bahn verschoben werden.', diff --git a/resources/lang/en/flowforge.php b/resources/lang/en/flowforge.php index 9e07ffb28..0306747a7 100644 --- a/resources/lang/en/flowforge.php +++ b/resources/lang/en/flowforge.php @@ -25,6 +25,7 @@ 'column_name_required' => 'Enter a name.', 'column_name' => 'Column name', 'column_color' => 'Column color', + 'expand_column' => 'Expand :column', 'set_column_color' => 'Set color to :color', 'show_more_cards' => 'Show :count more', 'lane_write_failed' => 'The card could not be moved to that lane.', diff --git a/resources/lang/es/flowforge.php b/resources/lang/es/flowforge.php index 6ed48db4e..a45514cc4 100644 --- a/resources/lang/es/flowforge.php +++ b/resources/lang/es/flowforge.php @@ -25,6 +25,7 @@ 'column_name_required' => 'Introduce un nombre.', 'column_name' => 'Nombre de la columna', 'column_color' => 'Color de la columna', + 'expand_column' => 'Expandir :column', 'set_column_color' => 'Establecer el color en :color', 'show_more_cards' => 'Mostrar :count más', 'lane_write_failed' => 'No se pudo mover la tarjeta a ese carril.', diff --git a/resources/lang/nl/flowforge.php b/resources/lang/nl/flowforge.php index 15beb84cf..a385bb461 100644 --- a/resources/lang/nl/flowforge.php +++ b/resources/lang/nl/flowforge.php @@ -25,6 +25,7 @@ 'column_name_required' => 'Voer een naam in.', 'column_name' => 'Kolomnaam', 'column_color' => 'Kolomkleur', + 'expand_column' => ':column uitvouwen', 'set_column_color' => 'Kleur instellen op :color', 'show_more_cards' => ':count meer tonen', 'lane_write_failed' => 'De kaart kon niet naar die baan worden verplaatst.', diff --git a/resources/views/modern/livewire/column.blade.php b/resources/views/modern/livewire/column.blade.php index aa1df2990..7ef2438a1 100644 --- a/resources/views/modern/livewire/column.blade.php +++ b/resources/views/modern/livewire/column.blade.php @@ -4,6 +4,7 @@ $total = $column['total'] ?? (isset($column['items']) ? count($column['items']) : 0); $isCollapsed = (bool) ($column['isCollapsed'] ?? false); $plainLabel = strip_tags((string) $column['label']); + $expandLabel = __('flowforge::flowforge.expand_column', ['column' => $plainLabel]); $trayLabel = __('flowforge::flowforge.column_label', [ 'column' => $plainLabel, 'count' => $total, @@ -20,8 +21,17 @@ class="ff-column" data-column-total="{{ $column['limitTotal'] ?? $total }}" @if (($column['limit'] ?? null) !== null) data-column-limit="{{ $column['limit'] }}" @endif @if ($column['isFull'] ?? false) data-full @endif - @if ($isCollapsed) data-collapsed title="{{ $plainLabel }}" @endif + @if ($isCollapsed) data-collapsed @endif + @if ($isCollapsed && ! ($column['canToggleCollapse'] ?? false)) + x-tooltip="{ content: @js($plainLabel), theme: $store.theme }" + @endif @if ($isCollapsed && ($column['canToggleCollapse'] ?? false)) + role="button" + tabindex="0" + aria-label="{{ $expandLabel }}" + x-tooltip="{ content: @js($expandLabel), theme: $store.theme }" + x-on:keydown.enter.self.prevent="$el.click()" + x-on:keydown.space.self.prevent="$el.click()" @if ($column['isCollapsedByAll'] ?? false) x-on:click="expandFromCollapseAll($event, @js((string) $columnId))" @else diff --git a/resources/views/modern/livewire/lanes.blade.php b/resources/views/modern/livewire/lanes.blade.php index beedca001..a7e555d69 100644 --- a/resources/views/modern/livewire/lanes.blade.php +++ b/resources/views/modern/livewire/lanes.blade.php @@ -20,7 +20,11 @@
@foreach ($columns as $columnId => $column) - @php $isCollapsed = (bool) ($column['isCollapsed'] ?? false); @endphp + @php + $isCollapsed = (bool) ($column['isCollapsed'] ?? false); + $plainLabel = strip_tags((string) $column['label']); + $expandLabel = __('flowforge::flowforge.expand_column', ['column' => $plainLabel]); + @endphp
toBe('300px'); }); +test('enter and space on a focused rail expand it like a click', function (string $key) { + boardSeed(); + $page = boardPage('/modern/test-collapsible-board'); + $pointer = Pointer::on($page); + $root = '[data-column-root="in_progress"]'; + + $pointer->doubleClick("{$root} .ff-column-title"); + $pointer->untilScript("document.querySelector('{$root}').hasAttribute('data-collapsed')"); + $page->script("document.querySelector('{$root}').focus()"); + + expect($page->script("document.querySelector('{$root}').getAttribute('role')"))->toBe('button'); + + $page->keys($root, $key); + $pointer->untilScript("! document.querySelector('{$root}').hasAttribute('data-collapsed')"); +})->with(['Enter', 'Space']); + +test('enter on a focused rail under collapse all sends the single click after the double click window', function () { + boardSeed(); + $page = boardPage('/modern/test-collapsed-all-board'); + $pointer = Pointer::on($page); + $root = '[data-column-root="in_progress"]'; + + $page->script("document.querySelector('{$root}').focus()"); + $page->keys($root, 'Enter'); + $pointer->untilScript("window.Alpine.\$data(document.querySelector('{$root}')).railToggledAt > 0"); +}); + test('a press on a rail that moves before release leaves the rail collapsed', function () { boardSeed(); $page = boardPage('/modern/test-collapsible-board'); diff --git a/tests/Modern/Feature/CollapsedColumnsTest.php b/tests/Modern/Feature/CollapsedColumnsTest.php index e4cc8f1b2..4652a399d 100644 --- a/tests/Modern/Feature/CollapsedColumnsTest.php +++ b/tests/Modern/Feature/CollapsedColumnsTest.php @@ -33,6 +33,17 @@ ->assertDontSeeHtml('data-collapsed'); }); + test('a rail the user can expand is a labelled button and a fixed one is not', function () { + $expandable = Livewire::test(TestCollapsibleBoard::class, ['collapsedIds' => ['in_progress']])->html(); + $fixed = Livewire::test(TestBoard::class, ['collapsedIds' => ['in_progress']])->html(); + + expect($expandable)->toMatch('/]*data-column-root="in_progress"[^>]*role="button"[^>]*tabindex="0"[^>]*aria-label="Expand In Progress"/') + ->and($expandable)->toContain("content: 'Expand In Progress'") + ->and($expandable)->not->toContain('data-collapsed title=') + ->and($fixed)->not->toContain('role="button"') + ->and($fixed)->not->toContain('data-collapsed title='); + }); + test('a collapsed column keeps its drop binding', function () { $html = Livewire::test(TestBoard::class, ['collapsedIds' => ['todo']])->html(); diff --git a/tests/Modern/Feature/ColumnLayoutTest.php b/tests/Modern/Feature/ColumnLayoutTest.php index 87315e796..74c4f30bb 100644 --- a/tests/Modern/Feature/ColumnLayoutTest.php +++ b/tests/Modern/Feature/ColumnLayoutTest.php @@ -72,6 +72,7 @@ $html = Livewire::test(TestBoard::class, ['htmlLabel' => true, 'collapseEmpty' => true])->html(); - expect($html)->toContain('title="In Progress"') - ->and($html)->not->toContain('title="<em>'); + expect($html)->toContain("content: 'In Progress'") + ->and($html)->not->toContain("content: '") + ->and($html)->not->toContain('data-collapsed title='); }); From b43c7b2d28d9672f43501bd0cab0755a134f8246 Mon Sep 17 00:00:00 2001 From: Manuk Date: Sun, 15 Nov 2026 04:20:29 +0400 Subject: [PATCH 31/34] feat(columns): read the add form and swatch overlay radius and shadow from tokens --- docs/content/2.essentials/7.design-system.md | 2 + resources/css/flowforge-modern.css | 43 ++++++++------------ resources/design-tokens.php | 2 + resources/dist/flowforge-modern.js | 2 +- resources/js/flowforge-modern.js | 2 + 5 files changed, 23 insertions(+), 28 deletions(-) diff --git a/docs/content/2.essentials/7.design-system.md b/docs/content/2.essentials/7.design-system.md index bb8582df8..976c26932 100644 --- a/docs/content/2.essentials/7.design-system.md +++ b/docs/content/2.essentials/7.design-system.md @@ -55,6 +55,8 @@ The dark column shows where the default changes under Filament's `.dark` class. | `--ff-duration` | semantic | `200ms` | 4.2.0 | Duration of the same transitions. | | `--ff-column-width` | component | `300px` | 4.2.0 | Width of a column, and of each column in the lane grid. | | `--ff-dot-size` | component | `0.5rem` | 4.4.0 | Diameter of the color dot in a column header and in the add column field. | +| `--ff-overlay-radius` | component | `0.75rem` | 4.4.0 | Corner radius of the add column form, its name field and the color swatch grid. | +| `--ff-overlay-shadow` | component | `0 0 0 1px color-mix(in oklab, var(--gray-950) 5%, transparent), 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1)` / the same with a `#fff` 10% ring and a 0.3 shadow | 4.4.0 | Ring and shadow list of the add column form and the color swatch grid. | | `--ff-tray-bg` | component | `var(--ff-surface-sunken)` | 4.2.0 | Background of a column tray and of a lane cell. | | `--ff-tray-radius` | component | `calc(var(--ff-radius) + 0.25rem)` | 4.2.0 | Corner radius of a tray and of a lane cell. | | `--ff-card-bg` | component | `var(--ff-surface-raised)` | 4.2.0 | Card background. | diff --git a/resources/css/flowforge-modern.css b/resources/css/flowforge-modern.css index feef26ab8..e2ae4c468 100644 --- a/resources/css/flowforge-modern.css +++ b/resources/css/flowforge-modern.css @@ -728,25 +728,27 @@ background-color: transparent; } + .ff-add-column-form, + .ff-swatches { + --_overlay-radius: var(--ff-overlay-radius, 0.75rem); + --_overlay-shadow: var(--ff-overlay-shadow, 0 0 0 1px color-mix(in oklab, var(--gray-950) 5%, transparent), 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1)); + background-color: var(--ff-surface-raised, #fff); + border-radius: var(--_overlay-radius); + box-shadow: var(--_overlay-shadow); + } + + :where(.dark) .ff-add-column-form, + :where(.dark) .ff-swatches { + --_overlay-shadow: var(--ff-overlay-shadow, 0 0 0 1px color-mix(in oklab, #fff 10%, transparent), 0 10px 15px -3px rgb(0 0 0 / 0.3)); + background-color: var(--ff-surface-raised, var(--gray-900)); + } + .ff-add-column-form { position: absolute; inset-block-start: 0; inset-inline: 0; z-index: 20; padding: 0.75rem; - background-color: var(--ff-surface-raised, #fff); - border-radius: 0.75rem; - box-shadow: - 0 0 0 1px color-mix(in oklab, var(--gray-950) 5%, transparent), - 0 10px 15px -3px rgb(0 0 0 / 0.1), - 0 4px 6px -4px rgb(0 0 0 / 0.1); - } - - :where(.dark) .ff-add-column-form { - background-color: var(--ff-surface-raised, var(--gray-900)); - box-shadow: - 0 0 0 1px color-mix(in oklab, #fff 10%, transparent), - 0 10px 15px -3px rgb(0 0 0 / 0.3); } .ff-add-column-field { @@ -757,7 +759,7 @@ height: 2.25rem; padding: 0 0.75rem; border: 1px solid var(--gray-200); - border-radius: 0.625rem; + border-radius: var(--_overlay-radius); transition: border-color var(--_duration) var(--_ease); } @@ -788,19 +790,6 @@ width: max-content; margin-block-start: -0.375rem; padding: 0.5rem; - background-color: var(--ff-surface-raised, #fff); - border-radius: 0.75rem; - box-shadow: - 0 0 0 1px color-mix(in oklab, var(--gray-950) 5%, transparent), - 0 10px 15px -3px rgb(0 0 0 / 0.1), - 0 4px 6px -4px rgb(0 0 0 / 0.1); - } - - :where(.dark) .ff-swatches { - background-color: var(--ff-surface-raised, var(--gray-900)); - box-shadow: - 0 0 0 1px color-mix(in oklab, #fff 10%, transparent), - 0 10px 15px -3px rgb(0 0 0 / 0.3); } .ff-swatch { diff --git a/resources/design-tokens.php b/resources/design-tokens.php index b6188147b..19e7cf9ff 100644 --- a/resources/design-tokens.php +++ b/resources/design-tokens.php @@ -19,6 +19,8 @@ '--ff-duration' => ['tier' => 'semantic', 'since' => '4.2.0'], '--ff-column-width' => ['tier' => 'component', 'since' => '4.2.0'], '--ff-dot-size' => ['tier' => 'component', 'since' => '4.4.0'], + '--ff-overlay-radius' => ['tier' => 'component', 'since' => '4.4.0'], + '--ff-overlay-shadow' => ['tier' => 'component', 'since' => '4.4.0'], '--ff-tray-bg' => ['tier' => 'component', 'since' => '4.2.0'], '--ff-tray-radius' => ['tier' => 'component', 'since' => '4.2.0'], '--ff-card-bg' => ['tier' => 'component', 'since' => '4.2.0'], diff --git a/resources/dist/flowforge-modern.js b/resources/dist/flowforge-modern.js index 0bdaf4a29..d6fcad0a9 100644 --- a/resources/dist/flowforge-modern.js +++ b/resources/dist/flowforge-modern.js @@ -1 +1 @@ -var L=["--ff-surface","--ff-surface-sunken","--ff-surface-raised","--ff-border","--ff-text","--ff-text-muted","--ff-accent","--ff-accent-tint","--ff-danger","--ff-warning","--ff-radius","--ff-gap","--ff-ease","--ff-duration","--ff-column-width","--ff-dot-size","--ff-tray-bg","--ff-tray-radius","--ff-card-bg","--ff-card-ring","--ff-card-radius","--ff-card-shadow","--ff-card-padding","--ff-drag-tilt","--ff-drag-shadow","--ff-placeholder-border"],c='.ff-column-actions, .fi-dropdown-panel, input, textarea, select, [contenteditable]:not([contenteditable="false"])',C=`.ff-card, .ff-column-header, .ff-add-slot, .ff-add-row, .ff-cards-more, .ff-limit-hint, button, a, ${c}`,f=4,D=300,x=e=>{let t=e.querySelector("[data-autofocus]");!t||e.style.display!=="block"||!window.matchMedia("(pointer: fine)").matches||(t.focus({preventScroll:!0}),t.setSelectionRange?.(t.value.length,t.value.length))},p=4,h=e=>[...e.querySelectorAll('[role="radio"]')],w=new WeakSet,g=new WeakSet,b=()=>window.Sortable.active||window.Sortable.dragged;function T(){return{isLoading:{},fullyLoaded:{},dragOverColumn:null,railToggledAt:0,railClickTimer:null,columnMenuPressAt:null,railPressAt:null,dragOverLane:null,dragSource:null,pendingCounts:{},pendingMoves:0,collapsedLanes:{},addingColumn:!1,newColumnName:"",newColumnColor:null,newColumnDotStyle:"",newColumnColorPicked:!1,choosingNewColumnColor:!1,newColumnTouched:!1,addingColumnPending:!1,placeholder:null,stopTrackingPointer:null,init(){this.$wire.$on("kanban-items-loaded",e=>{let{columnId:t,isFullyLoaded:o}=e;o&&(this.fullyLoaded[t]=!0)})},configureSortable(e){if(!e.sortable||e.sortable.options.forceFallback)return;if(b()){this.configureSortableAfterDrag(e);return}let t=window.matchMedia("(prefers-reduced-motion: reduce)").matches;e.sortable.destroy(),e.sortable=window.Sortable.create(e,{draggable:"[x-sortable-item]",handle:"[x-sortable-handle]",dataIdAttr:"x-sortable-item",forceFallback:!0,fallbackTolerance:5,fallbackOnBody:!0,fallbackClass:"",ghostClass:"",delay:150,delayOnTouchOnly:!0,animation:t?0:200,scrollSensitivity:100,scrollSpeed:15,forceAutoScrollFallback:!0,group:{name:e.getAttribute("x-sortable-group"),pull:!0,put:(o,r)=>this.canDrop(o.el,r.el)},onStart:o=>this.startDrag(o),onEnd(o){let{item:r,to:n,oldDraggableIndex:s,newDraggableIndex:a}=o;if(s===a)return;let i=n.querySelectorAll(`:scope > ${this.options.draggable}`)[a-1];i&&n.insertBefore(r,i.nextSibling)}})},configureSortableAfterDrag(e){if(g.has(e))return;g.add(e);let t=()=>{if(b()){requestAnimationFrame(t);return}g.delete(e),e.isConnected&&this.configureSortable(e)};requestAnimationFrame(t)},startDrag(e){this.stopTrackingPointer?.(),this.placeholder=e.item,this.placeholder.setAttribute("data-placeholder",""),this.markGhost(),window.getSelection()?.removeAllRanges(),document.documentElement.classList.add("ff-dragging"),this.dragSource={column:e.from.dataset.columnId,lane:e.from.dataset.laneId??null};let t=o=>this.trackPointer(o);document.addEventListener("pointermove",t,{passive:!0}),document.addEventListener("touchmove",t,{passive:!0}),this.stopTrackingPointer=()=>{document.removeEventListener("pointermove",t),document.removeEventListener("touchmove",t)}},trackPointer(e){if(!window.Sortable.active){this.endDrag();return}this.markGhost();let t=e.touches?.[0]??e,o=document.elementFromPoint(t.clientX,t.clientY),r=o?.closest("[data-column-id]"),n=o?.closest("[data-column-root]");this.dragOverColumn=r?.dataset.columnId??n?.dataset.columnRoot??null,this.dragOverLane=r?.dataset.laneId??null},markGhost(){let e=window.Sortable.ghost;if(!e||e.hasAttribute("data-dragging"))return;e.removeAttribute("data-placeholder"),e.setAttribute("data-dragging",""),e.style.opacity="1";let t=getComputedStyle(this.placeholder);for(let o of L){let r=t.getPropertyValue(o);r!==""&&e.style.setProperty(o,r)}},endDrag(){document.documentElement.classList.remove("ff-dragging"),this.placeholder?.removeAttribute("data-placeholder"),this.placeholder=null,this.stopTrackingPointer?.(),this.stopTrackingPointer=null,this.dragOverColumn=null,this.dragOverLane=null,this.dragSource=null},railPress(e){this.railPressAt={x:e.clientX,y:e.clientY}},toggleColumnCollapse(e,t,o=!1){if(!(e.target.closest(c)||o&&e.detail>1)){if(o){let r=this.railPressAt;if(this.railPressAt=null,r&&Math.hypot(e.clientX-r.x,e.clientY-r.y)>f)return}Date.now()-this.railToggledAt<500||(o&&(this.railToggledAt=Date.now()),this.$wire.toggleBoardColumnCollapse(t))}},expandFromCollapseAll(e,t){let o=this.railPressAt;if(this.railPressAt=null,e.target.closest(c)||o&&Math.hypot(e.clientX-o.x,e.clientY-o.y)>f)return;let r=e.detail>1;clearTimeout(this.railClickTimer),this.railClickTimer=setTimeout(()=>{this.railToggledAt=Date.now(),this.$wire.toggleBoardColumnCollapse(t,r)},r?0:D)},collapseFromEmptySpace(e,t){e.target.closest(C)||this.toggleColumnCollapse(e,t)},suppressEmptySpaceSelection(e){e.detail>1&&!e.target.closest(C)&&e.preventDefault()},openNewColumn(e=null,t=""){this.addingColumn=!0,this.newColumnTouched=!0,this.newColumnColor=e,this.newColumnDotStyle=t,this.newColumnColorPicked=!1,this.$nextTick(()=>requestAnimationFrame(()=>{let o=this.$refs.newColumnInput,r=o.closest(".ff-columns, .ff-lanes");o.focus({preventScroll:!0}),r?.scrollTo({left:r.scrollWidth}),o.closest(".ff-add-column-ghost").scrollIntoView({block:"nearest"})}))},cancelNewColumn(){this.addingColumn=!1,this.newColumnTouched=!0,this.newColumnName="",this.newColumnColor=null,this.newColumnDotStyle="",this.choosingNewColumnColor=!1},closeNewColumnColors(){this.choosingNewColumnColor=!1,this.$refs.newColumnDot?.focus({preventScroll:!0})},pickNewColumnColor(e,t){this.newColumnColorPicked=!0,this.newColumnColor=e,this.newColumnDotStyle=t,this.choosingNewColumnColor=!1,this.$refs.newColumnInput.focus({preventScroll:!0})},async submitNewColumn(){if(!this.addingColumnPending){this.addingColumnPending=!0,this.newColumnTouched=!0;try{await this.$wire.addBoardColumn(this.newColumnName,this.newColumnColorPicked?this.newColumnColor:null)}finally{this.addingColumnPending=!1}this.newColumnTouched=!1,this.$root.querySelector(".ff-add-column-error")||this.cancelNewColumn()}},suppressDoubleClickSelection(e){e.detail>1&&!e.target.closest(c)&&e.preventDefault()},initColumnMenu(e){let t=e.closest(".fi-dropdown");if(w.has(t))return;let o=window.Alpine.$data(t),r=o.toggle.bind(o);w.add(t),o.toggle=n=>n?.type==="mousedown"?void 0:r(n)},columnMenuPress(e){this.columnMenuPressAt={x:e.clientX,y:e.clientY}},columnMenuClick(e){let t=this.columnMenuPressAt;if(this.columnMenuPressAt=null,e.detail>1||t&&Math.hypot(e.clientX-t.x,e.clientY-t.y)>f)return;let o=e.currentTarget.closest(".fi-dropdown");window.Alpine.$data(o).toggle(e),requestAnimationFrame(()=>x(o.querySelector(":scope > .fi-dropdown-panel")))},focusSwatch(e){let t=h(e);(t.find(r=>r.getAttribute("aria-checked")==="true")??t[0])?.focus({preventScroll:!0})},swatchFocused(e){let t=e.target.closest('[role="radiogroup"]');h(t).forEach(o=>o.setAttribute("tabindex",o===e.target?"0":"-1"))},swatchKey(e){let t=h(e.currentTarget),o=t.indexOf(e.target),r=t.length-1,n={ArrowRight:o===r?0:o+1,ArrowLeft:o===0?r:o-1,ArrowDown:Math.min(o+p,r),ArrowUp:Math.max(o-p,0),Home:0,End:r}[e.key];o<0||n===void 0||(e.preventDefault(),t[n].focus({preventScroll:!0}))},columnDrop(e){return this.dragOverColumn!==e?null:this.isColumnBlocked(e)?"blocked":"active"},cellDrop(e,t){return this.dragOverColumn!==e||this.dragOverLane!==t?null:this.isCellBlocked(e,t)?"blocked":"active"},canDrop(e,t){if(!this.$root.contains(e)||!this.$root.contains(t))return!1;let o=e.dataset.laneId??null,r=t.dataset.laneId??null;return o!==r&&this.$root.dataset.lanesWritable!=="true"?!1:!this.isColumnBlocked(e.dataset.columnId,t.dataset.columnId)},isColumnBlocked(e,t=this.dragSource?.column){if(!e||e===t)return!1;let o=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"]`),r=o?.dataset.columnLimit;return r===void 0||r===""?!1:Number(o.dataset.columnTotal)>=Number(r)},isCellBlocked(e,t){return this.dragSource?t!==this.dragSource.lane&&this.$root.dataset.lanesWritable!=="true"?!0:this.isColumnBlocked(e):!1},displayCount(e,t){let o=this.pendingCounts[e]??t,r=this.dragSource?.column,n=this.dragOverColumn;return!r||!n||r===n||this.isColumnBlocked(n)?o:e===n?o+1:e===r?o-1:o},holdMovedCounts(e,t){if(e===t)return()=>{};let o={[e]:-1,[t]:1},r=!1;for(let[n,s]of Object.entries(o))this.pendingCounts[n]=this.renderedCount(n)+s;return this.pendingMoves++,n=>{if(!r){if(r=!0,n)for(let[s,a]of Object.entries(o))this.pendingCounts[s]-=a;--this.pendingMoves===0&&(this.pendingCounts={})}}},renderedCount(e){let t=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"] .ff-count`);return this.pendingCounts[e]??Number(t?.dataset.total)},handleSortableEnd(e){this.endDrag();let t=e.item,o=e.to,r=e.newDraggableIndex??e.newIndex,n=":scope > [x-sortable-item], :scope > [data-card-id]",s=l=>l.getAttribute("x-sortable-item")||l.getAttribute("data-card-id");if(e.from===o&&e.oldDraggableIndex===e.newDraggableIndex)return;if(r===0){let l=o.querySelector(n);l&&l!==t&&o.insertBefore(t,l)}let a=s(t);if(!a){console.error("Flowforge: Could not determine card ID for move operation");return}let i=o.getAttribute("data-column-id");if(!i){console.error("Flowforge: Target column ID is missing");return}let S=e.from.dataset.laneId??null,y=o.dataset.laneId??null,d=o.querySelectorAll(n),u=Array.prototype.indexOf.call(d,t),A=u>0?s(d[u-1]):null,k=u>=0&&u{this.setCardState(t,!1),m(l===!1),l===!1&&this.revertCard(e)}).catch(()=>{this.setCardState(t,!1),m(!0),this.revertCard(e)})},revertCard({item:e,from:t,oldDraggableIndex:o}){e.remove();let r=t.querySelectorAll(":scope > [x-sortable-item]"),n=r[r.length-1],s=r[o]??(n?n.nextSibling:t.firstChild);t.insertBefore(e,s)},setCardState(e,t){e.toggleAttribute("data-pending",t)},isLaneCollapsed(e){return this.collapsedLanes[e]===!0},toggleLane(e){this.collapsedLanes[e]=!this.isLaneCollapsed(e)},isLoadingColumn(e){return this.isLoading[e]||!1},isColumnFullyLoaded(e){return this.fullyLoaded[e]||!1},handleSmoothScroll(e){this.isLoadingColumn(e)||this.isColumnFullyLoaded(e)||(this.isLoading[e]=!0,this.$wire.loadMoreItems(e).then(()=>setTimeout(()=>this.isLoading[e]=!1,100)).catch(()=>this.isLoading[e]=!1))},handleColumnScroll(e,t){if(this.isColumnFullyLoaded(t))return;let{scrollTop:o,scrollHeight:r,clientHeight:n}=e.target;(o+n)/r>=.8&&!this.isLoadingColumn(t)&&this.handleSmoothScroll(t)}}}export{T as default}; +var L=["--ff-surface","--ff-surface-sunken","--ff-surface-raised","--ff-border","--ff-text","--ff-text-muted","--ff-accent","--ff-accent-tint","--ff-danger","--ff-warning","--ff-radius","--ff-gap","--ff-ease","--ff-duration","--ff-column-width","--ff-dot-size","--ff-overlay-radius","--ff-overlay-shadow","--ff-tray-bg","--ff-tray-radius","--ff-card-bg","--ff-card-ring","--ff-card-radius","--ff-card-shadow","--ff-card-padding","--ff-drag-tilt","--ff-drag-shadow","--ff-placeholder-border"],c='.ff-column-actions, .fi-dropdown-panel, input, textarea, select, [contenteditable]:not([contenteditable="false"])',C=`.ff-card, .ff-column-header, .ff-add-slot, .ff-add-row, .ff-cards-more, .ff-limit-hint, button, a, ${c}`,f=4,D=300,x=e=>{let t=e.querySelector("[data-autofocus]");!t||e.style.display!=="block"||!window.matchMedia("(pointer: fine)").matches||(t.focus({preventScroll:!0}),t.setSelectionRange?.(t.value.length,t.value.length))},p=4,h=e=>[...e.querySelectorAll('[role="radio"]')],w=new WeakSet,g=new WeakSet,b=()=>window.Sortable.active||window.Sortable.dragged;function T(){return{isLoading:{},fullyLoaded:{},dragOverColumn:null,railToggledAt:0,railClickTimer:null,columnMenuPressAt:null,railPressAt:null,dragOverLane:null,dragSource:null,pendingCounts:{},pendingMoves:0,collapsedLanes:{},addingColumn:!1,newColumnName:"",newColumnColor:null,newColumnDotStyle:"",newColumnColorPicked:!1,choosingNewColumnColor:!1,newColumnTouched:!1,addingColumnPending:!1,placeholder:null,stopTrackingPointer:null,init(){this.$wire.$on("kanban-items-loaded",e=>{let{columnId:t,isFullyLoaded:o}=e;o&&(this.fullyLoaded[t]=!0)})},configureSortable(e){if(!e.sortable||e.sortable.options.forceFallback)return;if(b()){this.configureSortableAfterDrag(e);return}let t=window.matchMedia("(prefers-reduced-motion: reduce)").matches;e.sortable.destroy(),e.sortable=window.Sortable.create(e,{draggable:"[x-sortable-item]",handle:"[x-sortable-handle]",dataIdAttr:"x-sortable-item",forceFallback:!0,fallbackTolerance:5,fallbackOnBody:!0,fallbackClass:"",ghostClass:"",delay:150,delayOnTouchOnly:!0,animation:t?0:200,scrollSensitivity:100,scrollSpeed:15,forceAutoScrollFallback:!0,group:{name:e.getAttribute("x-sortable-group"),pull:!0,put:(o,r)=>this.canDrop(o.el,r.el)},onStart:o=>this.startDrag(o),onEnd(o){let{item:r,to:n,oldDraggableIndex:s,newDraggableIndex:a}=o;if(s===a)return;let i=n.querySelectorAll(`:scope > ${this.options.draggable}`)[a-1];i&&n.insertBefore(r,i.nextSibling)}})},configureSortableAfterDrag(e){if(g.has(e))return;g.add(e);let t=()=>{if(b()){requestAnimationFrame(t);return}g.delete(e),e.isConnected&&this.configureSortable(e)};requestAnimationFrame(t)},startDrag(e){this.stopTrackingPointer?.(),this.placeholder=e.item,this.placeholder.setAttribute("data-placeholder",""),this.markGhost(),window.getSelection()?.removeAllRanges(),document.documentElement.classList.add("ff-dragging"),this.dragSource={column:e.from.dataset.columnId,lane:e.from.dataset.laneId??null};let t=o=>this.trackPointer(o);document.addEventListener("pointermove",t,{passive:!0}),document.addEventListener("touchmove",t,{passive:!0}),this.stopTrackingPointer=()=>{document.removeEventListener("pointermove",t),document.removeEventListener("touchmove",t)}},trackPointer(e){if(!window.Sortable.active){this.endDrag();return}this.markGhost();let t=e.touches?.[0]??e,o=document.elementFromPoint(t.clientX,t.clientY),r=o?.closest("[data-column-id]"),n=o?.closest("[data-column-root]");this.dragOverColumn=r?.dataset.columnId??n?.dataset.columnRoot??null,this.dragOverLane=r?.dataset.laneId??null},markGhost(){let e=window.Sortable.ghost;if(!e||e.hasAttribute("data-dragging"))return;e.removeAttribute("data-placeholder"),e.setAttribute("data-dragging",""),e.style.opacity="1";let t=getComputedStyle(this.placeholder);for(let o of L){let r=t.getPropertyValue(o);r!==""&&e.style.setProperty(o,r)}},endDrag(){document.documentElement.classList.remove("ff-dragging"),this.placeholder?.removeAttribute("data-placeholder"),this.placeholder=null,this.stopTrackingPointer?.(),this.stopTrackingPointer=null,this.dragOverColumn=null,this.dragOverLane=null,this.dragSource=null},railPress(e){this.railPressAt={x:e.clientX,y:e.clientY}},toggleColumnCollapse(e,t,o=!1){if(!(e.target.closest(c)||o&&e.detail>1)){if(o){let r=this.railPressAt;if(this.railPressAt=null,r&&Math.hypot(e.clientX-r.x,e.clientY-r.y)>f)return}Date.now()-this.railToggledAt<500||(o&&(this.railToggledAt=Date.now()),this.$wire.toggleBoardColumnCollapse(t))}},expandFromCollapseAll(e,t){let o=this.railPressAt;if(this.railPressAt=null,e.target.closest(c)||o&&Math.hypot(e.clientX-o.x,e.clientY-o.y)>f)return;let r=e.detail>1;clearTimeout(this.railClickTimer),this.railClickTimer=setTimeout(()=>{this.railToggledAt=Date.now(),this.$wire.toggleBoardColumnCollapse(t,r)},r?0:D)},collapseFromEmptySpace(e,t){e.target.closest(C)||this.toggleColumnCollapse(e,t)},suppressEmptySpaceSelection(e){e.detail>1&&!e.target.closest(C)&&e.preventDefault()},openNewColumn(e=null,t=""){this.addingColumn=!0,this.newColumnTouched=!0,this.newColumnColor=e,this.newColumnDotStyle=t,this.newColumnColorPicked=!1,this.$nextTick(()=>requestAnimationFrame(()=>{let o=this.$refs.newColumnInput,r=o.closest(".ff-columns, .ff-lanes");o.focus({preventScroll:!0}),r?.scrollTo({left:r.scrollWidth}),o.closest(".ff-add-column-ghost").scrollIntoView({block:"nearest"})}))},cancelNewColumn(){this.addingColumn=!1,this.newColumnTouched=!0,this.newColumnName="",this.newColumnColor=null,this.newColumnDotStyle="",this.choosingNewColumnColor=!1},closeNewColumnColors(){this.choosingNewColumnColor=!1,this.$refs.newColumnDot?.focus({preventScroll:!0})},pickNewColumnColor(e,t){this.newColumnColorPicked=!0,this.newColumnColor=e,this.newColumnDotStyle=t,this.choosingNewColumnColor=!1,this.$refs.newColumnInput.focus({preventScroll:!0})},async submitNewColumn(){if(!this.addingColumnPending){this.addingColumnPending=!0,this.newColumnTouched=!0;try{await this.$wire.addBoardColumn(this.newColumnName,this.newColumnColorPicked?this.newColumnColor:null)}finally{this.addingColumnPending=!1}this.newColumnTouched=!1,this.$root.querySelector(".ff-add-column-error")||this.cancelNewColumn()}},suppressDoubleClickSelection(e){e.detail>1&&!e.target.closest(c)&&e.preventDefault()},initColumnMenu(e){let t=e.closest(".fi-dropdown");if(w.has(t))return;let o=window.Alpine.$data(t),r=o.toggle.bind(o);w.add(t),o.toggle=n=>n?.type==="mousedown"?void 0:r(n)},columnMenuPress(e){this.columnMenuPressAt={x:e.clientX,y:e.clientY}},columnMenuClick(e){let t=this.columnMenuPressAt;if(this.columnMenuPressAt=null,e.detail>1||t&&Math.hypot(e.clientX-t.x,e.clientY-t.y)>f)return;let o=e.currentTarget.closest(".fi-dropdown");window.Alpine.$data(o).toggle(e),requestAnimationFrame(()=>x(o.querySelector(":scope > .fi-dropdown-panel")))},focusSwatch(e){let t=h(e);(t.find(r=>r.getAttribute("aria-checked")==="true")??t[0])?.focus({preventScroll:!0})},swatchFocused(e){let t=e.target.closest('[role="radiogroup"]');h(t).forEach(o=>o.setAttribute("tabindex",o===e.target?"0":"-1"))},swatchKey(e){let t=h(e.currentTarget),o=t.indexOf(e.target),r=t.length-1,n={ArrowRight:o===r?0:o+1,ArrowLeft:o===0?r:o-1,ArrowDown:Math.min(o+p,r),ArrowUp:Math.max(o-p,0),Home:0,End:r}[e.key];o<0||n===void 0||(e.preventDefault(),t[n].focus({preventScroll:!0}))},columnDrop(e){return this.dragOverColumn!==e?null:this.isColumnBlocked(e)?"blocked":"active"},cellDrop(e,t){return this.dragOverColumn!==e||this.dragOverLane!==t?null:this.isCellBlocked(e,t)?"blocked":"active"},canDrop(e,t){if(!this.$root.contains(e)||!this.$root.contains(t))return!1;let o=e.dataset.laneId??null,r=t.dataset.laneId??null;return o!==r&&this.$root.dataset.lanesWritable!=="true"?!1:!this.isColumnBlocked(e.dataset.columnId,t.dataset.columnId)},isColumnBlocked(e,t=this.dragSource?.column){if(!e||e===t)return!1;let o=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"]`),r=o?.dataset.columnLimit;return r===void 0||r===""?!1:Number(o.dataset.columnTotal)>=Number(r)},isCellBlocked(e,t){return this.dragSource?t!==this.dragSource.lane&&this.$root.dataset.lanesWritable!=="true"?!0:this.isColumnBlocked(e):!1},displayCount(e,t){let o=this.pendingCounts[e]??t,r=this.dragSource?.column,n=this.dragOverColumn;return!r||!n||r===n||this.isColumnBlocked(n)?o:e===n?o+1:e===r?o-1:o},holdMovedCounts(e,t){if(e===t)return()=>{};let o={[e]:-1,[t]:1},r=!1;for(let[n,s]of Object.entries(o))this.pendingCounts[n]=this.renderedCount(n)+s;return this.pendingMoves++,n=>{if(!r){if(r=!0,n)for(let[s,a]of Object.entries(o))this.pendingCounts[s]-=a;--this.pendingMoves===0&&(this.pendingCounts={})}}},renderedCount(e){let t=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"] .ff-count`);return this.pendingCounts[e]??Number(t?.dataset.total)},handleSortableEnd(e){this.endDrag();let t=e.item,o=e.to,r=e.newDraggableIndex??e.newIndex,n=":scope > [x-sortable-item], :scope > [data-card-id]",s=l=>l.getAttribute("x-sortable-item")||l.getAttribute("data-card-id");if(e.from===o&&e.oldDraggableIndex===e.newDraggableIndex)return;if(r===0){let l=o.querySelector(n);l&&l!==t&&o.insertBefore(t,l)}let a=s(t);if(!a){console.error("Flowforge: Could not determine card ID for move operation");return}let i=o.getAttribute("data-column-id");if(!i){console.error("Flowforge: Target column ID is missing");return}let S=e.from.dataset.laneId??null,y=o.dataset.laneId??null,d=o.querySelectorAll(n),u=Array.prototype.indexOf.call(d,t),A=u>0?s(d[u-1]):null,k=u>=0&&u{this.setCardState(t,!1),m(l===!1),l===!1&&this.revertCard(e)}).catch(()=>{this.setCardState(t,!1),m(!0),this.revertCard(e)})},revertCard({item:e,from:t,oldDraggableIndex:o}){e.remove();let r=t.querySelectorAll(":scope > [x-sortable-item]"),n=r[r.length-1],s=r[o]??(n?n.nextSibling:t.firstChild);t.insertBefore(e,s)},setCardState(e,t){e.toggleAttribute("data-pending",t)},isLaneCollapsed(e){return this.collapsedLanes[e]===!0},toggleLane(e){this.collapsedLanes[e]=!this.isLaneCollapsed(e)},isLoadingColumn(e){return this.isLoading[e]||!1},isColumnFullyLoaded(e){return this.fullyLoaded[e]||!1},handleSmoothScroll(e){this.isLoadingColumn(e)||this.isColumnFullyLoaded(e)||(this.isLoading[e]=!0,this.$wire.loadMoreItems(e).then(()=>setTimeout(()=>this.isLoading[e]=!1,100)).catch(()=>this.isLoading[e]=!1))},handleColumnScroll(e,t){if(this.isColumnFullyLoaded(t))return;let{scrollTop:o,scrollHeight:r,clientHeight:n}=e.target;(o+n)/r>=.8&&!this.isLoadingColumn(t)&&this.handleSmoothScroll(t)}}}export{T as default}; diff --git a/resources/js/flowforge-modern.js b/resources/js/flowforge-modern.js index 479be8274..8865288e6 100644 --- a/resources/js/flowforge-modern.js +++ b/resources/js/flowforge-modern.js @@ -15,6 +15,8 @@ const FLOWFORGE_TOKENS = [ '--ff-duration', '--ff-column-width', '--ff-dot-size', + '--ff-overlay-radius', + '--ff-overlay-shadow', '--ff-tray-bg', '--ff-tray-radius', '--ff-card-bg', From 357bfdd41f8a004ff935cf8121308a9d9fd6ef3b Mon Sep 17 00:00:00 2001 From: Manuk Date: Sun, 15 Nov 2026 04:24:01 +0400 Subject: [PATCH 32/34] fix(columns): cap the column menu to the room left in the window --- resources/views/modern/livewire/column-header.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/modern/livewire/column-header.blade.php b/resources/views/modern/livewire/column-header.blade.php index ca77da27a..47039d345 100644 --- a/resources/views/modern/livewire/column-header.blade.php +++ b/resources/views/modern/livewire/column-header.blade.php @@ -32,7 +32,7 @@ class="ff-column-header" @endif > @if ($hasMenu) - + Date: Sun, 15 Nov 2026 05:06:53 +0400 Subject: [PATCH 33/34] fix(columns): focus the current swatch a frame after the grid shows so webkit moves focus --- resources/dist/flowforge-modern.js | 2 +- resources/js/flowforge-modern.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/resources/dist/flowforge-modern.js b/resources/dist/flowforge-modern.js index d6fcad0a9..6fa3b8ff4 100644 --- a/resources/dist/flowforge-modern.js +++ b/resources/dist/flowforge-modern.js @@ -1 +1 @@ -var L=["--ff-surface","--ff-surface-sunken","--ff-surface-raised","--ff-border","--ff-text","--ff-text-muted","--ff-accent","--ff-accent-tint","--ff-danger","--ff-warning","--ff-radius","--ff-gap","--ff-ease","--ff-duration","--ff-column-width","--ff-dot-size","--ff-overlay-radius","--ff-overlay-shadow","--ff-tray-bg","--ff-tray-radius","--ff-card-bg","--ff-card-ring","--ff-card-radius","--ff-card-shadow","--ff-card-padding","--ff-drag-tilt","--ff-drag-shadow","--ff-placeholder-border"],c='.ff-column-actions, .fi-dropdown-panel, input, textarea, select, [contenteditable]:not([contenteditable="false"])',C=`.ff-card, .ff-column-header, .ff-add-slot, .ff-add-row, .ff-cards-more, .ff-limit-hint, button, a, ${c}`,f=4,D=300,x=e=>{let t=e.querySelector("[data-autofocus]");!t||e.style.display!=="block"||!window.matchMedia("(pointer: fine)").matches||(t.focus({preventScroll:!0}),t.setSelectionRange?.(t.value.length,t.value.length))},p=4,h=e=>[...e.querySelectorAll('[role="radio"]')],w=new WeakSet,g=new WeakSet,b=()=>window.Sortable.active||window.Sortable.dragged;function T(){return{isLoading:{},fullyLoaded:{},dragOverColumn:null,railToggledAt:0,railClickTimer:null,columnMenuPressAt:null,railPressAt:null,dragOverLane:null,dragSource:null,pendingCounts:{},pendingMoves:0,collapsedLanes:{},addingColumn:!1,newColumnName:"",newColumnColor:null,newColumnDotStyle:"",newColumnColorPicked:!1,choosingNewColumnColor:!1,newColumnTouched:!1,addingColumnPending:!1,placeholder:null,stopTrackingPointer:null,init(){this.$wire.$on("kanban-items-loaded",e=>{let{columnId:t,isFullyLoaded:o}=e;o&&(this.fullyLoaded[t]=!0)})},configureSortable(e){if(!e.sortable||e.sortable.options.forceFallback)return;if(b()){this.configureSortableAfterDrag(e);return}let t=window.matchMedia("(prefers-reduced-motion: reduce)").matches;e.sortable.destroy(),e.sortable=window.Sortable.create(e,{draggable:"[x-sortable-item]",handle:"[x-sortable-handle]",dataIdAttr:"x-sortable-item",forceFallback:!0,fallbackTolerance:5,fallbackOnBody:!0,fallbackClass:"",ghostClass:"",delay:150,delayOnTouchOnly:!0,animation:t?0:200,scrollSensitivity:100,scrollSpeed:15,forceAutoScrollFallback:!0,group:{name:e.getAttribute("x-sortable-group"),pull:!0,put:(o,r)=>this.canDrop(o.el,r.el)},onStart:o=>this.startDrag(o),onEnd(o){let{item:r,to:n,oldDraggableIndex:s,newDraggableIndex:a}=o;if(s===a)return;let i=n.querySelectorAll(`:scope > ${this.options.draggable}`)[a-1];i&&n.insertBefore(r,i.nextSibling)}})},configureSortableAfterDrag(e){if(g.has(e))return;g.add(e);let t=()=>{if(b()){requestAnimationFrame(t);return}g.delete(e),e.isConnected&&this.configureSortable(e)};requestAnimationFrame(t)},startDrag(e){this.stopTrackingPointer?.(),this.placeholder=e.item,this.placeholder.setAttribute("data-placeholder",""),this.markGhost(),window.getSelection()?.removeAllRanges(),document.documentElement.classList.add("ff-dragging"),this.dragSource={column:e.from.dataset.columnId,lane:e.from.dataset.laneId??null};let t=o=>this.trackPointer(o);document.addEventListener("pointermove",t,{passive:!0}),document.addEventListener("touchmove",t,{passive:!0}),this.stopTrackingPointer=()=>{document.removeEventListener("pointermove",t),document.removeEventListener("touchmove",t)}},trackPointer(e){if(!window.Sortable.active){this.endDrag();return}this.markGhost();let t=e.touches?.[0]??e,o=document.elementFromPoint(t.clientX,t.clientY),r=o?.closest("[data-column-id]"),n=o?.closest("[data-column-root]");this.dragOverColumn=r?.dataset.columnId??n?.dataset.columnRoot??null,this.dragOverLane=r?.dataset.laneId??null},markGhost(){let e=window.Sortable.ghost;if(!e||e.hasAttribute("data-dragging"))return;e.removeAttribute("data-placeholder"),e.setAttribute("data-dragging",""),e.style.opacity="1";let t=getComputedStyle(this.placeholder);for(let o of L){let r=t.getPropertyValue(o);r!==""&&e.style.setProperty(o,r)}},endDrag(){document.documentElement.classList.remove("ff-dragging"),this.placeholder?.removeAttribute("data-placeholder"),this.placeholder=null,this.stopTrackingPointer?.(),this.stopTrackingPointer=null,this.dragOverColumn=null,this.dragOverLane=null,this.dragSource=null},railPress(e){this.railPressAt={x:e.clientX,y:e.clientY}},toggleColumnCollapse(e,t,o=!1){if(!(e.target.closest(c)||o&&e.detail>1)){if(o){let r=this.railPressAt;if(this.railPressAt=null,r&&Math.hypot(e.clientX-r.x,e.clientY-r.y)>f)return}Date.now()-this.railToggledAt<500||(o&&(this.railToggledAt=Date.now()),this.$wire.toggleBoardColumnCollapse(t))}},expandFromCollapseAll(e,t){let o=this.railPressAt;if(this.railPressAt=null,e.target.closest(c)||o&&Math.hypot(e.clientX-o.x,e.clientY-o.y)>f)return;let r=e.detail>1;clearTimeout(this.railClickTimer),this.railClickTimer=setTimeout(()=>{this.railToggledAt=Date.now(),this.$wire.toggleBoardColumnCollapse(t,r)},r?0:D)},collapseFromEmptySpace(e,t){e.target.closest(C)||this.toggleColumnCollapse(e,t)},suppressEmptySpaceSelection(e){e.detail>1&&!e.target.closest(C)&&e.preventDefault()},openNewColumn(e=null,t=""){this.addingColumn=!0,this.newColumnTouched=!0,this.newColumnColor=e,this.newColumnDotStyle=t,this.newColumnColorPicked=!1,this.$nextTick(()=>requestAnimationFrame(()=>{let o=this.$refs.newColumnInput,r=o.closest(".ff-columns, .ff-lanes");o.focus({preventScroll:!0}),r?.scrollTo({left:r.scrollWidth}),o.closest(".ff-add-column-ghost").scrollIntoView({block:"nearest"})}))},cancelNewColumn(){this.addingColumn=!1,this.newColumnTouched=!0,this.newColumnName="",this.newColumnColor=null,this.newColumnDotStyle="",this.choosingNewColumnColor=!1},closeNewColumnColors(){this.choosingNewColumnColor=!1,this.$refs.newColumnDot?.focus({preventScroll:!0})},pickNewColumnColor(e,t){this.newColumnColorPicked=!0,this.newColumnColor=e,this.newColumnDotStyle=t,this.choosingNewColumnColor=!1,this.$refs.newColumnInput.focus({preventScroll:!0})},async submitNewColumn(){if(!this.addingColumnPending){this.addingColumnPending=!0,this.newColumnTouched=!0;try{await this.$wire.addBoardColumn(this.newColumnName,this.newColumnColorPicked?this.newColumnColor:null)}finally{this.addingColumnPending=!1}this.newColumnTouched=!1,this.$root.querySelector(".ff-add-column-error")||this.cancelNewColumn()}},suppressDoubleClickSelection(e){e.detail>1&&!e.target.closest(c)&&e.preventDefault()},initColumnMenu(e){let t=e.closest(".fi-dropdown");if(w.has(t))return;let o=window.Alpine.$data(t),r=o.toggle.bind(o);w.add(t),o.toggle=n=>n?.type==="mousedown"?void 0:r(n)},columnMenuPress(e){this.columnMenuPressAt={x:e.clientX,y:e.clientY}},columnMenuClick(e){let t=this.columnMenuPressAt;if(this.columnMenuPressAt=null,e.detail>1||t&&Math.hypot(e.clientX-t.x,e.clientY-t.y)>f)return;let o=e.currentTarget.closest(".fi-dropdown");window.Alpine.$data(o).toggle(e),requestAnimationFrame(()=>x(o.querySelector(":scope > .fi-dropdown-panel")))},focusSwatch(e){let t=h(e);(t.find(r=>r.getAttribute("aria-checked")==="true")??t[0])?.focus({preventScroll:!0})},swatchFocused(e){let t=e.target.closest('[role="radiogroup"]');h(t).forEach(o=>o.setAttribute("tabindex",o===e.target?"0":"-1"))},swatchKey(e){let t=h(e.currentTarget),o=t.indexOf(e.target),r=t.length-1,n={ArrowRight:o===r?0:o+1,ArrowLeft:o===0?r:o-1,ArrowDown:Math.min(o+p,r),ArrowUp:Math.max(o-p,0),Home:0,End:r}[e.key];o<0||n===void 0||(e.preventDefault(),t[n].focus({preventScroll:!0}))},columnDrop(e){return this.dragOverColumn!==e?null:this.isColumnBlocked(e)?"blocked":"active"},cellDrop(e,t){return this.dragOverColumn!==e||this.dragOverLane!==t?null:this.isCellBlocked(e,t)?"blocked":"active"},canDrop(e,t){if(!this.$root.contains(e)||!this.$root.contains(t))return!1;let o=e.dataset.laneId??null,r=t.dataset.laneId??null;return o!==r&&this.$root.dataset.lanesWritable!=="true"?!1:!this.isColumnBlocked(e.dataset.columnId,t.dataset.columnId)},isColumnBlocked(e,t=this.dragSource?.column){if(!e||e===t)return!1;let o=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"]`),r=o?.dataset.columnLimit;return r===void 0||r===""?!1:Number(o.dataset.columnTotal)>=Number(r)},isCellBlocked(e,t){return this.dragSource?t!==this.dragSource.lane&&this.$root.dataset.lanesWritable!=="true"?!0:this.isColumnBlocked(e):!1},displayCount(e,t){let o=this.pendingCounts[e]??t,r=this.dragSource?.column,n=this.dragOverColumn;return!r||!n||r===n||this.isColumnBlocked(n)?o:e===n?o+1:e===r?o-1:o},holdMovedCounts(e,t){if(e===t)return()=>{};let o={[e]:-1,[t]:1},r=!1;for(let[n,s]of Object.entries(o))this.pendingCounts[n]=this.renderedCount(n)+s;return this.pendingMoves++,n=>{if(!r){if(r=!0,n)for(let[s,a]of Object.entries(o))this.pendingCounts[s]-=a;--this.pendingMoves===0&&(this.pendingCounts={})}}},renderedCount(e){let t=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"] .ff-count`);return this.pendingCounts[e]??Number(t?.dataset.total)},handleSortableEnd(e){this.endDrag();let t=e.item,o=e.to,r=e.newDraggableIndex??e.newIndex,n=":scope > [x-sortable-item], :scope > [data-card-id]",s=l=>l.getAttribute("x-sortable-item")||l.getAttribute("data-card-id");if(e.from===o&&e.oldDraggableIndex===e.newDraggableIndex)return;if(r===0){let l=o.querySelector(n);l&&l!==t&&o.insertBefore(t,l)}let a=s(t);if(!a){console.error("Flowforge: Could not determine card ID for move operation");return}let i=o.getAttribute("data-column-id");if(!i){console.error("Flowforge: Target column ID is missing");return}let S=e.from.dataset.laneId??null,y=o.dataset.laneId??null,d=o.querySelectorAll(n),u=Array.prototype.indexOf.call(d,t),A=u>0?s(d[u-1]):null,k=u>=0&&u{this.setCardState(t,!1),m(l===!1),l===!1&&this.revertCard(e)}).catch(()=>{this.setCardState(t,!1),m(!0),this.revertCard(e)})},revertCard({item:e,from:t,oldDraggableIndex:o}){e.remove();let r=t.querySelectorAll(":scope > [x-sortable-item]"),n=r[r.length-1],s=r[o]??(n?n.nextSibling:t.firstChild);t.insertBefore(e,s)},setCardState(e,t){e.toggleAttribute("data-pending",t)},isLaneCollapsed(e){return this.collapsedLanes[e]===!0},toggleLane(e){this.collapsedLanes[e]=!this.isLaneCollapsed(e)},isLoadingColumn(e){return this.isLoading[e]||!1},isColumnFullyLoaded(e){return this.fullyLoaded[e]||!1},handleSmoothScroll(e){this.isLoadingColumn(e)||this.isColumnFullyLoaded(e)||(this.isLoading[e]=!0,this.$wire.loadMoreItems(e).then(()=>setTimeout(()=>this.isLoading[e]=!1,100)).catch(()=>this.isLoading[e]=!1))},handleColumnScroll(e,t){if(this.isColumnFullyLoaded(t))return;let{scrollTop:o,scrollHeight:r,clientHeight:n}=e.target;(o+n)/r>=.8&&!this.isLoadingColumn(t)&&this.handleSmoothScroll(t)}}}export{T as default}; +var L=["--ff-surface","--ff-surface-sunken","--ff-surface-raised","--ff-border","--ff-text","--ff-text-muted","--ff-accent","--ff-accent-tint","--ff-danger","--ff-warning","--ff-radius","--ff-gap","--ff-ease","--ff-duration","--ff-column-width","--ff-dot-size","--ff-overlay-radius","--ff-overlay-shadow","--ff-tray-bg","--ff-tray-radius","--ff-card-bg","--ff-card-ring","--ff-card-radius","--ff-card-shadow","--ff-card-padding","--ff-drag-tilt","--ff-drag-shadow","--ff-placeholder-border"],c='.ff-column-actions, .fi-dropdown-panel, input, textarea, select, [contenteditable]:not([contenteditable="false"])',C=`.ff-card, .ff-column-header, .ff-add-slot, .ff-add-row, .ff-cards-more, .ff-limit-hint, button, a, ${c}`,f=4,D=300,x=e=>{let t=e.querySelector("[data-autofocus]");!t||e.style.display!=="block"||!window.matchMedia("(pointer: fine)").matches||(t.focus({preventScroll:!0}),t.setSelectionRange?.(t.value.length,t.value.length))},p=4,h=e=>[...e.querySelectorAll('[role="radio"]')],w=new WeakSet,g=new WeakSet,b=()=>window.Sortable.active||window.Sortable.dragged;function T(){return{isLoading:{},fullyLoaded:{},dragOverColumn:null,railToggledAt:0,railClickTimer:null,columnMenuPressAt:null,railPressAt:null,dragOverLane:null,dragSource:null,pendingCounts:{},pendingMoves:0,collapsedLanes:{},addingColumn:!1,newColumnName:"",newColumnColor:null,newColumnDotStyle:"",newColumnColorPicked:!1,choosingNewColumnColor:!1,newColumnTouched:!1,addingColumnPending:!1,placeholder:null,stopTrackingPointer:null,init(){this.$wire.$on("kanban-items-loaded",e=>{let{columnId:t,isFullyLoaded:o}=e;o&&(this.fullyLoaded[t]=!0)})},configureSortable(e){if(!e.sortable||e.sortable.options.forceFallback)return;if(b()){this.configureSortableAfterDrag(e);return}let t=window.matchMedia("(prefers-reduced-motion: reduce)").matches;e.sortable.destroy(),e.sortable=window.Sortable.create(e,{draggable:"[x-sortable-item]",handle:"[x-sortable-handle]",dataIdAttr:"x-sortable-item",forceFallback:!0,fallbackTolerance:5,fallbackOnBody:!0,fallbackClass:"",ghostClass:"",delay:150,delayOnTouchOnly:!0,animation:t?0:200,scrollSensitivity:100,scrollSpeed:15,forceAutoScrollFallback:!0,group:{name:e.getAttribute("x-sortable-group"),pull:!0,put:(o,r)=>this.canDrop(o.el,r.el)},onStart:o=>this.startDrag(o),onEnd(o){let{item:r,to:n,oldDraggableIndex:s,newDraggableIndex:a}=o;if(s===a)return;let i=n.querySelectorAll(`:scope > ${this.options.draggable}`)[a-1];i&&n.insertBefore(r,i.nextSibling)}})},configureSortableAfterDrag(e){if(g.has(e))return;g.add(e);let t=()=>{if(b()){requestAnimationFrame(t);return}g.delete(e),e.isConnected&&this.configureSortable(e)};requestAnimationFrame(t)},startDrag(e){this.stopTrackingPointer?.(),this.placeholder=e.item,this.placeholder.setAttribute("data-placeholder",""),this.markGhost(),window.getSelection()?.removeAllRanges(),document.documentElement.classList.add("ff-dragging"),this.dragSource={column:e.from.dataset.columnId,lane:e.from.dataset.laneId??null};let t=o=>this.trackPointer(o);document.addEventListener("pointermove",t,{passive:!0}),document.addEventListener("touchmove",t,{passive:!0}),this.stopTrackingPointer=()=>{document.removeEventListener("pointermove",t),document.removeEventListener("touchmove",t)}},trackPointer(e){if(!window.Sortable.active){this.endDrag();return}this.markGhost();let t=e.touches?.[0]??e,o=document.elementFromPoint(t.clientX,t.clientY),r=o?.closest("[data-column-id]"),n=o?.closest("[data-column-root]");this.dragOverColumn=r?.dataset.columnId??n?.dataset.columnRoot??null,this.dragOverLane=r?.dataset.laneId??null},markGhost(){let e=window.Sortable.ghost;if(!e||e.hasAttribute("data-dragging"))return;e.removeAttribute("data-placeholder"),e.setAttribute("data-dragging",""),e.style.opacity="1";let t=getComputedStyle(this.placeholder);for(let o of L){let r=t.getPropertyValue(o);r!==""&&e.style.setProperty(o,r)}},endDrag(){document.documentElement.classList.remove("ff-dragging"),this.placeholder?.removeAttribute("data-placeholder"),this.placeholder=null,this.stopTrackingPointer?.(),this.stopTrackingPointer=null,this.dragOverColumn=null,this.dragOverLane=null,this.dragSource=null},railPress(e){this.railPressAt={x:e.clientX,y:e.clientY}},toggleColumnCollapse(e,t,o=!1){if(!(e.target.closest(c)||o&&e.detail>1)){if(o){let r=this.railPressAt;if(this.railPressAt=null,r&&Math.hypot(e.clientX-r.x,e.clientY-r.y)>f)return}Date.now()-this.railToggledAt<500||(o&&(this.railToggledAt=Date.now()),this.$wire.toggleBoardColumnCollapse(t))}},expandFromCollapseAll(e,t){let o=this.railPressAt;if(this.railPressAt=null,e.target.closest(c)||o&&Math.hypot(e.clientX-o.x,e.clientY-o.y)>f)return;let r=e.detail>1;clearTimeout(this.railClickTimer),this.railClickTimer=setTimeout(()=>{this.railToggledAt=Date.now(),this.$wire.toggleBoardColumnCollapse(t,r)},r?0:D)},collapseFromEmptySpace(e,t){e.target.closest(C)||this.toggleColumnCollapse(e,t)},suppressEmptySpaceSelection(e){e.detail>1&&!e.target.closest(C)&&e.preventDefault()},openNewColumn(e=null,t=""){this.addingColumn=!0,this.newColumnTouched=!0,this.newColumnColor=e,this.newColumnDotStyle=t,this.newColumnColorPicked=!1,this.$nextTick(()=>requestAnimationFrame(()=>{let o=this.$refs.newColumnInput,r=o.closest(".ff-columns, .ff-lanes");o.focus({preventScroll:!0}),r?.scrollTo({left:r.scrollWidth}),o.closest(".ff-add-column-ghost").scrollIntoView({block:"nearest"})}))},cancelNewColumn(){this.addingColumn=!1,this.newColumnTouched=!0,this.newColumnName="",this.newColumnColor=null,this.newColumnDotStyle="",this.choosingNewColumnColor=!1},closeNewColumnColors(){this.choosingNewColumnColor=!1,this.$refs.newColumnDot?.focus({preventScroll:!0})},pickNewColumnColor(e,t){this.newColumnColorPicked=!0,this.newColumnColor=e,this.newColumnDotStyle=t,this.choosingNewColumnColor=!1,this.$refs.newColumnInput.focus({preventScroll:!0})},async submitNewColumn(){if(!this.addingColumnPending){this.addingColumnPending=!0,this.newColumnTouched=!0;try{await this.$wire.addBoardColumn(this.newColumnName,this.newColumnColorPicked?this.newColumnColor:null)}finally{this.addingColumnPending=!1}this.newColumnTouched=!1,this.$root.querySelector(".ff-add-column-error")||this.cancelNewColumn()}},suppressDoubleClickSelection(e){e.detail>1&&!e.target.closest(c)&&e.preventDefault()},initColumnMenu(e){let t=e.closest(".fi-dropdown");if(w.has(t))return;let o=window.Alpine.$data(t),r=o.toggle.bind(o);w.add(t),o.toggle=n=>n?.type==="mousedown"?void 0:r(n)},columnMenuPress(e){this.columnMenuPressAt={x:e.clientX,y:e.clientY}},columnMenuClick(e){let t=this.columnMenuPressAt;if(this.columnMenuPressAt=null,e.detail>1||t&&Math.hypot(e.clientX-t.x,e.clientY-t.y)>f)return;let o=e.currentTarget.closest(".fi-dropdown");window.Alpine.$data(o).toggle(e),requestAnimationFrame(()=>x(o.querySelector(":scope > .fi-dropdown-panel")))},focusSwatch(e){let t=h(e),o=t.find(r=>r.getAttribute("aria-checked")==="true")??t[0];requestAnimationFrame(()=>o?.focus({preventScroll:!0}))},swatchFocused(e){let t=e.target.closest('[role="radiogroup"]');h(t).forEach(o=>o.setAttribute("tabindex",o===e.target?"0":"-1"))},swatchKey(e){let t=h(e.currentTarget),o=t.indexOf(e.target),r=t.length-1,n={ArrowRight:o===r?0:o+1,ArrowLeft:o===0?r:o-1,ArrowDown:Math.min(o+p,r),ArrowUp:Math.max(o-p,0),Home:0,End:r}[e.key];o<0||n===void 0||(e.preventDefault(),t[n].focus({preventScroll:!0}))},columnDrop(e){return this.dragOverColumn!==e?null:this.isColumnBlocked(e)?"blocked":"active"},cellDrop(e,t){return this.dragOverColumn!==e||this.dragOverLane!==t?null:this.isCellBlocked(e,t)?"blocked":"active"},canDrop(e,t){if(!this.$root.contains(e)||!this.$root.contains(t))return!1;let o=e.dataset.laneId??null,r=t.dataset.laneId??null;return o!==r&&this.$root.dataset.lanesWritable!=="true"?!1:!this.isColumnBlocked(e.dataset.columnId,t.dataset.columnId)},isColumnBlocked(e,t=this.dragSource?.column){if(!e||e===t)return!1;let o=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"]`),r=o?.dataset.columnLimit;return r===void 0||r===""?!1:Number(o.dataset.columnTotal)>=Number(r)},isCellBlocked(e,t){return this.dragSource?t!==this.dragSource.lane&&this.$root.dataset.lanesWritable!=="true"?!0:this.isColumnBlocked(e):!1},displayCount(e,t){let o=this.pendingCounts[e]??t,r=this.dragSource?.column,n=this.dragOverColumn;return!r||!n||r===n||this.isColumnBlocked(n)?o:e===n?o+1:e===r?o-1:o},holdMovedCounts(e,t){if(e===t)return()=>{};let o={[e]:-1,[t]:1},r=!1;for(let[n,s]of Object.entries(o))this.pendingCounts[n]=this.renderedCount(n)+s;return this.pendingMoves++,n=>{if(!r){if(r=!0,n)for(let[s,a]of Object.entries(o))this.pendingCounts[s]-=a;--this.pendingMoves===0&&(this.pendingCounts={})}}},renderedCount(e){let t=this.$root.querySelector(`[data-column-root="${CSS.escape(e)}"] .ff-count`);return this.pendingCounts[e]??Number(t?.dataset.total)},handleSortableEnd(e){this.endDrag();let t=e.item,o=e.to,r=e.newDraggableIndex??e.newIndex,n=":scope > [x-sortable-item], :scope > [data-card-id]",s=l=>l.getAttribute("x-sortable-item")||l.getAttribute("data-card-id");if(e.from===o&&e.oldDraggableIndex===e.newDraggableIndex)return;if(r===0){let l=o.querySelector(n);l&&l!==t&&o.insertBefore(t,l)}let a=s(t);if(!a){console.error("Flowforge: Could not determine card ID for move operation");return}let i=o.getAttribute("data-column-id");if(!i){console.error("Flowforge: Target column ID is missing");return}let S=e.from.dataset.laneId??null,y=o.dataset.laneId??null,d=o.querySelectorAll(n),u=Array.prototype.indexOf.call(d,t),A=u>0?s(d[u-1]):null,k=u>=0&&u{this.setCardState(t,!1),m(l===!1),l===!1&&this.revertCard(e)}).catch(()=>{this.setCardState(t,!1),m(!0),this.revertCard(e)})},revertCard({item:e,from:t,oldDraggableIndex:o}){e.remove();let r=t.querySelectorAll(":scope > [x-sortable-item]"),n=r[r.length-1],s=r[o]??(n?n.nextSibling:t.firstChild);t.insertBefore(e,s)},setCardState(e,t){e.toggleAttribute("data-pending",t)},isLaneCollapsed(e){return this.collapsedLanes[e]===!0},toggleLane(e){this.collapsedLanes[e]=!this.isLaneCollapsed(e)},isLoadingColumn(e){return this.isLoading[e]||!1},isColumnFullyLoaded(e){return this.fullyLoaded[e]||!1},handleSmoothScroll(e){this.isLoadingColumn(e)||this.isColumnFullyLoaded(e)||(this.isLoading[e]=!0,this.$wire.loadMoreItems(e).then(()=>setTimeout(()=>this.isLoading[e]=!1,100)).catch(()=>this.isLoading[e]=!1))},handleColumnScroll(e,t){if(this.isColumnFullyLoaded(t))return;let{scrollTop:o,scrollHeight:r,clientHeight:n}=e.target;(o+n)/r>=.8&&!this.isLoadingColumn(t)&&this.handleSmoothScroll(t)}}}export{T as default}; diff --git a/resources/js/flowforge-modern.js b/resources/js/flowforge-modern.js index 8865288e6..0a3485bb3 100644 --- a/resources/js/flowforge-modern.js +++ b/resources/js/flowforge-modern.js @@ -421,7 +421,8 @@ export default function flowforgeModern() { const swatches = swatchesOf(group); const target = swatches.find((swatch) => swatch.getAttribute('aria-checked') === 'true') ?? swatches[0]; - target?.focus({ preventScroll: true }); + // WebKit applies x-show a frame after Alpine's next tick, and a hidden button refuses focus. + requestAnimationFrame(() => target?.focus({ preventScroll: true })); }, swatchFocused(event) { From 8d01130308f505c8187b4994389e942f66ff467b Mon Sep 17 00:00:00 2001 From: Manuk Date: Sun, 15 Nov 2026 15:22:37 +0400 Subject: [PATCH 34/34] fix(cards): wrap an unbreakable title inside its box --- resources/css/flowforge-modern.css | 1 + tests/Browser/ModernBoardTest.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/resources/css/flowforge-modern.css b/resources/css/flowforge-modern.css index e2ae4c468..022190400 100644 --- a/resources/css/flowforge-modern.css +++ b/resources/css/flowforge-modern.css @@ -451,6 +451,7 @@ font-size: 0.875rem; line-height: 1.25rem; font-weight: 500; + overflow-wrap: anywhere; color: var(--_text); } diff --git a/tests/Browser/ModernBoardTest.php b/tests/Browser/ModernBoardTest.php index 6def0f03d..10491f173 100644 --- a/tests/Browser/ModernBoardTest.php +++ b/tests/Browser/ModernBoardTest.php @@ -1127,6 +1127,21 @@ function boardTraySampler(int $budgetMilliseconds): string ->and($page->script("document.querySelector('{$heading}').scrollWidth"))->toBeLessThanOrEqual(40); }); +test('an unbreakable card title wraps inside the title box and clear of the hover actions', function () { + $task = Task::query()->create([ + 'title' => 'https://github.com/llyapashayan20/c3-engine', + 'status' => 'todo', + 'order_position' => '500.0000000000', + 'priority' => 'medium', + ]); + $page = boardPage('/modern/test-add-column-board'); + $title = boardCard($task) . ' .ff-card-title'; + + $overflow = $page->script("(() => { const title = document.querySelector('{$title}'); const box = title.getBoundingClientRect(); const limit = box.right - parseFloat(getComputedStyle(title).paddingInlineEnd); const range = document.createRange(); range.selectNodeContents(title); return Math.max(...[...range.getClientRects()].map((line) => line.right - limit)); })()"); + + expect($overflow)->toBeLessThanOrEqual(0.5); +}); + test('clicking the add column tile, typing a name and pressing enter adds the column', function () { boardSeed(); $page = boardPage('/modern/test-add-column-board');