|
| 1 | +import 'package:onix_flutter_bricks/core/arch/domain/common/converter/mapper.dart'; |
| 2 | +import 'package:onix_flutter_bricks/data/mapper/figma/properties_mapper.dart'; |
| 3 | +import 'package:onix_flutter_bricks/data/model/figma/nodes/connector/connector_node_data_model.dart'; |
| 4 | +import 'package:onix_flutter_bricks/data/model/figma/nodes/document/document_node_data_model.dart'; |
| 5 | +import 'package:onix_flutter_bricks/data/model/figma/nodes/frame/frame_node_data_model.dart'; |
| 6 | +import 'package:onix_flutter_bricks/data/model/figma/nodes/node/node_data_model.dart'; |
| 7 | +import 'package:onix_flutter_bricks/data/model/figma/nodes/section/section_node_data_model.dart'; |
| 8 | +import 'package:onix_flutter_bricks/data/model/figma/nodes/shape_with_text/shape_with_text_node_data_model.dart'; |
| 9 | +import 'package:onix_flutter_bricks/data/model/figma/nodes/sticky/sticky_node_data_model.dart'; |
| 10 | +import 'package:onix_flutter_bricks/data/model/figma/nodes/table_cell/table_cell_node_data_model.dart'; |
| 11 | +import 'package:onix_flutter_bricks/data/model/figma/nodes/text/text_node_data_model.dart'; |
| 12 | +import 'package:onix_flutter_bricks/data/model/figma/nodes/vector/vector_node_data_model.dart'; |
| 13 | +import 'package:onix_flutter_bricks/data/model/figma/properties/paint/paint_property_data_model.dart'; |
| 14 | +import 'package:onix_flutter_bricks/data/model/figma/properties/type_style/figma_type_style.dart'; |
| 15 | +import 'package:onix_flutter_bricks/domain/entity/figma/nodes/connector_node/connector_node_entity.dart'; |
| 16 | +import 'package:onix_flutter_bricks/domain/entity/figma/nodes/document_node/document_node_entity.dart'; |
| 17 | +import 'package:onix_flutter_bricks/domain/entity/figma/nodes/frame_node/frame_node_entity.dart'; |
| 18 | +import 'package:onix_flutter_bricks/domain/entity/figma/nodes/node/base_node.dart'; |
| 19 | +import 'package:onix_flutter_bricks/domain/entity/figma/nodes/node/base_node_entity.dart'; |
| 20 | +import 'package:onix_flutter_bricks/domain/entity/figma/nodes/section_node/section_node_entity.dart'; |
| 21 | +import 'package:onix_flutter_bricks/domain/entity/figma/nodes/shape_with_text_node/shape_with_text_node_entity.dart'; |
| 22 | +import 'package:onix_flutter_bricks/domain/entity/figma/nodes/sticky_node/sticky_node_entity.dart'; |
| 23 | +import 'package:onix_flutter_bricks/domain/entity/figma/nodes/table_cell_node/table_cell_node_entity.dart'; |
| 24 | +import 'package:onix_flutter_bricks/domain/entity/figma/nodes/text_node/text_node_entity.dart'; |
| 25 | +import 'package:onix_flutter_bricks/domain/entity/figma/nodes/vector_node/vector_node_entity.dart'; |
| 26 | +import 'package:onix_flutter_bricks/domain/entity/figma/properties/paint_property/paint_property.dart'; |
| 27 | + |
| 28 | +class FigmaNodesMapper { |
| 29 | + List<BaseNode> mapNodesDataModelToEntity(List<NodeDataModel> from) => |
| 30 | + _MapNodeDataModelToEntity().mapIterable(from).toList(); |
| 31 | +} |
| 32 | + |
| 33 | +class _MapNodeDataModelToEntity |
| 34 | + extends MapperIterable<NodeDataModel, BaseNode> { |
| 35 | + @override |
| 36 | + BaseNode map(NodeDataModel from) { |
| 37 | + switch (from) { |
| 38 | + case (DocumentNodeDataModel _): |
| 39 | + return DocumentNodeEntity( |
| 40 | + id: from.id ?? '', |
| 41 | + key: from.key ?? '', |
| 42 | + name: from.name ?? '', |
| 43 | + type: from.type ?? '', |
| 44 | + // (Ivan Modlo): Maybe we should call the map method recursively |
| 45 | + children: from.children |
| 46 | + ?.map( |
| 47 | + (e) => BaseNodeEntity( |
| 48 | + id: e?.id ?? '', |
| 49 | + key: e?.key ?? '', |
| 50 | + name: e?.name ?? '', |
| 51 | + type: e?.type ?? '', |
| 52 | + ), |
| 53 | + ) |
| 54 | + .toList() ?? |
| 55 | + [], |
| 56 | + ); |
| 57 | + case TextNodeDataModel _: |
| 58 | + return TextNodeEntity( |
| 59 | + id: from.id ?? '', |
| 60 | + key: from.key ?? '', |
| 61 | + name: from.name ?? '', |
| 62 | + type: from.type ?? '', |
| 63 | + fills: _mapPaintProperty(from.fills), |
| 64 | + style: PropertyMapper().mapFigmaTypeStyleDataModelToEntity( |
| 65 | + from.style ?? |
| 66 | + const FigmaTypeStyle( |
| 67 | + fontFamily: '', |
| 68 | + fontWeight: 0, |
| 69 | + fontSize: 0, |
| 70 | + letterSpacing: 0, |
| 71 | + ), |
| 72 | + ), |
| 73 | + ); |
| 74 | + case FrameNodeDataModel _: |
| 75 | + return FrameNodeEntity( |
| 76 | + id: from.id ?? '', |
| 77 | + key: from.key ?? '', |
| 78 | + name: from.name ?? '', |
| 79 | + type: from.type ?? '', |
| 80 | + fills: _mapPaintProperty(from.fills), |
| 81 | + ); |
| 82 | + case SectionNodeDataModel _: |
| 83 | + return SectionNodeEntity( |
| 84 | + id: from.id ?? '', |
| 85 | + key: from.key ?? '', |
| 86 | + name: from.name ?? '', |
| 87 | + type: from.type ?? '', |
| 88 | + fills: _mapPaintProperty(from.fills), |
| 89 | + ); |
| 90 | + case VectorNodeDataModel _: |
| 91 | + return VectorNodeEntity( |
| 92 | + id: from.id ?? '', |
| 93 | + key: from.key ?? '', |
| 94 | + name: from.name ?? '', |
| 95 | + type: from.type ?? '', |
| 96 | + fills: _mapPaintProperty(from.fills), |
| 97 | + ); |
| 98 | + case TableCellNodeDataModel _: |
| 99 | + return TableCellNodeEntity( |
| 100 | + id: from.id ?? '', |
| 101 | + key: from.key ?? '', |
| 102 | + name: from.name ?? '', |
| 103 | + type: from.type ?? '', |
| 104 | + fills: _mapPaintProperty(from.fills), |
| 105 | + ); |
| 106 | + |
| 107 | + case StickyNodeDataModel _: |
| 108 | + return StickyNodeEntity( |
| 109 | + id: from.id ?? '', |
| 110 | + key: from.key ?? '', |
| 111 | + name: from.name ?? '', |
| 112 | + type: from.type ?? '', |
| 113 | + fills: _mapPaintProperty(from.fills), |
| 114 | + ); |
| 115 | + |
| 116 | + case ShapeWithTextNodeDataModel _: |
| 117 | + return ShapeWithTextNodeEntity( |
| 118 | + id: from.id ?? '', |
| 119 | + key: from.key ?? '', |
| 120 | + name: from.name ?? '', |
| 121 | + type: from.type ?? '', |
| 122 | + fills: _mapPaintProperty(from.fills), |
| 123 | + ); |
| 124 | + case ConnectorNodeDataModel _: |
| 125 | + return ConnectorNodeEntity( |
| 126 | + id: from.id ?? '', |
| 127 | + key: from.key ?? '', |
| 128 | + name: from.name ?? '', |
| 129 | + type: from.type ?? '', |
| 130 | + fills: _mapPaintProperty(from.fills), |
| 131 | + ); |
| 132 | + default: |
| 133 | + return BaseNodeEntity( |
| 134 | + id: from.id ?? '', |
| 135 | + key: from.key ?? '', |
| 136 | + name: from.name ?? '', |
| 137 | + type: from.type ?? '', |
| 138 | + ); |
| 139 | + } |
| 140 | + } |
| 141 | + |
| 142 | + List<PaintProperty> _mapPaintProperty(List<PaintPropertyDataModel>? from) => |
| 143 | + PropertyMapper().mapPaintPropertyDataModelToEntity(from ?? []).toList(); |
| 144 | +} |
0 commit comments