Editors / Draw

Draw

A whiteboard on the canvas. Board is built on it.

Package
@forgeron/draw
Layers
core (no React) · /plugins · /plugins/editor · /react
On
@forgeron/canvas · @forgeron/ui

RshapeAarrowPpixel penFframedouble-click to write

Board:Sprint planQ1 product workshop (2,618 items)

/01 → Features come from plugins

core only: the canvas, nothing to draw withwhat a plugin removes stays in the board, shown as a dashed boxXthe star, a plugin of this page

/02 → What it covers
  • Rectangles, ellipses and diamonds with a solid or dither fill, a stroke and a label.
  • Sticky notes in the token colours that grow with their text; text typed in place.
  • Lines and arrows, straight or elbow, bound to items: they follow when the items move.
  • A pixel pen: strokes land on a 4 px grid and are simplified.
  • Frames: named, they move, clip and export their items.
  • Images from a file or a drop, kept in the page, never uploaded.
  • Group, lock, align, distribute, z-order; undo and redo through the canvas history.
  • Export a frame or the selection as PNG or SVG; copy and paste the board as JSON.
  • A minimal core (the canvas and the plugin host) and plugins for everything else: kinds, tools, rules, panels, exports. Add, remove or write them.
/03 → Use it
/01 → A board
import "@forgeron/canvas/styles.css";
import "@forgeron/draw/styles.css";
import { shapeItem, stickyItem } from "@forgeron/draw";
import { DrawEditor, useDrawStore } from "@forgeron/draw/react";

export function Board() {
  const store = useDrawStore();
  // A board is JSON: store.serialize() and store.load(json).
  return <DrawEditor store={store} label="Team board" />;
}
/02 → Plugins
import { createDrawStore, definePlugin, exportSvg, parseBoard } from "@forgeron/draw";
import { fullCorePlugins } from "@forgeron/draw/plugins";
import { defineEditorPlugin, rectangle, sticky, toolbar } from "@forgeron/draw/plugins/editor";
import { DrawEditor, useDrawStore } from "@forgeron/draw/react";

// A board of rectangles and notes: the whole configuration is this list (module scope: a new list
// rebuilds the editor). A board that holds arrows or frames still opens: they are kept, drawn as
// labelled boxes, skipped by the exports, and written back as they were.
const plugins = [rectangle, sticky, toolbar];
const store = useDrawStore({ plugins });
<DrawEditor store={store} plugins={plugins} />; // or variant="sketch" | "minimal" | "full"

// Read-only places load the core halves only, never React: an export at build time, a Worker.
const cores = plugins.map((p) => p.core);
const { items } = parseBoard(json, cores, { unknown: "keep" });
exportSvg(items, { ids: items.map((i) => i.id) }, cores);

// Your own kind: two halves, the first with no framework in it (see the star of this page).
const starCore = definePlugin({ id: "star", name: "Star", description: "A star.", kinds: { star: starKind } });
const star = defineEditorPlugin({ core: starCore, tools: () => [starTool] });
createDrawStore({ plugins: [...fullCorePlugins, starCore] });
/04 → Keys
SelectV
HandH
RectangleR
EllipseO
DiamondD
Sticky noteS
TextT
ArrowA
Pixel penP
EraserE
FrameF
Group⌘G
Ungroup⌘⇧G
Lock⌘⇧L
Export PNG⌘⇧E
Duplicate⌘D