Add Surface Element
add_surface_elementAdd shapes, connectors, text, or groups to an AFFiNE edgeless canvas. Programmatically build diagrams with customizable properties like fill, stroke, and text.
Instructions
Add a shape, connector, text, or group to the AFFiNE edgeless canvas surface. Shapes support rect/ellipse/diamond/triangle with fill, stroke, and text. Connectors draw arrows between shapes (by id) or between absolute points. Use for building diagrams programmatically. Style fields that don't apply to the chosen element type are reported in the response 'ignored' list (mirrors update_surface_element).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| workspaceId | No | Workspace ID (optional if default set) | |
| docId | Yes | Document ID | |
| type | Yes | Element type | |
| x | No | X position on canvas (shape/text; default 0). | |
| y | No | Y position on canvas (shape/text; default 0). | |
| width | No | Width (shape default 100, text default 200). | |
| height | No | Height (shape default 100, text default 30). | |
| shapeType | No | Shape type (default rect). Shape only. | |
| radius | No | Corner radius for rect (0.1 = rounded). Shape only. | |
| filled | No | Whether shape is filled (default true). Shape only. | |
| fillColor | No | Fill color. Prefer the `--affine-palette-shape-<color>` family (yellow/orange/red/magenta/purple/navy/blue/green/teal/grey/white/black). These are fixed colors — AFFiNE shape colors are not theme-adaptive by design. Shape only. | |
| strokeColor | No | Stroke color. Prefer the `--affine-palette-line-<color>` family (same color names as fillColor). Fixed colors, not theme-adaptive. Shape only. | |
| strokeWidth | No | Stroke width (default 2). Shape/connector. | |
| strokeStyle | No | Stroke style. Shape/connector. | |
| text | No | Text content (shape/text) or connector label. Replaces existing Y.Text on update. | |
| color | No | Text color. Shape default `#000000` — keep unless the fill is dark, then pass a contrasting hex. Canvas text default `--affine-text-primary-color` (theme-adaptive). Shape/text. | |
| fontSize | No | Font size (shape default 20, text default 16). Shape/text. | |
| fontWeight | No | Font weight (shape default 600, text default 400). Shape/text. | |
| sourceId | No | Connector source element id. Connector only. | |
| targetId | No | Connector target element id. Connector only. | |
| sourcePosition | No | Source [x,y]: relative [0-1] if sourceId set, absolute otherwise. Connector only. | |
| targetPosition | No | Target [x,y]: relative [0-1] if targetId set, absolute otherwise. Connector only. When both source/target are bound by id and neither position is provided, endpoints snap to the BlockSuite side-midpoint facing the other endpoint so connectors flow in a clear direction. Pass [0.5,0] top, [0.5,1] bottom, [0,0.5] left, [1,0.5] right to force a specific side. | |
| mode | No | Connector mode: 0=straight, 1=orthogonal (elbow), 2=curve (default 2). Connector only. | |
| frontEndpointStyle | No | Front endpoint style (default None). Connector only. | |
| rearEndpointStyle | No | Rear endpoint style (default Arrow). Connector only. | |
| stroke | No | Connector stroke color (default '--affine-text-primary-color' — theme-adaptive, near-black in light / near-white in dark). Accepts any CSS color or AFFiNE palette token. Connector only. | |
| label | No | Connector label (stored as text on the connector). Connector only. | |
| children | No | Child element ids. Group only. | |
| title | No | Group title. Group only. | |
| index | No | BlockSuite fractional-index string controlling z-order. On add, defaults to a key above every existing element's index (new elements render on top). On update, replaces the stored value — pass a key less than some existing index to send-to-back, or greater to bring-to-front. Use the value returned by list_surface_elements to pick a specific position. |