mergeNodePatch function
base (a node's JSON, or a patch of it) with patch merged in, as the
node's declarations read them: as mergePatch's JSON merge patch, except
that where patch writes a union-typed field (isUnionType) in another
form than base has, the patch's value replaces base's (its null
keys left out), as CSS replaces a declaration. A size object always
replaces (it has one key). props are the node type's prop
declarations (null: its props merge as plain JSON). With keepNulls, a
null is kept (two patches merged into one).
Implementation
Json mergeNodePatch(Json base, Json patch, {List<PropDef<Object?>>? props, bool keepNulls = false}) {
final out = <String, Object?>{...base};
for (final e in patch.entries) {
final fields = switch (e.key) {
'layout' => LayoutFields.all,
'decoration' => DecorationFields.all,
'props' => props,
_ => null,
};
out[e.key] = fields == null
? _plain(out[e.key], e.value, keepNulls, out.containsKey(e.key))
: _typed(out[e.key], e.value, {for (final f in fields) f.key: f.type}, keepNulls);
if (e.value == null && !keepNulls) out.remove(e.key);
}
return out;
}