npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@affino/dockview-core

v0.2.2

Published

Headless serializable split and docking workspace layout engine

Readme

@affino/dockview-core

Headless, Node-compatible layout state and split resolution for Affino workspaces.

pnpm add @affino/dockview-core

The package has no runtime dependencies and does not access Vue, the DOM, window, or document.

const engine = createDockviewEngine({ layout, panels })
engine.dispatch({ type: "dockPanel", panelId: "chat", targetGroupId: "editor", position: "right" })
const json = engine.serialize()
engine.restore(json)

The canonical layout remains a version 1 recursive split / tabs tree. Split axis x arranges children left-to-right; y arranges top-to-bottom. sizes[i] belongs to children[i]: mode: "fixed", value means preferred pixels; mode: "flex", value means a unitless relative weight for remaining space. min/max are axis pixels. resizable: false disables pointer/keyboard resize across an adjacent separator. These are preferred configuration fields and are never overwritten by resolution.

Resolution uses the actual container rectangle and splitter thickness. Nested same-axis minima and splitter gaps add; perpendicular minima combine by maximum, and perpendicular maximums by minimum. A tab group aggregates the largest registered minimum and smallest registered maximum across all its panels, so tab activation does not change geometry. Fixed preferences are clamped first; flex children divide remaining space by weight. If a child reaches a maximum, remaining eligible flex children absorb the slack; if all flex children reach maximum, constraints.unused reports the leftover space. When minima do not fit, requested allocations are proportionally compressed; constraints.feasible becomes false and compressed reports the minimum shortfall. Contradictory group min/max ranges set conflict. Returned rectangles stay finite and non-negative. Expanding the container resolves again from the untouched preferences.

Commands are atomic and return committed, unchanged, or rejected. dockPanel accepts center | left | right | top | bottom; optional insertionIndex is a final zero-based tab slot for center docking. Center drops activate the moved panel; same-group reorders preserve active selection. Same-group directional drops split a panel out when its group has multiple panels; a singleton self-drop is an unchanged no-op. Empty source groups are removed, one-child splits collapse, and sibling size specs remain paired during removal. Compatible same-axis parents are reused. New siblings use flex weight 1; a new split uses equal flex weights, retaining existing preferred specs when reusing a parent. Infeasible minimum constraints do not silently cancel the layout operation: the candidate carries the resolver's feasible, compressed, and conflict diagnostics, allowing the UI to mark the preview.

getDockCandidate(command, container, splitterSize) runs the same atomic transformation as dispatch without changing the tree, revision, or subscriptions. It returns a deterministic preview tree, resolved rectangles, resulting group, diagnostics, and result. Generated IDs are deterministic for the current committed tree and are reused by commitDockCandidate. Commit revalidates against the current revision and rejects stale or changed candidates. acceptsPanels: false on a group rejects incoming panels; group allowedDockPositions and panel allowedDockPositions restrict dock positions. Panel allowedTargetGroupIds restricts destinations and movable: false rejects moves. These policies are checked by commands and candidates.

setPreferredSize sets the exact size mode; resizeChild sets one child to a fixed preferred pixel size; getResizeCandidate computes a resize candidate without publishing (default mode adjacent preserves the existing two-child behavior; { mode: "cascade" } distributes boundary movement in visual order on both sides of the separator, respecting each child's min/max and resizable setting); commitResizeCandidate commits only if no newer mutation invalidated it; resizeAdjacent is the convenience preview-and-commit method and accepts the same mode option. Candidate preview and commit use the same resolved layout. Cascade resize updates changed fixed pixel preferences and adjusts flex weights to preserve the resolved allocation while retaining each child's fixed/flex mode. equalizeSplit sets eligible child weights to one, resetSplit restores that split's configured defaults, and reset restores the default tree and clears presentation preferences. Batch rejection leaves state and subscribers untouched. restore validates identities and recovers unavailable panels by removing those placements and normalizing empty groups; newly registered panels are not automatically opened. Malformed JSON and unsupported schemas are rejected. The consumer owns persistence and defaults.

collapseRegion(nodeId) and expandRegion(nodeId) apply to tab groups with a parent split. Collapse size defaults to zero content pixels and can be set to a rail size; it is independent of preferred size. A collapse is rejected if it would hide the last expanded region or any panel in the group is non-collapsible. maximizeGroup(groupId) temporarily resolves that group to the workspace bounds without replacing the canonical tree. restorePresentation() restores the current tree, including mutations made while maximized. Collapse preferences are in immutable snapshot.collapsedRegions; snapshot.maximizedGroupId is transient. Docking into a collapsed group and directional docking while maximized are rejected; center docking into the maximized group is supported. A split separator is restricted only when one of its two directly adjacent children is collapsed; other separators in the same split remain resizable. Resizing during maximization is unavailable. Opening without an explicit group while maximized opens in that group. Removing a collapsed group prunes its preference; removing the maximized group clears maximization.

serialize() emits a version 2 wrapper containing the unchanged version 1 canonical layout plus collapsedRegions. Restore accepts both legacy raw v1 layouts and this wrapper. Invalid, duplicate, or obsolete collapsed identities are dropped; if restored preferences would collapse every eligible group, the final entry is removed deterministically. Maximization, resolved dimensions, component definitions, and browser measurements are not serialized.

The Vue adapter owns container measurement and gesture state. Pointer movement stores only a temporary Core candidate; pointerup commits once, while Escape, cancellation, disposal, or an intervening engine mutation discards it. Keyboard arrows resize by 10 px, Shift+arrows by 50 px. Core candidates and committed commands share the same constraints. Core tests cover shallow and nested constraints, generated layouts, compression diagnostics, and committed versus preview resize behavior.

Panel IDs identify instances, while type can identify a shared application definition. registerPanel, updatePanelMetadata, and unregisterPanel modify the runtime registry independently of layout membership. Registry changes notify subscribers in snapshot.panels without replacing the layout. Unregistering an open panel is rejected with panel-open; close the panel first. Reopening a closed but registered instance creates a new Vue content instance when its next host mounts. Applications own unsaved-data guards and resource persistence. disabled: true prevents open, activate, reorder, and dock commands for that instance.

Schema version 1 restores only definitions registered at restore time: unavailable panel placements are removed and empty groups normalized. Register definitions before restoration when they should be retained. Definitions that become available later remain closed until explicitly opened. Runtime Vue state, callbacks, close requests, and subscriptions are never serialized.

Public API inventory

The root ESM entry exports createDockviewEngine, resolveDockLayout, validateLayout, DockviewEngine, and the public types declared in src/types.ts.

| Area | Public contract | |---|---| | Create and observe | createDockviewEngine({ layout?, panels? }), getSnapshot(), getState(), subscribe() | | Runtime registry | registerPanel(), getPanelDefinition(s)(), updatePanelMetadata(), unregisterPanel() | | Commands | dispatch(DockCommand), dispatchBatch(); results are committed, unchanged, or rejected with a reason | | Placement | openPanel, closePanel, activatePanel, reorderPanel, dockPanel | | Split sizing | getResolvedLayout, getResizeCandidate, commitResizeCandidate, resizeAdjacent, setPreferredSize, resizeChild, equalizeSplit, resetSplit | | Presentation | collapseRegion, expandRegion, maximizeGroup, restorePresentation | | Persistence | serialize(), restore(), reset() | | Lifetime | dispose() |

getDockCandidate() and commitDockCandidate() provide non-mutating preview and stale-checked commit. getPanelLocation() queries placement. resolveDockLayout() is a stateless resolver for applications that need to resolve a tree directly. Resolved rectangles are derived and must not be persisted as preferred sizing.

Complete engine example

import { createDockviewEngine } from "@affino/dockview-core"

const layout = {
  version: 1 as const,
  root: {
    id: "workspace",
    type: "split" as const,
    axis: "x" as const,
    children: [
      { id: "explorer", type: "tabs" as const, panelIds: ["explorer-panel"], activePanelId: "explorer-panel" },
      { id: "editor", type: "tabs" as const, panelIds: ["document:42", "chat"], activePanelId: "document:42" },
      { id: "inspector", type: "tabs" as const, panelIds: ["inspector-panel"], activePanelId: "inspector-panel" },
    ],
    sizes: [
      { mode: "fixed" as const, value: 260, min: 180, max: 420 },
      { mode: "flex" as const, value: 1, min: 320 },
      { mode: "fixed" as const, value: 340, min: 240, max: 520 },
    ],
  },
}

const engine = createDockviewEngine({
  layout,
  panels: [
    { id: "explorer-panel", type: "explorer", title: "Explorer", closable: false, movable: false },
    { id: "document:42", type: "document", title: "Network Model" },
    { id: "chat", type: "chat", title: "Chat" },
    { id: "inspector-panel", type: "inspector", title: "Inspector" },
  ],
})

const unsubscribe = engine.subscribe(snapshot => {
  // Forward immutable state to application persistence or another adapter.
  console.log(snapshot.layout.root?.id, snapshot.presentation.maximizedGroupId)
})

engine.dispatch({ type: "dockPanel", panelId: "chat", targetGroupId: "inspector", position: "bottom" })
const savedJson = engine.serialize()
// Store savedJson in an application-owned persistence layer.
engine.restore(savedJson)

unsubscribe.unsubscribe()
engine.dispose()

The application owns panel components, default layout, storage, and unsaved-document policy. Direct Core closePanel and replaceLayout commands are explicit application-authorized mutations; Core does not run Vue close guards. A UI should ask the application to approve closure before dispatching a close command. reset() restores the engine's configured initial tree and clears presentation preferences; gate user-facing reset through application close protection if it removes open panels.

Serialization compatibility

The canonical layout schema remains version 1. serialize() wraps it in serialized-state version 2 to include collapsed preferences. restore() accepts raw v1 layouts and the v2 wrapper. Unknown versions, malformed data, duplicate node/panel placement, invalid size specifications, or invalid active references reject without replacing current state. Missing panel definitions are recovered by removing only their placements, choosing a valid active tab, and normalizing empty groups. Register definitions before restore when placements should be kept. Later registration does not reopen a recovered panel. Obsolete collapsed group IDs are dropped; maximize is never persisted. The consumer owns the stored JSON and schema migration between application releases.

Deliberate limitations

This package provides a single-workspace tree and deterministic state/geometry operations. It does not provide floating windows, cross-window or cross-workspace docking, multi-monitor management, remote persistence, application document lifecycle, or Vue rendering. Infeasible layouts are represented by resolver diagnostics (feasible, compressed, conflict, unused); consumers decide how to present warnings.

Reproducible Core benchmark

Run pnpm --filter @affino/dockview-core bench. The script reports p50/p95/p99 in milliseconds for shallow and nested layouts with 5/10/20/100/500 panels. A 500-sample, 50-warmup run on Node v24.22.3/Linux arm64 measured 20-panel nested layout resolution at 0.054/0.083/0.087 ms and docking candidate calculation at 0.079/0.112/0.121 ms. These are Core timings, not browser rendering or frame-rate claims; the benchmark output is the environment-specific source of truth.