Skip to content
SheetForge

Nodes, slots and tokens

Three capabilities add to what an edge contributor can edit on the canvas: node menu entries, connect slots, and a row for the part of a token that is not the key. This page also covers the field name that makes an extra edge editable.

The Data Studio finds each capability by casting the registered edge contributor. Canvas editing contracts describes the registration.

Offer one more element

Sometimes "one more" is not a new row but one more element in each of several cells. The canvas cannot invent that gesture.

With IVirtualNodeFactory, declare the kinds you can make. When one is picked, hand back the cell writes.

using SheetForge.Core.Edges;
 
public sealed class ExampleStepContributor : IEdgeContributor, IVirtualNodeFactory
{
    // Called every time the node menu is built — keep it cheap and side-effect free.
    public IReadOnlyList<VirtualNodeKind> KindsFor(EdgeAuthoringContext context, string tab, string recordId)
        => tab == "ExampleSkills"
            ? new[] { new VirtualNodeKind("step", Loc("Add a step")) }   // your own translated string
            : null;
 
    public bool TryPlanCreate(EdgeAuthoringContext context, string tab, string recordId,
                              VirtualNodeKind kind, out IReadOnlyList<EdgeCellWrite> writes)
    {
        writes = null;
        if (kind.Id != "step") return false;                            // not mine → nothing happens
        writes = new[] { … };                                           // one element appended per column
        return true;
    }
}

KindsFor is called every time the node menu is built. Keep it cheap and free of side effects.

The label is already translated. Core does not translate it. Supply the string your plugin resolved, as Theming and strings describes.

A / in the label makes a submenu, so you can group your own entries.

Nodes that are not in a sheet

tab may be a virtual tab name or empty. Nodes that your canvas override put on screen do not live in a sheet.

The menu still offers what you declare, because the cells you write are named by your plan, not by the node's identity. Tabs owned by a code registry are excluded.

Undo and failure

The writes are one Undo step, all or nothing, by the rule in How a batch of writes is staged. Returning false leaves nothing staged.

Declare connect slots

Connect slots normally come from the schema, from its RecordId@Tab columns. Two cases fall outside that. A node that your override put on screen has no columns. A contributor edge only reveals a slot once a link already exists.

In both cases the first link has nowhere to start. Declare the slots with IEdgeSlotDeclarer instead.

using SheetForge.Core.Edges;
 
public sealed class ExampleStepContributor : IEdgeContributor, IEdgeSlotDeclarer, IBatchAuthorableEdgeContributor
{
    // Called per card and per port gate — keep it cheap and side-effect free.
    public IReadOnlyList<DeclaredSlot> DeclareSlots(EdgeAuthoringContext context,
                                                    string nodeTab, string nodeRecordId)
        => nodeTab == "#step"
            ? new[] { new DeclaredSlot("target", "ExampleEffects", /*isList*/ false) }
            : null;
}

DeclareSlots is called per card and per port gate, the check the canvas runs before a wire may land on a port. Keep it cheap and free of side effects.

Slot names

The name has two duties. It must be unique within that node. It must also equal the FieldName of the edge you draw into it, because slot lookup and wire anchoring both match on that name.

If a sheet column already has that name, the sheet wins and your declaration is quietly dropped.

Declare and plan together

Declaring is not planning. A declared slot is connected through your plan, which is IAuthorableEdgeContributor or the batch form.

If you declare without planning, the port opens but nothing is staged. Implement both.

Ports on nodes with no sheet row

Ports open on nodes with no sheet row. For a node whose tab is not a sheet, the window does not look for a row by that name. The write address comes from your plan and is checked at staging time.

Edit the rest of a token

Linking and unlinking move a whole token, one entry of a list cell. Often the token is more than a key. For example, attack:add:10 names a stat and how much.

Add IEdgeTokenEditor to the same contributor. The wire inspector gains one row for that leftover, the part that is not the key.

using SheetForge.Core.Edges;
 
public sealed class ModifierStatEdgeContributor : IEdgeContributor, IAuthorableEdgeContributor, IEdgeTokenEditor
{
    public bool TryDescribeToken(EdgeAuthoringContext context, RecordEdge edge,
                                 out EdgeTokenDescription description)
    {
        description = null;
        if (edge.FieldName != "modifier") return false;                    // not mine
 
        // Read the fragment out of the cell — never rebuild it from the edge, or the
        // highlight points at a piece that is not there.
        string fragment = FindFragment(context.CellText(edge.FromTab, edge.FromRecordId, "modifier"),
                                       edge.ToRecordId);
        if (fragment == null) return false;                                // hand-edited away
 
        description = new EdgeTokenDescription(
            /*tokenText*/ fragment,                                        // "attack:add:10"
            /*modifierText*/ fragment.Substring(fragment.IndexOf(':') + 1),// "add:10"
            /*modifierLabel*/ "op:value",
            /*isChoice*/ false, /*options*/ null, /*optionLabels*/ null);   // free text
        return true;
    }
 
    public bool TryPlanSetModifier(EdgeAuthoringContext context, RecordEdge edge,
                                   string newModifier, out EdgeCellWrite write)
    {
        // …rebuild the cell with that one fragment's leftover replaced, key untouched…
    }
}

Both halves read the same cell

An edge knows where it points, not what letters it is written in today. So describing takes the same EdgeAuthoringContext that the write takes. That makes the highlighted fragment and the rewritten fragment provably the same one.

Read the fragment out of the cell. Never rebuild it from the edge, or the highlight points at a piece that is not there.

The token row never changes the key

The row changes only the leftover, never the key. Changing what a link points at is re-aiming, which you do by dragging the wire.

Returning false from either half hides the row or disables it. There is no staging and no silent failure.

Describe the widget

The widget is yours to describe. isChoice with options draws a popup. Otherwise the row is a text field. The row's label and the option labels are your strings.

If there is no leftover at all, construct new EdgeTokenDescription(tokenText), and the row is not drawn. A core reference behaves this way with no code at all, because its key is the whole token.

Name the cell a wire is written in

A wire can only be edited if it names the cell it is written in. The core fills that in for the references it reads itself.

An extra edge that you add in a canvas override names its cell by naming the field.

// Display-only edge — the canvas honestly reports it cannot be edited.
builder.AddEdge(tab, recordId, targetTab, targetKey, "raises");
 
// Edge that names its cell: "this link is written in (tab, record, column)".
builder.AddEdge(tab, recordId, targetTab, targetKey, "listen", /*fieldName*/ "listen");

When a named wire is editable

Naming a cell does not promise that the wire is editable. It says where the link lives.

An edge you added is handed to the same plumbing a contributor edge uses. It becomes editable exactly when an IAuthorableEdgeContributor claims it.

If that column is a plain text or enum column with nobody to rewrite it, the canvas reports the wire as not editable here, instead of letting a gesture silently do nothing.

Next steps