Reference parity
Give your own cell notation full reference parity with the built-in references. Implement IReferencingCellType on a parser you already register. A MyType@Tab column is then validated, suggested, propagated, drawn, picked and indexed exactly like RecordId@Tab.
How the opt-in works
There is no new registration channel. The Core casts the parsers already in CellParserRegistry. Canvas capabilities are cast from registered edge contributors in the same way. See How capabilities are discovered.
A custom type that does not implement the interface is unchanged, bit for bit.
What the opt-in gives you
One opt-in turns on every service below. Each one is the Core's own code path, not a re-implementation.
Integrity and suggestions
A key that does not exist is reported as UnresolvedRecordId, with the coordinate and the nearest existing key as a suggestion. The suggestions share the per-field suggestion budget with built-in references.
Rename propagation
A rename keeps the payload intact. The payload is the part of the notation that is not the key. Renaming attack to power rewrites attack:add:10 into power:add:10. The operator and the number are the author's, and they survive.
Graph edges
The link becomes a real edge with coordinates. The edge is drawn, and the node gets a port. The Used by count of the node inspector includes it. The reference index holds the edge in both directions. See ReferenceIndex.
The picker
The cell gets the same searchable ▾ dropdown a RecordId@Tab cell has. Picking a different record replaces the target and keeps the residue, which is the payload already in the cell.
When the parser registry is not available, the picker declines rather than pasting a bare key over your value.
Orphan detection and exported dropdowns
A row whose only outbound link lives inside your notation is not treated as unconnected.
A scalar column of your type also gets a data-validation dropdown over the target tab's keys. Columns that get a rule covers the exported dropdown rule.
The five hooks
IReferencingCellType has five hooks, and all of them work on one element. For a scalar column, the element is the whole cell. For List<MyType@Tab>, it is one ;-separated element. This is the same unit your ICellValueParser.TryParse receives.
| Hook | Answers | Used for |
|---|---|---|
bool TryGetTokenKey(elementText, out key) | "What does this element point at?" | Membership: is this cell already linked to that record |
string MakeToken(key) | "Write a new link to this key" | An empty cell, or appending to a list |
bool TryRetargetToken(elementText, newKey, out newText) | "Point this at something else" | Picking a different record in the ▾ cell, and re-aiming a wire on the canvas |
bool TryRemoveToken(elementText, key, out newText) | "Unlink this" | Clearing a scalar cell, or dropping a list element |
bool TryRewriteKeys(elementText, renames, out newText) | "Substitute all of these keys" | The rename sweep |
Rules for each hook
None of the five hooks may throw. Answer false or null for anything you cannot interpret, and preserve the residue whenever you rewrite.
MakeTokenfills the payload with a neutral starting point. The Data Studio and the web app must not invent values. Return null or empty, and the gesture is disabled with a reason instead of faked.TryRetargetTokenchanges the target only. Removing and re-making the token would reset the numbers a person typed.TryRemoveTokendecides what stays. Return empty text, and the element disappears: the scalar cell clears, or the list element is dropped. Return non-empty text, and that much stays.TryRewriteKeysis separate fromTryRetargetToken. A retarget is a single instruction from a person. A rewrite is a bulk pass, and an element holding two references must rewrite both.
The text half and the value half
Add IRefBearingValue to the parsed value as well. The opt-in has two halves. Both are needed, because they do different jobs.
| Half | Interface | Goes on | What it cannot do |
|---|---|---|---|
| Text | IReferencingCellType | The parser | See a parsed value |
| Value | IRefBearingValue | The value the parser produces | Restore the notation the author typed |
The example uses a stat:op:value notation, where the first segment is the reference.
using System.Collections.Generic;
using SheetForge.Core.Model;
// Text half — on the parser. `stat:op:value`, e.g. attack:add:10
public sealed class ModifierCellParser : ICellValueParser, ICustomCellType, IReferencingCellType
{
public bool TryGetTokenKey(string t, out string key)
{
key = Head(t); // the first segment is the reference
return key.Length != 0;
}
public string MakeToken(string key) => key + ":add:0"; // neutral, ready to edit
public bool TryRetargetToken(string t, string newKey, out string newText)
{
newText = newKey + Rest(t); // the residue is preserved
return Head(t).Length != 0;
}
public bool TryRemoveToken(string t, string key, out string newText)
{
newText = string.Empty; // nothing is left without the key
return Head(t) == key; // not ours → false, never overwrite blindly
}
public bool TryRewriteKeys(string t, IReadOnlyDictionary<string, string> renames, out string newText)
{
newText = t;
if (!renames.TryGetValue(Head(t), out string to)) return false;
newText = to + Rest(t); // attack:add:10 → power:add:10
return true;
}
// … TypeName / TryParse / ValueType / TryRender as in §2
}
// Value half — on the value the parser produces.
public struct Modifier : IRefBearingValue
{
public string stat; public string op; public float value;
IEnumerable<string> IRefBearingValue.ReferencedKeys =>
string.IsNullOrEmpty(stat) ? System.Array.Empty<string>() : new[] { stat };
}The remaining parser members are TypeName, TryParse, ValueType and TryRender. They are the same as in Add a custom cell type.
Implementing an interface adds no fields, so the baked ScriptableObject and the generated code are unchanged.
Alias types
The simplest use is an alias type. The value is a key, and the cell text is that key.
| Hook | What it does in an alias |
|---|---|
TryGetTokenKey | Trims |
MakeToken | Returns the key |
TryRetargetToken | Returns the new key |
TryRemoveToken | Returns empty |
The column is then a RecordId@Tab in every functional respect. No separate contract is needed for an alias.
The only thing left to you is presentation:
- The type appears under its own name in
@type. - You can attach a cell widget to that column alone. See Custom cell widgets.
- You can attach a canvas shape to that column alone. See Register an override.
Constraints
Both constraints are structural.
No ; in the payload
The Core splits a list cell into elements before your parser or any of the hooks sees the text. A semicolon inside a value would split that value into two elements.
Wrapper types carry the same constraint for the same reason.
The target must be a real sheet tab
@target must name a real sheet tab, exactly as RecordId@Tab does. A code registry's virtual tab is rejected with UnknownTargetTab. Sheet columns and virtual tabs explains why the import does not know virtual tabs.
That restriction lets the Core keep three services as its own, unmodified: unresolved-reference reporting, nearest-match suggestions and rename propagation.
Integer key spaces
The opt-in works against an integer key space too. The IntId key column describes such a tab. If the tab your @target names keys on IntId rather than RecordId, nothing changes in your code. The key your hooks hand back and receive is the integer written as text.
The target tab's own identity decides which key space to compare against. Your type does not.
Validation, nearest-match suggestions, rename propagation, edges, the picker and orphan detection all work the same way.
Padded integer spellings
An integer can be spelled several ways. For that reason, a rename hands TryRewriteKeys two spellings: the one that appears in that element, and the canonical one. For example, 007 and 7 both map to 12. An ordinal lookup inside your type does not miss a padded value.
No worked sample for integer keys
The bundled demo does not include a referencing custom type aimed at an IntId tab. Its Modifier example targets a string-keyed one. This path has tests but no worked sample to copy.
Next steps
- Markers and templates
Register per-column marker rows and sheet templates.
- Canvas editing contracts
Make your edges editable on the record canvas.
- Validators and edges
The recipe for a column that names no target.
- Types and grammar
The types behind custom cell types.