Skip to content

Corkboard

Corkboard lays a flat ordered list out as a grid of cards and makes the order manipulable — drag a card (or a multi-selection) into a gap, or pick it up with mod+arrows — without owning what a card looks like: the card’s content is a snippet, and the component contributes only the grid, the cursor, the selection and the reorder gestures. When a drop lands, the surrounding cards settle into place with a FLIP animation rather than a jump.

Selection follows the same shared model as Tree, List and Table: shift/mod click, shift+arrows to extend, mod+a, escape. The keyboard walk is genuinely two-dimensional — ↑/↓ step by the laid-out column count, whatever CSS decided it was.

import Corkboard from '@delightstack/components/display/Corkboard.svelte';

Corkboard deliberately has no barrel export — not from @delightstack/components and not from ./display. Without a sideEffects declaration, a barrel’s modules ride in whatever chunk imports the barrel, so a shell that eagerly imports ./display for SplitPane would ship the whole board in its boot payload whether or not anything renders one. A corkboard is a view-level component; it gets the per-component export path from birth, and the pure model rides beside it:

import { planReorder } from '@delightstack/components/display/corkboard-model';
  • Arrival

    Elias reaches the lighthouse at dusk; the lamp still turns.

    1,840 words
  • The cottage

    Every window boarded. A key that fits nothing.

    920 words
  • The ledger

    Eleven years of entries, and the last one unfinished.

    1,430 words
  • First storm

    The generator fails. Someone answers the radio anyway.

    2,210 words
  • The landing

    A boat that should not have made the crossing.

    760 words
  • Letters

    What the keeper wrote and never sent.

    1,120 words

Double-click or press Enter to open a card.

View code
<Corkboard
cards={scenes}
bind:selected
reorderable
label_of={(s) => s.title}
onreorder={(plan) => commit(plan)}
onopen={(s) => open(s)}>
{#snippet card(scene)}
<article>
<h4>{scene.title}</h4>
<p>{scene.synopsis}</p>
</article>
{/snippet}
</Corkboard>

A card marked droppable accepts drops onto it as well as beside it — a folder among documents. The middle half of such a card means “into”; the outer quarters still mean the gap on that side, so a droppable card never makes the gaps beside it unreachable. The drop arrives as ondropinto with the moving ids and the target card, and it is your move to make — the board never mutates cards.

  • Act II

    9 scenes

  • The ferry

  • The argument

  • Act III

    4 scenes

  • Aftermath

Drag a scene onto a folder card.

View code
<Corkboard {cards} reorderable {onreorder} ondropinto={({ ids, target }) => moveInto(ids, target)}>
{#snippet card(item)}…{/snippet}
</Corkboard>

onreorder hands you a plan, not a mutation: the moved ids in screen order, the index where the run lands once it is out of the list, and the before / after neighbours — which is exactly what a fractional-key scheme wants, and enough for a splice.

function onreorder(plan: CorkboardReorderPlan) {
const moving = cards.filter((c) => plan.ids.includes(c.id));
const kept = cards.filter((c) => !plan.ids.includes(c.id));
cards = [...kept.slice(0, plan.index), ...moving, ...kept.slice(plan.index)];
}

A plan is only produced when the drop would change something — putting a card back into its own gap calls nothing.

The board is one tab stop; the cursor moves inside it and is announced through a visually hidden status line, named by label_of.

KeyDoes
↑ ↓ ← →Move the cursor (2D — ↑/↓ step a row)
Home / EndFirst / last card
Enteronopen the cursor’s card
SpaceToggle the card in the selection
shift+arrows / shift-clickExtend the selection as a range
mod-clickToggle one card
mod+aSelect everything
escapeClear the selection (unclaimed when nothing is selected)
mod+arrowsMove the cursor’s card — or the whole selection — one step

Keys typed into a control inside a card — an inline editor, a button — are left alone, so a card can carry its own interaction without fighting the board.

PropTypeDefaultDescription
cardsT[]requiredThe cards, in order. T needs id; disabled and droppable are read when present.
selectedstring[][]Selected ids, bindable.
cursorstring | nullnullThe keyboard cursor’s card id, bindable.
columnsnumberautoFixed column count. Unset, the grid fits as many min_card_width columns as it can.
min_card_widthnumber220Minimum card width in px for the auto grid.
reorderablebooleanfalseEnable drag and mod+arrow reordering.
cardSnippet<[T, { selected, cursor }]>requiredOne card’s content.
emptySnippetundefinedRendered instead of the grid when cards is empty.
label_of(c: T) => stringc.idHow a card is named to a screen reader.
onreorder(plan: CorkboardReorderPlan) => voidundefinedA run of cards moved.
onopen(c: T) => voidundefinedEnter or double click on a card.
ondropinto({ ids, target }) => voidundefinedA run dropped onto a droppable card.
aria_labelstringundefinedAccessible name for the board.
idstringautoElement ID.
classstring''Additional CSS classes.
VariableDefaultDescription
--corkboard-gap0.75remGap between cards — the drop indicator centres itself in it.
--corkboard-radius8pxRadius of the selection tint and cursor outline around a card.

The grid arithmetic is a pure module exported alongside the component — no runes, no DOM — for consumers that drive their own board or test their own bindings.

import {
columnCount, // offsetTops → laid-out column count
arrowTarget, // (index, move, columns, count) → next index, clamped, never wrapping
moveSlot, // the slot a mod+arrow asks for, or -1 at an edge
planKeyMove, // (order, moving, move, columns) → the mod+arrow plan, measured from the run's edge
insertionIndex, // (over, past_midline) → slot
planReorder, // (order, moving, slot) → { ids, index, before, after } | null
planKeyMove, // a mod+arrow resolved end to end, stepped from the run's edge
dropOnCard, // (over, past_midline, rects) → the slot plus the indicator's anchor
dropFromPoint, // (x, y, rects) → the nearest slot to a pointer over the grid's gaps
} from '@delightstack/components/display/corkboard-model';
  • One tab stop; the board is the focus holder and every key is handled there, because a card may carry focusable controls of its own and a listbox/option shape forbids that.
  • The cursor’s card carries aria-current="true", and a role="status" line announces it — position, name (via label_of), and whether it is selected.
  • The FLIP settle collapses to nothing under prefers-reduced-motion.
  • Drag has a keyboard equivalent (mod+arrows) for every reorder it can perform except dropping into a card — give droppable targets a command-shaped path of their own.