Skip to content
SheetForge

Canvas editing contracts

Opt-in capabilities extend canvas editing to the places the core cannot reach. This page covers how the Data Studio finds them, where new records may be created, and how a gesture becomes cell text.

What the canvas edits by itself

The Data Studio's record canvas is a place to edit as well as a view. Right-clicking creates records, connects them and disconnects wires, as Edit on the canvas describes. All of that works on a project with no plugins for ordinary RecordId@Tab columns.

The capabilities on this page and in Nodes, slots and tokens extend the canvas where the core cannot reach. None of them changes an existing contract, so a plugin that ignores them compiles unchanged.

How capabilities are discovered

A capability is never discovered by itself. The window finds every one of them by casting the objects that are already registered.

CapabilityCast fromWhat it adds
IAuthorableGraphShapeThe canvas override registered by ISheetForgeGraphPluginWhere new records may be created
IAuthorableEdgeContributorThe edge contributor registered by ISheetForgeEdgePluginTurns one gesture into one cell write
IBatchAuthorableEdgeContributorThe same edge contributorTurns one gesture into several cell writes
IVirtualNodeFactoryThe same edge contributorOffers "create one more" on the node menu
IEdgeSlotDeclarerThe same edge contributorDeclares connect slots the schema cannot derive
IEdgeTokenEditorThe same edge contributorDescribes a token and edits the part that is not the key

This page covers the first three. Nodes, slots and tokens covers the last three.

Register an edge contributor

The five edge-side capabilities are reached only if the class is registered as an IEdgeContributor. Registration goes through ISheetForgeEdgePlugin, which Validators and edges describes.

If your domain contributes no edges of its own, that is not a reason to skip registration. Implement ContributeEdges as an empty method and register the class anyway. That empty contributor is the officially supported way to join.

public sealed class ExampleSlotPlugin : ISheetForgeEdgePlugin
{
    public void RegisterEdgeContributors(EdgeContributorRegistry contributors)
        => contributors.Register(new ExampleSlotContributor());
}
 
public sealed class ExampleSlotContributor : IEdgeContributor, IEdgeSlotDeclarer
{
    public string Name => "ExampleSlots";
 
    // Nothing to declare — this class is here for the capabilities below.
    public void ContributeEdges(EdgeContributionContext context, ICollection<EdgeSpec> edges) { }
 
    public IReadOnlyList<DeclaredSlot> DeclareSlots(EdgeAuthoringContext context,
                                                    string nodeTab, string nodeRecordId) => …;
}

Exceptions in a capability

All of the capabilities run inside try/catch. An exception becomes an English console warning and disables that one affordance, nothing else.

Choose where records are created

IAuthorableGraphShape decides the tabs in which the canvas may create records. Without it, the window uses two defaults, and they are deliberately different.

The creatable-tabs list

The creatable-tabs list is one of the two defaults this capability replaces. It also decides whether a canvas opens at all.

The list covers every tab the focus tab's schema can reach, following references transitively. It is computed from the schema, not the data, so it holds even on a sheet that has no rows yet.

Reaching a tab two links deep is stepwise. Create the intermediate record, its ports appear, and the next hop joins the cascade.

The linking cascade

The linking cascade is the picker you see on empty canvas. It is narrower than the creatable-tabs list. It starts from the tabs that the ports currently drawn on screen aim at.

Tabs that both defaults drop

Either way, tabs owned by a code registry and tabs with no key column are dropped. A new record there could not have an identity.

Replace the defaults

An override registered for the focus tab can add this interface to replace both defaults. Canvas overrides describes how to register an override.

using SheetForge.Core.Graphing;
 
public sealed class ExamplePipelineAugmenter : IRecordCanvasAugmenter, IAuthorableGraphShape
{
    // Empty list = no creating from this canvas. The window still applies its own gates
    // (read-only source, running pipeline, workbook-backed tab, no key column) on top.
    public IReadOnlyList<string> CreatableTabs(GraphBuildContext context, string tabName)
        => new[] { "ExampleEffects", "ExampleActions" };
}

An empty list means no creating from this canvas. The window still applies its own gates on top of the list you return.

The override may name a tab that no port on screen accepts. That tab stays listed in the linking cascade with its reason attached. It does not disappear.

Make an edge editable

An edge you contribute with IEdgeContributor is drawn but not editable, because only you know the notation it lives in. Add IAuthorableEdgeContributor to turn a gesture back into cell text.

The window stages exactly what you return. The parser then checks that text as it checks a typed value.

using SheetForge.Core.Edges;
 
public sealed class ModifierStatEdgeContributor : IEdgeContributor, IAuthorableEdgeContributor
{
    public bool TryPlanConnect(EdgeAuthoringContext context, string fromTab, string fromRecordId,
                               string toTab, string toRecordId, out EdgeCellWrite write)
    {
        write = default;
        if (fromTab != "ExampleEffects" || toTab != "ExampleStats") return false;   // not mine
 
        // CellText = the cell as it reads right now (baseline + staging), not the parsed value.
        string current = context.CellText(fromTab, fromRecordId, "modifier");
        if (current.Contains(toRecordId + ":")) return false;                       // already linked
 
        string next = current.Length == 0 ? toRecordId + ":add:0"
                                          : current + "; " + toRecordId + ":add:0";
        write = new EdgeCellWrite(fromTab, fromRecordId, "modifier", next);
        return true;
    }
 
    public bool TryPlanDisconnect(EdgeAuthoringContext context, RecordEdge edge, out EdgeCellWrite write)
    {
        write = default;
        if (edge.FieldName != "modifier") return false;
        // …remove the fragment naming edge.ToRecordId, hand back the rewritten cell…
        write = new EdgeCellWrite(edge.FromTab, edge.FromRecordId, "modifier", rewritten);
        return true;
    }
}

Both methods are called during a gesture. An exception in either one is handled as Exceptions in a capability describes.

What the return value does

false means nothing happens. No staging is created, and the menu item is disabled with its reason. There is never a half-applied edit.

Returning true with nonsense text is allowed but pointless. The staged value goes through the same pre-flight validation as a typed one and shows up in Problems.

Address by key, not by row

EdgeCellWrite names a tab, a record id and a field. Row numbers are re-resolved at write time, so a staged plan survives rows moving.

Read the current cell text from the context

CellText returns the value including staging, so the second of two links made in a row sees the first. Reading the parsed table instead would miss the first one.

Change several cells in one gesture

Some data keeps one item spread across parallel columns. An example is stepDelays | stepTargets | stepCounts, where the entries at one index of every column make one step.

Adding a link there has to grow every column at once, or the columns end up different lengths. A single-cell plan cannot avoid that half-valid state.

IBatchAuthorableEdgeContributor is the sibling of IAuthorableEdgeContributor, not a subclass. Contributors that only have the singular form are untouched.

using SheetForge.Core.Edges;
 
public sealed class ExampleStepContributor : IEdgeContributor, IBatchAuthorableEdgeContributor
{
    public bool TryPlanConnectMany(EdgeAuthoringContext context, string fromTab, string fromRecordId,
                                   string toTab, string toRecordId,
                                   out IReadOnlyList<EdgeCellWrite> writes)
    {
        writes = new[]
        {
            new EdgeCellWrite(fromTab, fromRecordId, "stepTargets", Append(context, fromTab, fromRecordId, toRecordId)),
            new EdgeCellWrite(fromTab, fromRecordId, "stepDelays",  AppendDefault(context, fromTab, fromRecordId)),
        };
        return true;
    }
 
    public bool TryPlanDisconnectMany(EdgeAuthoringContext context, RecordEdge edge,
                                      out IReadOnlyList<EdgeCellWrite> writes) => …;
}

How a batch of writes is staged

Every write in the list is staged as one native Undo step. If a single one cannot be written (no such row, read-only source, pipeline running), nothing is staged at all.

Which form the window asks

If one class implements both the singular and the batch form, the window asks the batch form only. One gesture never has two different answers.

Contributors are still asked in registration order, and the first one that plans wins.

Every write needs an address

An empty list, or a list containing a write with an empty tab or field, counts as "no plan".

Cut several wires in one gesture

Unlinking runs on a chain. When several wires on one card are cut in a single gesture, the context you read already carries the earlier plans in this gesture. Cutting two tokens, two entries of the same list cell, therefore removes both.

The singular contract has no surface to receive that intermediate value. The batch capability is how that limit is lifted.

A record being created cannot be a target

In the "create and link in one gesture" flow, write addresses are resolved before the new row enters the session. A plan aimed at the record being created therefore cannot stand, and the whole gesture fails.

Aiming at rows that already exist is unaffected. The parallel-column case is one of those.

Next steps