diff --git a/docs/content/2.essentials/2.customization.md b/docs/content/2.essentials/2.customization.md index 26aa76c04..b3090770f 100644 --- a/docs/content/2.essentials/2.customization.md +++ b/docs/content/2.essentials/2.customization.md @@ -290,6 +290,122 @@ 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. + +### Let users toggle columns + +`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: + +```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. + +A rail collapsed by `collapsedColumns()` or `collapseAllColumns()` expands on a click. Under +`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. + +### 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, 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 +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. + +### Add a column from the board + +`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: + +```php +use Illuminate\Validation\ValidationException; + +->addColumnUsing(function (string $name): void { + throw_if( + $this->stages->contains($name), + ValidationException::withMessages(['name' => 'That stage already exists.']), + ); + + $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". `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. + +`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`. `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', '#a2a4a7' => 'Gray']) +->addColumnDefaultColor('#a2a4a7') +``` + +The picker is a radio group. Arrow keys move between swatches, Enter or Space picks one, and Escape closes the grid and returns focus to the dot. `addColumnColorLabel()` sets each swatch's accessible name, with `:color` standing for the palette label, and defaults to "Set color to :color". + +Opening the form scrolls the board to its end, so the new column and the tile both show. + ## 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..6e8cde4c7 100644 --- a/docs/content/2.essentials/4.api-reference.md +++ b/docs/content/2.essentials/4.api-reference.md @@ -28,6 +28,14 @@ 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 | | +| `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" | | +| `addColumnPlaceholder(string\|Closure\|null)` | The input's placeholder. Defaults to "Column name" | | +| `addColumnColorLabel(string\|Closure\|null)` | The accessible name of each swatch in the color picker. `:color` stands for the palette label. Defaults to "Set color to :color" | | ## Board Methods @@ -138,6 +146,14 @@ 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 +->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 +->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 +->addColumnColorLabel('Pick :color') // Accessible name of a color swatch ``` ### Modern board additions diff --git a/docs/content/2.essentials/6.swimlanes.md b/docs/content/2.essentials/6.swimlanes.md index 838f0f3b8..d67cab6fe 100644 --- a/docs/content/2.essentials/6.swimlanes.md +++ b/docs/content/2.essentials/6.swimlanes.md @@ -91,4 +91,8 @@ 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 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 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/docs/content/2.essentials/7.design-system.md b/docs/content/2.essentials/7.design-system.md index 208aaabc3..976c26932 100644 --- a/docs/content/2.essentials/7.design-system.md +++ b/docs/content/2.essentials/7.design-system.md @@ -54,6 +54,9 @@ The dark column shows where the default changes under Filament's `.dark` class. | `--ff-ease` | semantic | `cubic-bezier(0.16, 1, 0.3, 1)` | 4.2.0 | Easing of tray and cell fills, add row color, card shadow and card action fades. | | `--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. | @@ -110,7 +113,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/boost/skills/flowforge-development/SKILL.md b/resources/boost/skills/flowforge-development/SKILL.md index 079ab9777..4cb8ccbd5 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 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 0fb809661..022190400 100644 --- a/resources/css/flowforge-modern.css +++ b/resources/css/flowforge-modern.css @@ -60,9 +60,12 @@ } .ff-column, + .ff-add-column, .ff-lanes-grid, .ff-lanes-heads { --_column-width: var(--ff-column-width, 300px); + --_collapsed-width: 3rem; + --_dot-size: var(--ff-dot-size, 0.5rem); } .ff-lanes-heads { @@ -84,14 +87,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))); } @@ -187,9 +192,9 @@ max-height: 100%; } - .ff-column[data-collapsed]:not([data-drop]) { - width: 3rem; - min-width: 3rem; + .ff-column[data-collapsed]:not([data-drop], .ff-lanes-heads .ff-column) { + width: var(--_collapsed-width); + min-width: var(--_collapsed-width); } .ff-column-header { @@ -200,11 +205,6 @@ padding: 0 0.25rem 0.5rem; } - .ff-column[data-collapsed]:not([data-drop]) .ff-column-header { - flex-direction: column; - justify-content: normal; - } - .ff-column-heading { display: flex; align-items: center; @@ -212,14 +212,20 @@ min-width: 0; } - .ff-column[data-collapsed]:not([data-drop]) .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 { flex-shrink: 0; - width: 0.5rem; - height: 0.5rem; + width: var(--_dot-size); + height: var(--_dot-size); background-color: var(--color-500); border-radius: 9999px; } @@ -240,7 +246,7 @@ white-space: nowrap; } - .ff-column[data-collapsed]:not([data-drop]) .ff-column-title { + .ff-column[data-collapsed]:not([data-drop], .ff-lanes-heads .ff-column) .ff-column-title { max-height: 16rem; writing-mode: vertical-rl; } @@ -266,6 +272,32 @@ 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; + } + + /* 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: var(--_column-width); + min-width: var(--_column-width); + } + } + .ff-column-actions { display: flex; flex-shrink: 0; @@ -322,7 +354,7 @@ overscroll-behavior-y: contain; } - .ff-column[data-collapsed]:not([data-drop]) .ff-cards { + .ff-column[data-collapsed]:not([data-drop], .ff-lanes-heads .ff-column) .ff-cards { padding: 0; } @@ -419,6 +451,7 @@ font-size: 0.875rem; line-height: 1.25rem; font-weight: 500; + overflow-wrap: anywhere; color: var(--_text); } @@ -643,6 +676,169 @@ color: var(--_text-muted); } + .ff-add-column { + --_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-items: flex-start; + gap: var(--_gap); + } + + :where(.dark) .ff-add-column { + --_tile-bg: color-mix(in oklab, #fff 8%, transparent); + --_tile-bg-hover: color-mix(in oklab, #fff 13%, transparent); + } + + .ff-add-column-button { + display: flex; + flex-shrink: 0; + align-items: center; + justify-content: center; + width: var(--_collapsed-width); + height: var(--_collapsed-width); + color: var(--_text-muted); + background-color: var(--_tile-bg); + border-radius: 0.75rem; + transition: + 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); + background-color: var(--_tile-bg-hover); + } + + .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-lanes-heads .ff-add-column-ghost { + position: absolute; + inset-block-start: 0; + inset-inline-start: 0; + z-index: 20; + 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; + } + + .ff-add-column-field { + position: relative; + display: flex; + align-items: center; + gap: 0.625rem; + height: 2.25rem; + padding: 0 0.75rem; + border: 1px solid var(--gray-200); + border-radius: var(--_overlay-radius); + 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: var(--_dot-size); + height: var(--_dot-size); + background-color: var(--color-500, var(--gray-400)); + border-radius: 9999px; + } + + .ff-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; + width: max-content; + margin-block-start: -0.375rem; + padding: 0.5rem; + } + + .ff-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-swatch { + --_tint: color-mix(in oklab, var(--color-500) 30%, var(--gray-900)); + } + + .ff-swatch:hover { + box-shadow: inset 0 0 0 1.5px var(--_tint), 0 0 0 1.5px var(--_tint), 0 0 0 2.5px color-mix(in oklab, var(--color-500) 50%, transparent); + } + + .ff-swatch[aria-checked="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-swatch:focus-visible { + outline: 2px solid var(--ff-accent, var(--primary-500)); + } + + .ff-add-column-input { + 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: transparent; + border: 0; + outline: none; + box-shadow: none; + } + + .ff-add-column-error { + margin: 0.25rem 0 0; + font-size: 0.75rem; + line-height: 1rem; + font-weight: 500; + color: var(--_danger); + } + .ff-lanes { height: 100%; max-height: calc(100vh - 13rem); @@ -653,19 +849,78 @@ 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 .ff-column[data-collapsed] .ff-column-header { + justify-content: center; + } + + .ff-lanes-heads .ff-column[data-collapsed] .ff-column-title { + position: absolute; + width: 1px; + height: 1px; + overflow: hidden; + clip-path: inset(50%); + white-space: nowrap; + } + + .ff-lanes-heads .ff-column[data-collapsed] .ff-column-heading { + flex-direction: column; + gap: 0; + } + + .ff-lanes-heads .ff-column[data-collapsed] .ff-column-dot { + width: 0.375rem; + height: 0.375rem; + } + + .ff-lanes-heads .ff-column[data-collapsed] .ff-count { + font-size: 0.75rem; + line-height: 0.875rem; + } + + .ff-lanes-heads .ff-column[data-collapsed] .ff-column-icon, + .ff-lanes-heads .ff-column[data-collapsed] .ff-column-actions { + display: none; + } + + .ff-lanes-heads > .ff-add-column { + height: 1.75rem; + } + + .ff-lanes-heads .ff-add-column-button { + height: 100%; + } + + .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; 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); @@ -755,6 +1010,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/design-tokens.php b/resources/design-tokens.php index 6358caee0..19e7cf9ff 100644 --- a/resources/design-tokens.php +++ b/resources/design-tokens.php @@ -18,6 +18,9 @@ '--ff-ease' => ['tier' => 'semantic', 'since' => '4.2.0'], '--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 a1739a248..6fa3b8ff4 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 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 39ca1e824..0a3485bb3 100644 --- a/resources/js/flowforge-modern.js +++ b/resources/js/flowforge-modern.js @@ -14,6 +14,9 @@ const FLOWFORGE_TOKENS = [ '--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', @@ -26,6 +29,33 @@ const FLOWFORGE_TOKENS = [ '--ff-placeholder-border', ]; +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; + +// 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]'); + + // 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 SWATCH_COLUMNS = 4; + +const swatchesOf = (group) => [...group.querySelectorAll('[role="radio"]')]; + +const menusIgnoringMousedown = new WeakSet(); + const sortablesAwaitingDrag = new WeakSet(); const sortableIsBusy = () => window.Sortable.active || window.Sortable.dragged; @@ -35,11 +65,24 @@ export default function flowforgeModern() { isLoading: {}, fullyLoaded: {}, dragOverColumn: null, + + railToggledAt: 0, + railClickTimer: null, + columnMenuPressAt: null, + railPressAt: null, dragOverLane: null, dragSource: null, pendingCounts: {}, pendingMoves: 0, collapsedLanes: {}, + addingColumn: false, + newColumnName: '', + newColumnColor: null, + newColumnDotStyle: '', + newColumnColorPicked: false, + choosingNewColumnColor: false, + newColumnTouched: false, + addingColumnPending: false, placeholder: null, stopTrackingPointer: null, @@ -213,6 +256,202 @@ 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; + } + + if (fromRail) { + this.railToggledAt = Date.now(); + } + + 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); + } + }, + + suppressEmptySpaceSelection(event) { + if (event.detail > 1 && !event.target.closest(EMPTY_SPACE_IGNORED)) { + event.preventDefault(); + } + }, + + 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(() => { + const input = this.$refs.newColumnInput; + const board = input.closest('.ff-columns, .ff-lanes'); + + input.focus({ preventScroll: true }); + board?.scrollTo({ left: board.scrollWidth }); + input.closest('.ff-add-column-ghost').scrollIntoView({ block: 'nearest' }); + })); + }, + + cancelNewColumn() { + this.addingColumn = false; + this.newColumnTouched = true; + this.newColumnName = ''; + this.newColumnColor = null; + this.newColumnDotStyle = ''; + this.choosingNewColumnColor = false; + }, + + closeNewColumnColors() { + this.choosingNewColumnColor = false; + this.$refs.newColumnDot?.focus({ preventScroll: true }); + }, + + pickNewColumnColor(color, style) { + this.newColumnColorPicked = true; + this.newColumnColor = color; + this.newColumnDotStyle = style; + this.choosingNewColumnColor = false; + this.$refs.newColumnInput.focus({ preventScroll: true }); + }, + + async submitNewColumn() { + if (this.addingColumnPending) { + return; + } + + this.addingColumnPending = true; + this.newColumnTouched = true; + + try { + await this.$wire.addBoardColumn(this.newColumnName, this.newColumnColorPicked ? this.newColumnColor : null); + } finally { + this.addingColumnPending = false; + } + + this.newColumnTouched = false; + + if (!this.$root.querySelector('.ff-add-column-error')) { + this.cancelNewColumn(); + } + }, + + suppressDoubleClickSelection(event) { + 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 root = trigger.closest('.fi-dropdown'); + + if (menusIgnoringMousedown.has(root)) { + return; + } + + const dropdown = window.Alpine.$data(root); + const toggle = dropdown.toggle.bind(dropdown); + + menusIgnoringMousedown.add(root); + 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 (event.detail > 1 || (press && Math.hypot(event.clientX - press.x, event.clientY - press.y) > MENU_DRAG_THRESHOLD)) { + return; + } + + const root = event.currentTarget.closest('.fi-dropdown'); + + window.Alpine.$data(root).toggle(event); + requestAnimationFrame(() => focusMenuField(root.querySelector(':scope > .fi-dropdown-panel'))); + }, + + focusSwatch(group) { + const swatches = swatchesOf(group); + const target = swatches.find((swatch) => swatch.getAttribute('aria-checked') === 'true') ?? swatches[0]; + + // WebKit applies x-show a frame after Alpine's next tick, and a hidden button refuses focus. + requestAnimationFrame(() => target?.focus({ preventScroll: true })); + }, + + swatchFocused(event) { + const group = event.target.closest('[role="radiogroup"]'); + + swatchesOf(group).forEach((swatch) => swatch.setAttribute('tabindex', swatch === event.target ? '0' : '-1')); + }, + + swatchKey(event) { + const swatches = swatchesOf(event.currentTarget); + const index = swatches.indexOf(event.target); + const last = swatches.length - 1; + const next = { + ArrowRight: index === last ? 0 : index + 1, + ArrowLeft: index === 0 ? last : index - 1, + ArrowDown: Math.min(index + SWATCH_COLUMNS, last), + ArrowUp: Math.max(index - SWATCH_COLUMNS, 0), + Home: 0, + End: last, + }[event.key]; + + if (index < 0 || next === undefined) { + return; + } + + event.preventDefault(); + swatches[next].focus({ preventScroll: true }); + }, + columnDrop(columnId) { if (this.dragOverColumn !== columnId) { return null; diff --git a/resources/lang/de/flowforge.php b/resources/lang/de/flowforge.php index 4e27a0f90..1f2768416 100644 --- a/resources/lang/de/flowforge.php +++ b/resources/lang/de/flowforge.php @@ -21,6 +21,12 @@ 'group_by' => 'Gruppieren nach', 'no_grouping' => 'Keine', 'show_more_lanes' => 'Weitere Bahnen anzeigen', + 'add_column' => 'Spalte hinzufügen', + '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 4225235c3..0306747a7 100644 --- a/resources/lang/en/flowforge.php +++ b/resources/lang/en/flowforge.php @@ -21,6 +21,12 @@ 'group_by' => 'Group by', 'no_grouping' => 'None', 'show_more_lanes' => 'Show more lanes', + 'add_column' => 'Add column', + '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 3395d7ddb..a45514cc4 100644 --- a/resources/lang/es/flowforge.php +++ b/resources/lang/es/flowforge.php @@ -21,6 +21,12 @@ 'group_by' => 'Agrupar por', 'no_grouping' => 'Ninguno', 'show_more_lanes' => 'Mostrar más carriles', + 'add_column' => 'Añadir columna', + '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 cccc0d2e4..a385bb461 100644 --- a/resources/lang/nl/flowforge.php +++ b/resources/lang/nl/flowforge.php @@ -21,6 +21,12 @@ 'group_by' => 'Groeperen op', 'no_grouping' => 'Geen', 'show_more_lanes' => 'Meer banen tonen', + 'add_column' => 'Kolom toevoegen', + '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/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/color-swatches.blade.php b/resources/views/modern/components/color-swatches.blade.php new file mode 100644 index 000000000..fdf4eb8e1 --- /dev/null +++ b/resources/views/modern/components/color-swatches.blade.php @@ -0,0 +1,37 @@ +@props(['colors', 'open', 'selected' => null, 'selectedExpression' => null, 'label' => null, 'setColorLabel' => null]) + +@php + $values = array_column($colors, 'value'); + $setColorLabel ??= __('flowforge::flowforge.set_column_color'); + $tabStop = in_array($selected, $values, true) ? $selected : ($values[0] ?? null); +@endphp + +

class(['ff-swatches']) }} + role="radiogroup" + aria-label="{{ $label ?? __('flowforge::flowforge.column_color') }}" + x-cloak + x-show="{{ $open }}" + x-effect="if ({{ $open }}) { $nextTick(() => focusSwatch($el)) }" + x-on:keydown="swatchKey($event)" + x-on:focusin="swatchFocused($event)" + x-on:keydown.escape.stop.prevent="$dispatch('swatch-close')" + x-on:dropdown-escape.prevent="$dispatch('swatch-close')" +> + @foreach ($colors as $color) + + @endforeach +
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/index.blade.php b/resources/views/modern/index.blade.php index 8a2dc4eb2..18d834c45 100644 --- a/resources/views/modern/index.blade.php +++ b/resources/views/modern/index.blade.php @@ -39,6 +39,10 @@ class="ff-board" wire:key="column-{{ $columnId }}" /> @endforeach + + @if ($config['canAddColumns'] ?? false) + + @endif
@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..263442067 100644 --- a/resources/views/modern/livewire/add-card-row.blade.php +++ b/resources/views/modern/livewire/add-card-row.blade.php @@ -15,9 +15,9 @@ 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]) }} @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..ca76d25f8 --- /dev/null +++ b/resources/views/modern/livewire/add-column.blade.php @@ -0,0 +1,69 @@ +@props(['label', 'placeholder', 'colors' => [], 'defaultColor' => null, 'colorLabel' => null]) + +@php + use Filament\Support\Enums\IconSize; + + $defaultStyle = collect($colors)->firstWhere('value', $defaultColor)['style'] ?? ''; +@endphp + +
+
+
+
+ @if ($colors) + + + + @else + + @endif + + +
+ + @error('boardNewColumn') +

{{ $message }}

+ @enderror +
+
+ + +
diff --git a/resources/views/modern/livewire/column-header.blade.php b/resources/views/modern/livewire/column-header.blade.php index 566b25f18..47039d345 100644 --- a/resources/views/modern/livewire/column-header.blade.php +++ b/resources/views/modern/livewire/column-header.blade.php @@ -3,55 +3,71 @@ @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; + 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())); - $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() - ->icon('heroicon-m-plus') + ->icon(FilamentIcon::resolve(FlowforgeIconAlias::ADD_CARD) ?? 'heroicon-m-plus') ->label(__('flowforge::flowforge.add_card', ['card' => $this->getBoard()->getCardLabel()])) + ->tooltip(($column['isFull'] ?? false) ? __('flowforge::flowforge.limit_reached') : __('flowforge::flowforge.add_card', ['card' => $this->getBoard()->getCardLabel()])) ->disabled($column['isFull'] ?? false); - if ($column['isFull'] ?? false) { - $createAction?->tooltip(__('flowforge::flowforge.limit_reached')); - } - $createAction = $createAction?->isVisible() ? $createAction : null; -@endphp -
-
- @if ($dotColor) - - @endif - - @if ($column['icon'] ?? null) - - @endif + // 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 -

{{ $column['label'] }}

+
+ @if ($hasMenu) + + + + - + @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..c69471e11 --- /dev/null +++ b/resources/views/modern/livewire/column-heading.blade.php @@ -0,0 +1,26 @@ +@props(['columnId', 'column', 'isCollapsed' => false]) + +@php + use Filament\Support\Enums\IconSize; + use Relaticle\Flowforge\Support\ColorResolver; + + $dotStyle = ColorResolver::dotStyle($column['color'] ?? null); +@endphp + +
class(['ff-column-heading']) }}> + @if ($dotStyle) + + @endif + + @if ($column['icon'] ?? null) + + @endif + +

{{ $column['label'] }}

+ + + + @if (! $isCollapsed && filled($column['summary'] ?? null)) + {{ $column['summary'] }} + @endif +
diff --git a/resources/views/modern/livewire/column.blade.php b/resources/views/modern/livewire/column.blade.php index 608dfedd3..7ef2438a1 100644 --- a/resources/views/modern/livewire/column.blade.php +++ b/resources/views/modern/livewire/column.blade.php @@ -2,8 +2,9 @@ @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']); + $expandLabel = __('flowforge::flowforge.expand_column', ['column' => $plainLabel]); $trayLabel = __('flowforge::flowforge.column_label', [ 'column' => $plainLabel, 'count' => $total, @@ -20,16 +21,44 @@ 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 + x-on:click="toggleColumnCollapse($event, @js((string) $columnId), true)" + @endif + 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) + + @endunless
+ @if ($isCollapsed) + + @endif + @if (($column['limit'] ?? null) !== null)

count($column['items'])) + @if(! $isCollapsed && isset($column['total']) && $column['total'] > count($column['items'])) @scroll.throttle.100ms="handleColumnScroll($event, '{{ $columnId }}')" @endif > @@ -59,7 +88,7 @@ class="ff-cards" /> @endforeach - @if(isset($column['total']) && $column['total'] > count($column['items'] ?? [])) + @if(! $isCollapsed && isset($column['total']) && $column['total'] > count($column['items'] ?? []))

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))'; + $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); + $plainLabel = strip_tags((string) $column['label']); + $expandLabel = __('flowforge::flowforge.expand_column', ['column' => $plainLabel]); + @endphp +
- +
@endforeach + + @if ($canAddColumns) + + @endif
@foreach ($lanes as $lane) @@ -46,7 +83,7 @@ class="ff-lane-toggle" aria-labelledby="{{ $laneTitleId }}" x-bind:aria-expanded="! isLaneCollapsed(@js($laneKey))" > - + @if ($lane['avatar']) @@ -62,14 +99,26 @@ 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']))