migrateNode2to3 function
A node's JSON alone (outside a document) upgraded as migrate2to3 upgrades the nodes of a document (its state and media patches on itself included). Returns a new map; never throws.
Implementation
Json migrateNode2to3(Json node, {MigrationReport? report, String id = ''}) {
final key = id.isEmpty ? (readString(node['id']) ?? 'node') : id;
final doc = migrate2to3({
'schema': kOldestSchemaVersion,
'nodes': {key: node},
}, report: report);
final out = readMap(readMap(doc['nodes'])?[key]) ?? copyJson(node) as Json;
// A node alone is not where a document starts: it inherits the default
// text style of the document it is put in (step text.lineHeight writes
// schema 2's on a document's top-level nodes).
if (!node.containsKey('defaultTextStyle') && jsonEquality.equals(out['defaultTextStyle'], {'height': 1.33})) {
out.remove('defaultTextStyle');
report?.entries.removeWhere((e) => e.step == 'text.lineHeight' && e.node.isEmpty && e.path == '/nodes/$key/defaultTextStyle');
}
return out;
}