Rules
A board with a workflow. In progress holds three cards at most (MaxItems).
Done takes cards from In progress only (CanDrop), and a server has the last word
on every drop into it (ConfirmDrop) - refused, the card slides back. A card released outside the
board goes back where it was (RevertOnSpill). While a card is dragged, the columns that take it are
outlined, and a column that refuses it turns red.
To do: Write the spec, Draw the icons, Plan the launch
In progress: Build the API, Review the PR
Done: Set up CI
Server: idle
Last drag (OnEnd): nothing yet
Try it
- Drag Write the spec into In progress: it fits, and the column is full. Now drag Draw the icons over it: In progress is no longer outlined and does not take it, but its own cards still sort.
- Drag a card from To do over Done: the column turns red, the pointer shows it cannot drop there, and nothing is previewed.
- Drag Build the API into Done: the server says yes after a moment, and the card stays. Untick the box and drag another one: the card shows in Done while the server thinks, then slides back - and Last drag says it was cancelled.
-
Drag a card and let go of it outside the board: it goes back where it came from, even if it was previewed in
another column, and
OnEndreportsCanceled. - From the keyboard the same rules apply: carry a card toward Done with the arrows and the refusal is announced - "Plan the launch cannot be moved there." - and the card stays put.
CanDrop - a rule for every position
CanDrop is asked whether the dragged item may take a position in this list, as the item reaches it
and before anything is shown - for a reorder within the list and for an item coming from another list alike. It
receives the proposed move: Item (and Items for a multi-drag), FromId and
FromGroup, OldIndex, and NewIndex, the index the item would have here.
Return false and the item stays where it was. It is the SortableJS onMove; it runs while
the pointer moves, so keep it fast and free of side effects.
CanDrop='e => e.FromId is "rules-doing" or "rules-done"'
MaxItems - a limit per list
A full list takes nothing from other lists - the pointer passes over it to the list around it, or shows that it cannot drop - while its own items still sort. A multi-drag counts every item it carries; a swap brings one item and takes one, so it is never refused for room.
MaxItems="3"
MinItems - a list that keeps a few
MinItems is the fewest items a list keeps: no item moves out of it to another list when that would
leave fewer - the other lists do not take the drag, as if they were full. A multi-drag counts every item it would
carry away. The list still sorts, clones out and swaps, none of which empties it.
Pipeline: Build → Test → Deploy
- Drag Deploy to the Unused steps: it goes, and two steps are left. Now drag Test: Unused steps does not take it, and it stays in the pipeline. Add Lint from the shelf, and a step can leave again.
ConfirmDrop - the last word
ConfirmDrop is asked once an item has been dropped into the list, for a check that has to wait: a
server call, a confirmation dialog. The drop shows at once and the lists stay as dropped while the task runs.
Return true to keep it, and the usual events follow. Return false to put back every list
the drag changed: the items slide back, ItemsChanged is raised for the lists put back, and
OnEnd reports Canceled - with no OnUpdate, OnAdd,
OnRemove or OnSort. No other drag starts until it answers; one that throws puts the lists
back too.
ConfirmDrop="ConfirmAsync" private async Task<bool> ConfirmAsync(BortableEventArgs<Card> e) => await Api.TryMoveAsync(e.Item.Id, e.ToId, e.NewIndex); // NewIndex: where the card is now
RevertOnSpill - released outside every list
A mouse drag released outside every list keeps what it did, as in SortableJS: a card previewed in another column
lands there. RevertOnSpill="true" on the list the drag started in puts it back instead. (A keyboard,
touch or pen drag cancelled with Escape is always put back.)
RevertOnSpill="true"
Showing where a card may go
While a drag runs, the browser layer marks every list that takes it with data-bortable-accepts, the
list under the pointer with data-bortable-over, and that list with data-bortable-refused
when it refused the position. The stylesheet draws nothing for them until you set its custom properties - this
board sets three:
.rules-board {
--bit-bortable-accepts-outline: 2px dashed color-mix(in srgb, var(--bb-primary) 45%, transparent);
--bit-bortable-over-outline: 2px solid var(--bb-primary);
--bit-bortable-refused-outline: 2px solid #dc2626;
}
The marks are attributes the browser layer sets, so they cost no render. See styling for every custom property and class.