@sincpro/web-composer
v1.9.1
Published
The Sincpro workspace for React: one page with its breadcrumb, a peek, side panels and windows, and ⌘K — all over references, never data.
Maintainers
Readme
@sincpro/web-composer
A window manager for enterprise web apps. A person opens a record, checks another beside it, peeks at a third and keeps a fourth floating while they work — without losing their place, and without any screen knowing about the others. A rich API for views, standalone: it depends on nothing but React. By Sincpro, open source.
yarn add @sincpro/web-composer react react-domManifesto
Purpose
The composer defines how work between records behaves: where each thing opens, how you get back, what is remembered, and what the others see. One behaviour, reviewed by Sincpro, for every application.
UI libraries prefer «one screen, one context» because it is clean. But people who work in accounting, audit or support spend the day between records: the bank statement against the invoices, the journal item against its entry, the customer while the order is half filled. Without a window manager, every app either navigates away (the list, its filters and its selection are gone) or sends people to browser tabs (the context lives in their head) — and each app reinvents peeks, breadcrumbs and panels its own way. The composer solves it once.
| Who | The question it answers |
| ---------------- | ------------------------------------------------------------------------ |
| The composer | Where each view lives and how it moves: page, peek, side panel, window |
| Your app | What a record is and how it looks — drawn with web-ui, or anything else |
| A framework | Puts both together (@sincpro/web-framework does, over server metadata) |
Principles — the contract
- One gesture, one destination. A click opens the page and the breadcrumb keeps the way back; a peek, a window, a side panel are one gesture away, never forced on anyone. Someone who never opens a panel just sees pages and breadcrumbs.
- References, not data. The workspace stores
domain:kind/id. A support case points at an invoice and the workspace opens it, while the support code never imports accounting. Views can open things and publish what they selected, but cannot read the workspace. - Never lose the place, nor what was typed. The breadcrumb, the URL, the browser's Back,
asking before discarding. Moving a panel does not remount it; neither does changing only a
reference's
params. The peek belongs to its page: when the page becomes another record, it closes. - Opinionated defaults, open doors. Good practice comes built in, and everything is
replaceable without forks: the look (
--sc-*,skin), the discard question (confirmDiscard), where a click goes (defaultOpen), any reducer (apply). - Standalone. Only React. The design belongs to whoever uses it; the composer ships a minimal skin so it works alone, and nothing else.
- Each domain declares itself. Register a
ViewSpecand it works in pages, panels, the peek and ⌘K. Adding a domain changes no file here — the view can be a module another team deploys. - Nothing a person arranges can break it. A view that throws stays in its own panel; a reference nobody resolves says so; a broken link loads what is valid; sizes are clamped.
- Addressable by people and agents. The place lives in the URL and in references, so the
same API (
context,open,peek,select) serves a person and an AI agent. An MCP or WebMCP adapter fits here — as a separate module, not in the core. - A rule comes with its story. Every behaviour is a Storybook story with its
play.
What it is not
- Not a component library. No form controls, tables or lists — that is your app (web-ui).
- Not a data layer. No fetching, permissions, entities or sessions.
- Not a router of URL paths, and not a free dashboard layout.
- No tabs, no multiple workspaces. One page, its trail, and what is around it.
- No design system, no icon library as a dependency.
How something new gets in
All three, or it belongs in another package:
- It answers where does it open? how do I get back? what is remembered? what does the other one see (a panel following the selection, an agent)?
- It serves any domain the same way — if it only makes sense for accounting, it is the app's.
- It comes from real use (forge, web-framework) and arrives with its story.
The model
One page, with its trail (the breadcrumb), and around it:
| Destination | What it is | When to use it | | ----------- | ----------------------------------------------------------------------- | -------------------------------------------- | | page | Replaces the page; the breadcrumb remembers where you were. The default | Opening a record to work on it | | peek | A drawer over the page that does not cover the panels | Reading without leaving the place | | window | Floating: moves anywhere, resizes, can grow into the page | A quick look or edit on top of what you do | | side | Docked left, right or at the bottom, resizable | A second context that stays: compare, follow | | modal | Over the surface that asked, blocking only it; moves by its title | A question, a chooser, a short form |
A view opens anything with one call and lets the workspace decide the rest:
api.open(ref); // the page — inside the peek, a step IN the drawer
api.open(ref, { to: "peek" }); // or "window", or "side"
api.open(ref, { to: "modal" }); // over THIS surface only; { blur: true } blurs what it covers
api.open(ref, { to: "window", size: { w: 720, h: 520 } }); // a window or a modal at that size
api.over; // in a modal: the record it was opened over — its context (null elsewhere)
api.replace(ref); // show it HERE without a step back: the record a form just created
api.setParams({ tenant }); // a filter that lives in the reference: survives reload and links
useCrumbs(api); // the breadcrumb, ready for List.Crumbs / Record.Crumbs — follows setTitle
usePhone(api); // one screen right now: what a view OFFERS — no «open beside» on a phone
api.back(); // one step back: the page's breadcrumb, or the peek's own trail
api.close(); // leave: closes the panel, the peek or the modal; on the page, goes back
api.expand(); // a window, a side panel or the peek grows into the page
api.setTitle(name); // the record's real name, for the crumbs and the frames, once loaded
api.setDirty(true); // unsaved: a crumb, a close or the browser's Back ask first
api.select(refs); // publish what this view has selected
api.context; // read what the user is on and what is selected — references only
api.pick(ref, onPick); // open a chooser (a many2one search); its view calls api.answer(ref)
api.pick(ref, onPick, { to: "modal" }); // the chooser as a modal over the form
api.pick(ref, onPick, { size: { w: 720, h: 520 } }); // a chooser window at that size (480×360 without it)
api.pick<boolean>(confirmRef, (ok) => ok && post(), { to: "modal" }); // any value, not only a ref
api.pick(ref, onPick, { question: { chosen } }); // what the chooser is asked, in memory
api.choosing; // in the chooser: { question } while someone waits for its answer; null when opened to lookA chooser knows it is one: api.choosing says it was opened by pick and what it was asked,
so the same list draws a «Choose» per row or rows that open, with no flag in its reference. The
question lives exactly as long as the wait for the answer — in memory, like the answer — and so
does choosing: a link or a reload opens the view to look at it. What must survive those (a
filter, a company, a default) is not a question: it goes in params.
A modal belongs to the surface it covers — the page, a window, a side panel or the peek —
and blocks only that one: the rest of the workspace keeps answering, and a window keeps moving
and closing by its own title bar. One per surface: opening another one over the same surface,
or from inside it, replaces it. When its surface shows another record or closes, the modal goes
with it (asking first if something was typed). What it shares with whoever opened it travels in
its reference (params) — or, for a chooser, in its question — and comes back with
api.answer; api.over says what it covers. No
blur unless asked.
On a phone — when the workspace is narrower than 640 px (<Composer phoneBelow>, 0 never)
— it is one screen, and the views change nothing: the page takes it all; a window or a side
panel opens as the page, with its crumb to come back; a chooser opens as a sheet from the bottom,
so the form that asked stays to receive the answer; the peek is the screen's width. Panels that
were already open wait in «Also open», mounted, and one tap brings each to the page. Widen it and
the desk is back as it was.
A view that wants to know — to offer nothing that opens beside — asks usePhone(api). How it is
drawn at a width is its CSS: every view sits in a container named sc-view (the page, a panel,
the peek, a modal, a skin's own drawer), so @container sc-view (width < 640px) answers a narrow
side panel on a desktop too, which a phone check would not.
A view fills its surface. That container is one element the composer owns, .sc-view: a
column as tall as the surface, around whatever the view returns. Its children stack and keep
their height, so a view's last child can stand at the foot of a short record
(margin-top: auto) and stick to it while a long one scrolls (position: sticky; bottom: 0) —
the floating actions of a record, a chat's input, a bar of totals — the same in every surface,
with nothing to override in the composer's classes.
From the app, around the workspace: workspace.start(ref) starts over from a menu (no
breadcrumb behind, no peek, the panels stay), and useSection(workspace, entries) says which
entry of that menu the person is under, to mark it — still the same entry a record and its lines
deeper. The menu itself is the app's: its groups, its icons, who may see what.
useWorkspace({ hash: true }) puts the workspace in the URL with the browser's Back working, and
a reload keeps the breadcrumb and the names views gave — drawn on a server too, add
serverRendered: true (Server rendering). Unsaved changes are asked with
the composer's own dialog; useWorkspace({ confirmDiscard }) replaces it.
Where each behaviour lives
The same gesture means the same thing on every screen:
| Where | Gesture | Destination |
| --------------------------------------------------- | ------------------------ | ------------------------------------------- |
| A row of a list | click | page, with breadcrumb |
| A record's name INSIDE the peek | click | a step in the peek; ← comes back |
| The record's name in a column (RecordLink) | hover icons, Space, ⇧, ⌘ | peek, side, window |
| A record's name inside a card that drags (kanban) | draggable={false} | the card drags; the name only clicks |
| A many2one field | open · search | window · a modal that answers |
| A short task on a record (register a payment) | click | modal over that record |
| A record's buttons that lead (see its items) | click | side |
| A record's buttons that produce (post, reconcile) | click | nothing opens: they act on the record |
| Ticking rows | select | nothing opens: the context changes |
| ⌘K | Enter · ⌥ · ⇧ · ⌘ | page · peek · side · window |
Using it
Declare a domain:
import { createRegistry } from "@sincpro/web-composer/domain";
const registry = createRegistry([
{
domain: "accounting",
kind: "entry",
title: (ref) => `Entry ${ref.id}`,
noun: "Entry", // ⌘K says what each record it found is: «Entry · ACME»
search: async (query) => findEntries(query), // ⌘K asks every domain that searches
load: async () => (await import("./EntryView")).EntryView, // lazy: a remote module fits here
},
]);Draw the workspace:
import {
Composer,
installComposerCopy,
SPANISH_COMPOSER_COPY,
useWorkspace,
} from "@sincpro/web-composer";
installComposerCopy(SPANISH_COMPOSER_COPY); // optional: the composer's words in Spanish
export function App() {
const workspace = useWorkspace();
return (
<>
<button onClick={() => workspace.openPalette()}>Search…</button>
<Composer workspace={workspace} registry={registry} />
</>
);
}workspace.openPalette() opens ⌘K from your own bar, as the shortcut does; openPalette({ query })
hands it what was already typed there. Each domain's results show as they arrive: a slow one does
not hold back the others. A shortcut is written with a Mac's glyphs (⌘K) or the web's words
(Mod+K) and drawn as each keyboard reads it — Ctrl+K off a Mac; an app that draws shortcuts itself
does the same with platformKeys(text).
Write a view — it receives its reference and the API, nothing else. It is drawn with whatever your app uses; here, web-ui:
import { RecordLink, useCrumbs, type ViewProps } from "@sincpro/web-composer";
import { List } from "@sincpro/web-ui";
export function Entries({ api }: ViewProps) {
const crumbs = useCrumbs(api);
return (
<List items={entries} keyOf={(e) => e.id} onOpen={(e) => api.open(entryRef(e.id))}>
<List.Bar>
<List.Crumbs crumbs={crumbs} />
</List.Bar>
<List.Table
columns={[
{
id: "number",
header: "number",
value: (e) => e.id,
cell: (e) => (
<RecordLink api={api} resource={entryRef(e.id)}>
{e.id}
</RecordLink>
),
},
]}
/>
</List>
);
}The Storybook in this repository is the long version: eleven accounting use cases — journal entries, journal items, bank reconciliation, a form with relations, an audit where the detail follows the selection, ⌘K, the keyboard, what happens when something fails, and your own design over the composer.
An agent in the browser (WebMCP)
WebMCP lets a page offer tools to the agent
built into the browser (document.modelContext.registerTool; a W3C Community Group draft, in
Chrome behind an origin trial). Everything is feature-detected: without it nothing happens.
<Composer workspace={workspace} registry={registry} agentTools />;
// workspace.where · workspace.open · workspace.search · workspace.act (the ⌘K actions)
// a view offers what ITS screen can do, alive while the view is:
useViewTool(api, {
name: "register_payment", // offered as register_payment.invoice-F-1: the record it acts on
description: "Open the form to register this invoice's payment",
execute: () => api.open(paymentRef(invoice.id), { to: "modal" }),
});The agent is one more person at the desk: it opens through the same open, a phone still turns
a window into the page, and throwing away what was typed still asks first.
When a view breaks
Each view draws inside its own boundary: a view that throws while drawing shows a notice in its
panel and the rest of the workspace goes on. onViewError tells the application, once per
failure, with the reference the view was opened with — hand it to the error reporter the use
cases report to:
<Composer
workspace={workspace}
registry={registry}
// @sincpro/client-framework's reportError, or the application's own reporter
onViewError={(error, { resource }) => reportError(error, `view ${formatRef(resource)}`)}
/>A host drawn outside Composer (PanelHost, ViewHost) reads the same handler from
ViewErrorProvider. A handler that throws is ignored: telling about a failure never becomes a
second one.
Testing a view
A view talks to the workspace only through its api, so a test checks what it ASKED for — no
store, no shell, no browser:
import { createTestApi } from "@sincpro/web-composer";
const t = createTestApi(invoiceRef("F-1")); // { surface, over, crumbs, selection, choosing, phone } optional
render(<Invoice resource={t.api.self} api={t.api} />);
// … click «Register payment»
expect(t.callsTo("open")[0].args).toEqual([paymentRef("F-1"), { to: "modal" }]);
t.respond(true); // answers the last chooser it opened, as its view wouldServer rendering
It works in a server-rendered app — Next.js (App Router or Pages Router), any SSR —, and nothing changes for a single-page app.
Server Components may import from
@sincpro/web-composer. Every module that needs the browser (hooks, context, events) starts with"use client", and a test keeps it so; the model (@sincpro/web-composer/domain),createWorkspaceStore, the copy andplatformKeysstay callable from a server. The workspace itself lives in the browser: hold it in a client component of your own, and draw<Composer>there.The workspace in the URL. The browser never sends the hash to the server.
useWorkspace({ hash: true })reads it as the store is created — a single-page app shows the link's place on its first frame —, so hydrating, the browser would draw a place the server did not: a hydration error. A server-rendered app asks for"use client"; const workspace = useWorkspace({ hash: true, serverRendered: true });It starts at
initial, what the server drew, and takes the URL's place once mounted, with its breadcrumb on a reload — before the effects of the component that holds it, soif (workspace.get().page === null) workspace.start(home)in an effect still sees the link.createWorkspaceStore({ hash: true, serverRendered: true })does the same on its first listener or its first change, whichever comes first.Drag and drop is loaded by the browser when the workspace mounts, never on import: a server — plain Node included — imports and draws the composer without touching
@atlaskit/pragmatic-drag-and-drop. The browser's bundle still gets it, as any dependency.The words.
installComposerCopysets the one global there is, and a server renders every request in one process: install it in a module every page loads (the root layout's client providers), never in one page.
The story «16 · Dibujado en el servidor» draws the workspace with renderToString, opens a link
and hydrates it in Chrome: no difference with the server, then the link's record.
Your design over it
Colors
Every color, radius and shadow is a CSS variable with a default (light and dark). Set them anywhere above the workspace — no stylesheet to import:
:root {
--sc-surface: var(--my-surface);
--sc-accent: var(--my-brand);
/* --sc-ground --sc-line --sc-line-strong --sc-ink --sc-muted --sc-danger --sc-scrim
--sc-shadow --sc-radius --sc-radius-control --sc-text --sc-text-small
--sc-icon (14px: every icon in a control, yours too) --sc-modal-scrim --sc-modal-blur */
}Three levels
The composer owns the behaviour; the look is yours. Take only what you need:
Colors — the
--sc-*variables above.Pieces —
skinswaps icons and parts one at a time; what you do not pass stays default:<Composer workspace={workspace} registry={registry} skin={{ icons: { close: X, more: Ellipsis }, // drawn at --sc-icon, whatever size they come in Peek: MyDrawer, // ({ title, onClose, actions, children }) Modal: MyModal, // ({ title, blur, onClose, children }) Confirm: MyConfirm, // ({ open, title, detail, keep, discard, onAnswer }) Notice: MyNotice, // ({ heading, detail, bad }) }} />Everything —
skin={{ styles: false }}drops the default sheet; style the stablesc-*classes from scratch.
The story «11 · Tu diseño sobre el composer» plugs web-ui's Peek and lucide's icons this way —
the composer imports neither.
Development
nvm use # Node 26, from .nvmrc
make init # pre-commit + yarn install
make test # vitest: the model's rules (Node) + every story with its play (Chrome)
make build
make dev # Storybook on :6007 — one story per use case; «Run tests» in the sidebarEvery operation — local or CI — goes through the Makefile; run make to list the targets.
src/domain/ the model: pure TypeScript, no browser state, tested in Node
src/state/ the store and the API views receive
src/shell/ the React shell, with its own minimal skin (sc-* classes, --sc-* variables)
tests/ the model's rules, vitest in Node
stories/ the use cases, over a fake accounting app drawn with web-ui (dev only)CI/CD
The workflows in .github/workflows/ only delegate to the shared Sincpro-SRL/.github
pipeline, which calls make init, make verify-format, make test,
make update-version VERSION=x and make publish.
License
MIT © Sincpro S.R.L.
