Fragiola

API: primitives (@fragiola/flow-react, @fragiola/flow-vue, @fragiola/flow-svelte, @fragiola/flow-angular)

Viewport

Flow.Viewport is the pannable, zoomable layer holding the edges, the nodes and the connection line, its transform written by the engine itself.

Flow.Viewport is the layer in flow coordinates, inside Flow.Root. Put in it what pans and zooms with the flow: Flow.Edges first, then Flow.Nodes (drawn on top), then Flow.ConnectionLine. Leave outside it, in the root, what stays in screen pixels: Flow.Background, Flow.SelectionBox, Flow.Controls, the minimap.

The engine writes its transform and transform-origin directly (engine.adapter.attachViewport): the framework never renders a transform on it, so a pan or a zoom re-renders nothing inside it. Before the engine is attached (on the server, and in the first client render) it has none, so the flow is drawn at the identity viewport ({ x: 0, y: 0, zoom: 1 }); defaultViewport and fitView apply once the engine is attached, after mount. It is its own stacking context (isolation: isolate) from the server on, so the edge levels and the nodes stack inside it (Z-order).

<Flow.Root<Types, typeof features> features={features} defaultNodes={nodes} className="size-full">
    <Flow.Background variant="dots" />
    <Flow.Viewport>
        <Flow.Edges<Types>>{renderEdge}</Flow.Edges>
        <Flow.Nodes<Types>>{renderNode}</Flow.Nodes>
        <Flow.ConnectionLine />
    </Flow.Viewport>
    <Flow.SelectionBox />
</Flow.Root>

Read the viewport with useViewport and change it with the engine (engine.run("set-viewport", { x, y, zoom }), "fit-view"): see The viewport.

Props

ViewportProps extends the common primitive props and every div attribute.

proptypedefaultdescription
childrenReactNodenonewhat is in flow coordinates

State

ViewportState, what className, style and render receive:

fieldtypedescription
viewportViewportthe pan (x, y, pixels) and the zoom

The viewport element itself re-renders on every viewport change (it reads useViewport for its state), while its children do not: the engine writes the transform, so nodes and edges stay put.

Data attributes

attributevalue
data-flow-part"viewport"

Structural style

position: absolute, at the root's top-left corner, 100% wide and high; transform and transform-origin are the engine's.