dvStudioImageOf function
The image a node describes.
src is the reference and source names its kind, defaulting to a URL so
that every document written before a page could say otherwise reads as it
always did. Built through DVImage.fromJson rather than a switch here, so
a page node and a model field cannot come to disagree about what stored
or asset means -- including the leniency, which is deliberate there: a
page that will not render because one word is misspelled is worse than one
that tries the address.
Implementation
DVImage dvStudioImageOf(Map<String, Object?> properties) {
final String reference = '${properties['src'] ?? ''}';
// An image with no source yet: one just dropped onto the canvas, or one an
// import could not resolve. A normal state, and a common one -- the reader
// refuses an empty reference, which is right for a model field and would
// take a page down here over a picture nobody has chosen.
if (reference.isEmpty) return const DVImage.network('');
return DVImage.fromJson(<String, Object?>{
'reference': reference,
if (properties['source'] != null) 'source': properties['source'],
if (properties['alt'] != null) 'alt': properties['alt'],
}) ??
const DVImage.network('');
}