Skip to content

Instantly share code, notes, and snippets.

@rodydavis
Created March 22, 2024 19:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodydavis/17a0a19c8d91a08e2674a57b93ba5259 to your computer and use it in GitHub Desktop.
Save rodydavis/17a0a19c8d91a08e2674a57b93ba5259 to your computer and use it in GitHub Desktop.
Dart classes for JsonCanvas schema
import 'package:dart_mappable/dart_mappable.dart';
part 'schema.mapper.dart';
@MappableClass()
class JsonCanvas with JsonCanvasMappable {
List<JsonCanvasNode> nodes;
List<JsonCanvasEdge> edges;
JsonCanvas({
this.nodes = const [],
this.edges = const [],
});
static const fromMap = JsonCanvasMapper.fromMap;
static const fromJson = JsonCanvasMapper.fromJson;
}
@MappableClass(discriminatorKey: 'type')
class JsonCanvasNode with JsonCanvasNodeMappable {
String id;
int x;
int y;
int width;
int height;
JsonCanvasNodeColor? color;
JsonCanvasNode({
required this.id,
required this.x,
required this.y,
required this.width,
required this.height,
this.color,
});
}
@MappableClass(discriminatorValue: 'text')
class JsonCanvasTextNode extends JsonCanvasNode
with JsonCanvasTextNodeMappable {
String text;
JsonCanvasTextNode({
required super.id,
required super.x,
required super.y,
required super.width,
required super.height,
required this.text,
super.color,
});
}
@MappableClass(discriminatorValue: 'file')
class JsonCanvasFileNode extends JsonCanvasNode
with JsonCanvasFileNodeMappable {
String file;
String? subpath;
JsonCanvasFileNode({
required super.id,
required super.x,
required super.y,
required super.width,
required super.height,
required this.file,
this.subpath,
super.color,
});
}
@MappableClass(discriminatorValue: 'link')
class JsonCanvasLinkNode extends JsonCanvasNode
with JsonCanvasLinkNodeMappable {
String url;
JsonCanvasLinkNode({
required super.id,
required super.x,
required super.y,
required super.width,
required super.height,
required this.url,
super.color,
});
}
@MappableClass(discriminatorValue: 'group')
class JsonCanvasGroupNode extends JsonCanvasNode
with JsonCanvasGroupNodeMappable {
String? label;
String? background;
JsonCanvasNodeBackgroundStyle? backgroundStyle;
JsonCanvasGroupNode({
required super.id,
required super.x,
required super.y,
required super.width,
required super.height,
this.label,
this.background,
this.backgroundStyle,
super.color,
});
}
@MappableClass()
class JsonCanvasEdge with JsonCanvasEdgeMappable {
String id;
String fromNode;
JsonCanvasNodeSide? fromSide;
JsonCanvasNodeEnd? fromEnd;
String toNode;
JsonCanvasNodeSide? toSide;
JsonCanvasNodeEnd? toEnd;
JsonCanvasNodeColor? color;
String? label;
JsonCanvasEdge({
required this.id,
required this.fromNode,
this.fromSide,
this.fromEnd,
required this.toNode,
this.toSide,
this.toEnd,
this.color,
this.label,
});
}
@MappableEnum()
enum JsonCanvasNodeColor {
red,
orange,
yellow,
green,
cyan,
purple,
}
@MappableEnum()
enum JsonCanvasNodeSide {
top,
right,
bottom,
left,
}
@MappableEnum()
enum JsonCanvasNodeEnd {
none,
arrow,
}
@MappableEnum()
enum JsonCanvasNodeBackgroundStyle {
cover,
ratio,
repeat,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment