FragiolaDnD
Documentation
Guides

With Dockable

Drop a card on a Dockable tabset to open a tab, drag and sort inside panels that move or pop out, and write one rule that spans both libraries.

dnd and Dockable compose without depending on each other: the packages never import a sibling, and the glue is a few lines of app code. Install Dockable beside dnd (pnpm add @fragiola/dockable-react).

A tabset as a drop target

Dockable.TabSet forwards its props and ref, as every Fragiola primitive does, so a Droppable wraps it directly. Both libraries' attributes sit on the one element (data-layout-path and data-dnd-*), without colliding. The drop changes the layout through Dockable's own command, so it goes through Dockable's rules like any other change:

layout.tsx
import { Droppable } from "@fragiola/dnd-react/droppable";
import { Dockable, type TabsetNode } from "@fragiola/dockable-react";

function TabSet({ node }: { node: TabsetNode<NoteTypes> }) {
    return (
        <Droppable
            id={node.id}
            accepts={["card"]}
            onDrop={(event) =>
                model.run("tab.add", {
                    component: "note",
                    label: String(event.operation.source.data),
                    data: { text: "…" },
                    to: node.id,
                })
            }
        >
            <Dockable.TabSet node={node} className="tabset data-dnd-over:outline">
                {/* the strip and the content, as usual */}
            </Dockable.TabSet>
        </Droppable>
    );
}

A rule across both libraries

Dockable's rules live in Dockable: here a Dockable middleware refuses tab.add into a tabset that holds three tabs. A dnd drop middleware asks Dockable the same question with model.can, which runs Dockable's chain without committing anything. dnd asks it as a dry run on every hover, so a full tabset is marked data-dnd-refused while the card is over it, not after the drop:

rules.tsx
import { useDragSpace } from "@fragiola/dnd-react";

// Dockable's rule, in Dockable
useEffect(
    () =>
        model.use((ctx, next) => {
            if (ctx.command !== "tab.add") return next();
            const target = ctx.get("node-by", { id: ctx.payload.to });
            return target?.type === "tabset" && target.children.length >= 3
                ? { ok: false, error: { code: "refused", message: "A tabset holds at most 3 tabs." } }
                : next();
        }),
    [model],
);

// dnd asks Dockable before a card may drop on a tabset
const space = useDragSpace();
useEffect(
    () =>
        space?.use((ctx, next) => {
            const tabset = String(ctx.payload.droppableId);
            if (model.get("node-by", { id: tabset })?.type !== "tabset") return next();
            return model.can("tab.add", newTab(String(ctx.source.data), tabset))
                ? next()
                : { ok: false, error: { code: "vetoed" } };
        }),
    [space, model],
);
A new Dockable tab
Gallery

Draggables inside panels

Dockable moves a panel's content when its tab moves to another tabset, or into a popout window, without remounting it. dnd measures at drag start and registers each element in its own document's drag space, so a draggable keeps working wherever its panel went, and inside a popout it meets that window's droppables (a drag never crosses windows).

A panel clips its content, so a card dragged out of it would vanish at its edge: give the cards translate={false} and let a DragOverlay carry a copy across panels.

Inside Dockable panels
Gallery

A sortable list inside panels

A sortable list works the same way. Its items register in their document's drag space and the list is measured when a sort starts, so after Dockable moves the panel to another tabset the items sort where they are now, with nothing to update:

panel.tsx
import { DragOverlay } from "@fragiola/dnd-react";
import { moveBetween, Sortable } from "@fragiola/dnd-react/sortable";

<Dockable.Panel node={tab}>
    <ul aria-label="Tasks" className="list">
        {tasks.map((id, index) => (
            <Sortable key={id} id={id} index={index} group="tasks" translate={false} onSortEnd={onSortEnd}>
                <li className="task data-dnd-dragging:opacity-50">{taskOf(id).title}</li>
            </Sortable>
        ))}
    </ul>
</Dockable.Panel>;

<DragOverlay>{(operation) => <div className="task lifted">{taskOf(operation.source.id).title}</div>}</DragOverlay>;

A panel clips its content, so here too translate={false} keeps the dragged item in the list, shifted to where it would land as its placeholder, and the overlay carries the copy. Two lists in two panels whose groups accept each other move items between panels.

Popped out into a window, the panel's elements now belong to the popout's document, so they meet that document's drag space: the list sorts inside the window, and an overlay given that window's document (<DragOverlay document={…}>) shows the copy there. A sort never crosses windows. The playground's interop/dockable-popout-sortable scenario and its e2e (Chromium and Firefox) sort a list in the main window, in a popout, and again once it is docked back.

Sortable in Dockable panels
Gallery

Two drags, side by side

Dockable drags its own tabs and tabsets with native HTML5 drag and drop inside its root; dnd uses Pointer Events. They do not meet: a dnd drag never starts a Dockable drag, and a tab dragged by Dockable never reaches a Droppable. Their attributes are distinct (data-dragging on a Dockable tab, data-dnd-dragging on a dnd draggable).