# Whiteboards

A whiteboard is a live document (documents.live_create with content_type
application/vnd.adlass.live-whiteboard): an endless board with elements on
levels. Read it with documents.whiteboard_read, change it with
documents.whiteboard_edit; open boards show each change at once with your name.
Before designing a board, read_docs("whiteboard_design").

Let the user watch: create a new board empty, call documents.whiteboard_open
with a new idempotency_key and open the returned url in the user's default
browser right away (macOS `open`, Linux `xdg-open`, Windows `start`; it works
once, for two minutes; the user may edit there when their Space role allows),
then add elements. Open an existing board the same way before changing it,
once per conversation. Without a browser, show the link.
Sharing: whiteboard_open takes `emails`; they reach the board read-only through
`share_url` after confirming a code. Guest accounts (shares.create) do not work
for whiteboards.

Reading: levels (id, name, parent) and elements (id, level, type, x, y, w, h,
z, hue, label, data) as columns/rows. label is the text or title, data the
other fields (items as columns/rows), plus `comments` (open) and `votes` (last voting
round) when above 0. Filter with level, types or rect, page with cursor. Pass
content_hash back as expected_content_hash.

Ops (up to 200 per call, all or nothing):
- {op:"add", type, level?, place?, ...fields}
- {op:"update", id, fields:{...}}; null removes an optional field.
- {op:"move", id, x?, y?, dx?, dy?}; a frame takes what lies fully inside along.
- {op:"delete", id}; deleting a frame keeps its content.
- {op:"add_item", id, item:{...}, index?}, {op:"update_item", id, item_id,
  fields}, {op:"delete_item", id, item_id} for elements with items.
- {op:"add_level", name, parent?} adds a level and its portal in parent;
  {op:"update_level", level_id, name}; {op:"delete_level", level_id} removes
  the level, its portal and everything below.
Results list per op index, id, level_id and item_id. "$n" in id, level,
parent, place targets, connector ends or progress source is the element or
level of op n (0-based) of the same call. Unknown fields are rejected.

Placement (place): {at:{x,y}} is exact (top-left). {right_of:id, gap?},
{below:id, gap?}, {near:id}, {near:"viewport", rect} and {free:true} (default:
the middle of the existing elements, (0,0) on an empty board) are starting
points: if taken, the element goes to the next free spot, so check x/y in the
read. A frame around the start or target is no obstacle. {inside:frame_id}
takes a free spot in the frame below its title; the frame grows when full.
The board opens with (0,0) in the middle at 100 %, so center your layout: one
W wide and H high starts at x=-W/2, y=-H/2.

Sizes: set w/h only on free types (shape, frame, todo, image, link, cards).
The server sizes the rest and ignores your w/h: postit, text, progress, video
and instagram take only w; table, kanban, matrix, calendar, timeline and
mindmap take neither and resize after every item op; timer (240x120), stamp
(48x48) and progress ring (200x200) are fixed.

Warnings: the edit result lists `warnings` for the elements of that call.
{code:"overlap", id, with:[ids]}: move one of them. {code:"text_overflow",
id}: a shape's text does not fit; enlarge it or shorten the text. Elements
fully inside a frame do not overlap the frame. Fix every warning before you
finish.

Status: postit, shape and the items of kanban, matrix and calendar take status
open|doing|blocked|done, shown as a symbol. Check off work with {op:"update",
id, fields:{status:"done"}} or update_item. Frames, levels and progress count
by it.

Text: text, shape and postit read `text` as Markdown: `#`, `##`, `###`
headings, `**bold**`, `*italic*`, `<u>underline</u>`, `~~strike~~`,
`` `code` ``, `[link](https://…)`, lists with `- ` or `1. `; a newline is a
line break, other HTML stays plain text. They take size 12..160 px (presets
14, 18, 24, 32; default text 28, shape 16, postit 18; headings scale with it),
align left|center|right (default center for shape, else left) and font
sans|mono (default sans).

Style: shape and frame take icon, a Lucide icon name in kebab-case
("file-text", "users", "shopping-cart") or exactly one emoji, shown above
centered text, otherwise before the first line, and before a frame title;
and fill none|soft|solid (default soft; solid is saturated with white text).
shape also takes stroke solid|dashed|none (default solid; none draws a card
with a soft shadow).

Types (all take hue, rot, locked):
- postit: text (≤5000), size, align, font, status. It grows with its text.
- text: text, size, align, font. todo: title, items [{text, done}].
- frame: title, icon, fill, default 640x420. Always behind; fill it with
  place {inside}.
- stamp: emoji, one of 👍 ❤️ ⭐ ✅ ❓ 🔥 💡 ➕.
- timer: title, mode countdown|stopwatch, duration_ms (≤360000000, default
  300000). Start
  with started_at:"now"; reset with {started_at:null, elapsed_ms:0}.
- progress: title, display bar|ring|steps|stacked, value, max (default 100),
  unit (≤8, default %). Or source: id of a frame, todo, kanban or calendar, or
  "level", and the board counts its statuses live. stacked without source
  takes items [{text, value, hue?}].
- skill: a routine tile, skill_id (from routines.search with the Space's
  space_id), a fixed 248x64 tile with live run status. integration:
  provider_key (from integrations.catalog.list, e.g. shopify), a fixed 96x92
  logo. Omit w, h and hue. Join integration -> skill -> records with
  connectors: open boards animate live calls and writes along them.
- link: url, title. Cards: page (page_id), document (document_id), records
  (record_type_id, view_key), chart (record_chart_id or spec ChartSpec v1,
  display chart|number); all from the whiteboard's Space.
- document also takes view card|content (default card). content shows the
  document's text, default 480x600, resizable, scrolls once selected and is
  visible to guests of public boards; section (a heading line such as
  "## Steps") limits it to that section.
- portal: made by add_level. ink: points (flat x,y list relative to x/y),
  width 1..40.
- shape, connector, mindmap: read_docs("whiteboard_diagrams").
- table, kanban, matrix, calendar, timeline: read_docs("whiteboard_planning").
- image, video, instagram: read_docs("whiteboard_media").

Comments live outside the board and are never shown to guests:
documents.whiteboard_comments (document_id, element_id?, include_resolved?),
documents.whiteboard_comment_create (document_id, element_id, body: Markdown
≤10000; a reply is another comment), documents.whiteboard_comment_resolve
(document_id, comment_id, resolved). Votes come from people in the browser.

Colors (hue): Neutral -1 (grey), Indigo 275, Sky 215, Teal 175, Sun 80,
Berry 340, Night 250, Sage 140, Coral 30. Post-its without hue cycle through
the eight colors. Give each color one meaning per board (e.g. Coral =
blocked), name it in a label or legend and keep the rest Neutral.
Levels: "root" is the top level; the others are entered through their portal.
Limits: 5000 elements, 50 levels, 200 items per element, 4 MiB per board.

Example, a titled frame with two post-its and an arrow:
{"document_id": "...", "ops": [
  {"op": "add", "type": "frame", "title": "Ideas", "w": 560, "h": 300, "place": {"at": {"x": -280, "y": -150}}},
  {"op": "add", "type": "postit", "text": "Faster checkout", "place": {"inside": "$0"}},
  {"op": "add", "type": "postit", "text": "One-click reorder", "hue": 175, "place": {"right_of": "$1", "gap": 80}},
  {"op": "add", "type": "connector", "from": {"id": "$1"}, "to": {"id": "$2"}}
]}
