Studio extensions
Three contracts add your own UI to the Data Studio: a widget above the record canvas, a button on the node inspector, and a cell widget in the grid. All three are opt-in and live in an Editor assembly.
Set up the Editor assembly
Implement these contracts in an Editor-side assembly that references SheetForge.Editor and SheetForge.Core.
The demo's Editor assembly is SheetForge.PluginDemo.Demo.Editor. It references SheetForge.Editor, SheetForge.Core and the plugin assembly. That is all the wiring an Editor-side extension needs.
Discovery
Discovery is automatic. TypeCache finds every implementation with a parameterless constructor. There is no registration call and no registry to bind.
An instantiation failure is logged and skipped.
Graph widgets
A widget is a strip of your own UI above the record canvas. It can be a fixed stage overview, an aggregate badge, or whatever the domain wants. The core ships no widgets, so this area is empty until a plugin fills it.
The return type is a VisualElement, a Unity UI type, so this contract lives in the Editor assembly rather than in Core. ISheetSourceProvider is the other kind of contract that lives there. Add an editor companion assembly lists the Editor-side contracts.
using SheetForge.Editor.Studio;
using UnityEngine.UIElements;
public sealed class ExampleStageStripWidget : IStudioGraphWidget
{
// context = Tab · ShapeId · ModeId · FocusRecordId · FocusRecord · Tables · References · CodeRegistries
public bool AppliesTo(StudioGraphContext context) =>
context.Tab == "ExampleSkills" && context.FocusRecord != null;
public VisualElement Create(StudioGraphContext context)
{
var strip = new VisualElement();
strip.Add(new Label("VALIDATE → CAST → COMMIT → DELIVER → APPLY"));
return strip; // return null to add nothing
}
}The demo widget is in Assets/SheetForge.PluginDemo/Demo/Editor/ExampleStageStripWidget.cs.
Widget rules
A widget is read-only by contract. The context exposes the parsed tables, the reference index and the code registries. It offers no way to create a staged edit. To change data from the canvas, use an inspector action, which stages the edit through the window.
Keep no state inside the element, because widgets are re-created every time the canvas is rebuilt. Keep state in your own objects. Rebuilds are coalesced to the pace of a person's actions, not keystrokes.
An exception in a widget does not break the canvas. When AppliesTo / Create throws, the Console shows an English warning, and the canvas still draws.
Inspector actions
An action is an extra button on the node inspector, the panel at the bottom right of the canvas. It is what this domain can do with this record. The inspector's own buttons, such as Open … and Duplicate and split, are built in. Everything else arrives through this contract.
using SheetForge.Editor.Studio;
public sealed class ExampleInspectorAction : IStudioInspectorAction
{
// A Loc key. The demo registers this key's sentences per language (§4.14);
// an unregistered key is displayed verbatim, so plain text also works.
public string LabelKey => ExampleLocStrings.BrakeActionKey;
public bool AppliesTo(StudioInspectorContext context) =>
context.Tab == "ExampleActions" && context.Record != null;
public void Execute(StudioInspectorContext context)
{
// Mediated mutation: the window turns this into one Undo step + one staged edit
// carrying the logical address (tab · record id · field).
context.StageCell(context.Tab, context.RecordId, "brakeSeconds", "0.25");
// Show the user what changed: (tab, original sheet row number, field); row 0 = tab only.
context.FocusCell(context.Tab, context.Record.RowNumber, "brakeSeconds");
context.RequestRebuild();
}
}The demo action is in Assets/SheetForge.PluginDemo/Demo/Editor/ExampleInspectorAction.cs.
Stage edits through the context
The context does not expose the authoring session. Every staging change must be one native Undo step and must bump the projection generation. The projection is the baseline with your staged edits applied. Handing out the raw session would give every plugin a way around that rule.
StageCell(tab, recordId, field, rawText) and StageCells(writes) are the whole mutation surface. The window owns the bookkeeping.
Two rules apply to every staged write:
- Pass canonical text. At reflect time, the importer's own parser parses the staged text, so write what the sheet would contain.
- When a key is not in the baseline, such as the key of a brand-new or unresolved record, the write is a no-op: nothing is written at all.
Change several cells in one step
To change several cells, use StageCells.
context.StageCells(new[] { new EdgeCellWrite(tab, recordId, field, text), … }) stages the whole list as one Undo step, all or nothing. If one write cannot be applied, none is. A null or empty list does nothing.
Calling StageCell several times splits Ctrl+Z into that many steps. For columns that belong together, that means a half-valid state appears in the middle of undoing.
Action services
| Service | What it does |
|---|---|
FocusCell | Scrolls the grid to a coordinate |
RequestRebuild | Asks for a refresh after you stage something |
Labels and exceptions
Discovery and exception handling work the same way as for widgets.
LabelKeyis a Loc key. An unregisteredLabelKeyis displayed verbatim, so plain text also works.- An empty key falls back to the type name.
AppliesTo/Executerun inside try/catch.
To register a key's sentences per language, see Theming and strings.
Custom cell widgets
The grid draws every cell with a built-in widget: boolean toggle, enum popup, reference picker or raw text. Some types deserve a better input, such as a curve, a color, a mini-grammar composer or a multi-line box. For those, replace the widget for that type name without touching how the value is parsed.
Check whether a hint is enough
Before writing a widget, check whether a hint would do. A hint covers a dropdown, a multi-line box, a slider, a toggle, a color picker, a curve editor and a gradient editor.
If that is all you want, register a StudioCellEditorHint instead. A hint needs no widget code, and it works in the browser too. Authoring surfaces covers hints.
The order is: this contract first, then the hint, then the core defaults. A hint is what the cell gets whenever no widget has claimed the type, or the one that did declined.
Implement the provider
using SheetForge.Editor.Studio;
using UnityEngine.UIElements;
public sealed class ModifierCellEditor : IStudioCellEditorProvider
{
// The base type name from @type (a CellParserRegistry name; for a wrapper, the wrapper name).
public string TypeName => "Modifier";
public VisualElement CreateEditor(StudioCellEditorContext context)
{
if (context.Type.IsList) return null; // decline — the built-in widget takes this cell.
var field = new TextField { value = context.CurrentRawText };
// Typing burst: coalesced into ONE Undo step for this cell.
field.RegisterValueChangedCallback(e => context.CommitTyping(e.newValue));
// Discrete confirmation (focus out): its own Undo step.
field.RegisterCallback<FocusOutEvent>(_ => context.Commit(field.value));
return field;
}
}Commit values
The widget shapes input, and the parser owns meaning. Whatever you commit is canonical sheet text. It goes through the same pre-flight validation as a typed value, and problems surface in the Problems panel. The widget never needs to validate.
There are two commit calls, because a single call would either spray Undo steps per letter or merge two distinct picks.
| Call | When to call it | Undo |
|---|---|---|
Commit | Picking from a list, releasing a slider, focus out | Creates one Undo step |
CommitTyping | Per keystroke | Coalesces a burst into one step |
Decline a cell
Returning null declines the cell, and the built-in widget takes over. Decline the shapes you do not handle, such as a List<T> of your type or optional fields.
context.Type is the parsed @type token. It carries everything needed to decide.
Offer reference keys
ReferenceKeys(tab) hands you the same candidate list the built-in reference picker uses: projected keys ∪ code-registry keys ∪ staged new-row keys, sorted. Projected keys are the keys of the baseline with your staged edits applied. There is no need to gather your own.
To let the person choose from that list, call StudioKeyPicker.Show(screenAnchor, tab, candidates, picked). It opens the same drop-down the built-in cell opens. Splice the returned key into your own notation before committing.
Three rules are the built-in reference cell's own and are not on that facade: creating a record, leaving the cell empty, and multi-toggling a list. A widget that owns the whole cell text owns those decisions too.
Claim a built-in type name
You may claim a built-in type name, not just your own. The registered-widget branch runs first, so TypeName => "float" really does replace the raw-text box for every float column. That is how a slider, a percentage field or a unit-suffixed box gets in.
Two cautions come with it:
- The widget applies to every column of that type in the project. Scope it by reading
context.FieldName/context.Taband returningnullfor the columns you did not mean. - What you commit is still canonical sheet text. A slider must render its value the way the parser reads it back. See
CanonicalValueRenderer.RenderFloatfor the float spelling the round trip expects.
Conflicts and failures
If two providers claim one type name, the first found wins and a console warning names both.
A thrown CreateEditor is caught and warned. The cell falls back to the built-in widget.
Next steps
- Authoring surfaces
Describe cell editors and panels without writing widget code.
- Theming and strings
Register color presets and translated UI strings.
- Canvas editing contracts
Let people create records and connect wires on the canvas.
- Studio extension points
Look up the types and members of these contracts.