M11: plugin widgets and the plugin panel tail

Widgets for FigCraft's own WebAssembly plugins (plugin API 3; API 1 and 2 plugins run unchanged), plus the panel tail.

- **Widgets.** A manifest with `"api": 3, "widget": true` makes a widget plugin. Plugins > Widgets (or `widget.insert {plugin, x?, y?}`) puts its widget on the page: the plugin is called with `widget: {id, state, event}` and hands back a description through the new `widget_render` import (`{state?, root}`: frames with auto layout, text, rectangles, ellipses and images it carries as base64). FigCraft validates the description (4 MB, 256 layers, 16 deep, finite numbers within ranges, hex colours, text length and control characters, a 16 KB state, images 1 MB each / 2 MB together / 4096 px a side) and builds it as a frame whose layers are locked, so the widget moves as one layer.
- **Clicks.** A plain click with the Move tool on a part the plugin named as a `target` (the cursor turns into a pointing hand there; quick repeated clicks each count) calls the plugin back in a fresh, metered sandbox (same fuel, memory and call limits as runs; nothing kept between calls, so the state and the click alone decide the result) as one undo step, and the widget is redrawn. Dragging moves it; Shift/Cmd/Alt clicks only select. Agents use `widget.click {id, target}` and `widget.list`.
- **State in the document.** The plugin id and the state live in the widget's own layer data (`figcraft.widget*`), so widgets survive save and reload, duplicate/copy and paste (the copy is a widget of its own), undo/redo, export (the built layers draw) and live sessions (synced like any layer data). No plugin can write `figcraft.widget*` data or call `widget.*`; a callback can only rebuild its own widget, and touches other layers only through the commands its manifest permits. A widget whose plugin is missing stays as drawn.
- **Example.** `plugins/examples/counter`: a counter between - and + buttons (read access, no assets). The SDK gained `Input::widget` and `render_widget`.
- **Panel tail.** Panels of several plugins are open at once, side by side (`plugin.ui` without an id returns the one opened last); a colour field's swatch opens FigCraft's colour picker beside the plugin's window (the plugin hears of the colour when a drag ends; also for parameters forms). Swatch grid's palette panel gained a label colour field.
- Docs: plugins.md (ABI v3, widget description, commands, limits), mcp.md, target-app-parity area 18, ROADMAP, gaps gap 6, roadmap M11; Spanish labels for the new commands.
This commit is contained in:
bflatastic
2026-10-12 04:41:28 +07:00
committed by BFlat
parent 1e0b51398a
commit 207373be15
34 changed files with 1716 additions and 165 deletions
+16 -2
View File
@@ -920,8 +920,9 @@ some commands, and can never touch files, other documents, the undo history, dia
plugins. A headless MCP session starts with no plugins: import them first. `plugins.runLast` runs
the last plugin command again.
A plugin that shows a panel (API 2) can be used headless too: `plugin.ui {id?}` returns the open
panel (`{plugin, command, title, controls, values}`, or null), `plugin.event {id, control, value?}`
A plugin that shows a panel (API 2) can be used headless too: `plugin.ui {id?}` returns plugin
`id`'s open panel, or without `id` the one opened last (`{plugin, command, title, controls,
values}`, or null; several plugins can have panels open at once), `plugin.event {id, control, value?}`
presses a button or sets a field as a click would (the plugin is called back; one undo step;
returns like `plugin.run`, with the updated `panel`), and `plugin.close {id}` ends the session.
Plugin settings are kept per plugin with the preferences (in a headless session, for the session).
@@ -932,6 +933,19 @@ Plugin settings are kept per plugin with the preferences (in a headless session,
{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"run_command","arguments":{"command":"plugin.event","params":{"id":"org.figcraft.examples.swatch-grid","control":"generate"}}}}
```
Widgets (API 3, layers on the canvas a plugin draws) are driven the same way: `widget.insert
{plugin, x?, y?}` puts one on the page (centred in the view without a position) and returns `{id,
plugin, state, targets, output, logs, calls, fuel}`; `widget.click {id, target}` clicks one of its
`targets` as a click on the canvas would (the plugin redraws it; one undo step; returns the same);
`widget.list` lists every widget in the file with its plugin, page, state and targets. A widget's
state is layer data, so it is saved, undone and synced with the file.
```json
{"jsonrpc":"2.0","id":4,"method":"tools/call","params":{"name":"run_command","arguments":{"command":"widget.insert","params":{"plugin":"org.figcraft.examples.counter"}}}}
{"jsonrpc":"2.0","id":5,"method":"tools/call","params":{"name":"run_command","arguments":{"command":"widget.click","params":{"id":12,"target":"increment"}}}}
{"jsonrpc":"2.0","id":6,"method":"tools/call","params":{"name":"run_command","arguments":{"command":"widget.list","params":{}}}}
```
### Dev Mode
- **Component code:** `inspect.code {id, language: react|swiftui|compose}` on a component, a