Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #344 from Parabeac/release/1.4.3
Browse files Browse the repository at this point in the history
Release/1.4.3
  • Loading branch information
mergify[bot] committed Mar 26, 2021
2 parents c3a866b + ec8e5da commit 1d1a276
Show file tree
Hide file tree
Showing 17 changed files with 103 additions and 42 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,6 @@ If we don't support your state management system, you can learn how to easily cr
# How to contribute
Welcome! The best way to contribute to Parabeac is through pull requests, filing issues on Github, writing documentation & helping others in our Discord community. We are an early project, but like many other projects, helping with bugs that others have filed on Stack Overflow is extremely helpful. We recommend filing bugs & feature requests on the Github issue tracker. For more details make sure to check out our [wiki](https://github.com/Parabeac/Parabeac-Core/wiki).

# How to contribute

The success of Parabeac-Core relies on community, and there are many ways to be apart of it.

# Running the exported code
### Requirements
Expand Down
2 changes: 1 addition & 1 deletion SketchAssetConverter
Submodule SketchAssetConverter updated 3 files
+2 −2 package.json
+7 −0 src/index.ts
+3,248 −1,615 yarn.lock
3 changes: 3 additions & 0 deletions lib/controllers/main_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class MainInfo {
/// Project ID on Figma
String figmaProjectID;

/// Boolean that indicates whether a `styles` document is created.
bool exportStyles;

Map defaultConfigs = {
'default': {
'widgetStyle': 'Material',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ class FlutterProjectBuilder {
}

// generate shared Styles if any found
if (mainTree.sharedStyles != null && mainTree.sharedStyles.isNotEmpty) {
if (mainTree.sharedStyles != null &&
mainTree.sharedStyles.isNotEmpty &&
MainInfo().exportStyles) {
await Directory('${pathToFlutterProject}lib/document/')
.create(recursive: true)
.then((value) {
Expand Down
60 changes: 50 additions & 10 deletions lib/generation/generators/symbols/pb_instancesym_gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import 'package:parabeac_core/generation/generators/pb_generator.dart';
import 'package:parabeac_core/generation/generators/util/pb_input_formatter.dart';
import 'package:parabeac_core/input/sketch/entities/style/shared_style.dart';
import 'package:parabeac_core/input/sketch/entities/style/text_style.dart';
import 'package:parabeac_core/input/sketch/helper/symbol_node_mixin.dart';
import 'package:parabeac_core/interpret_and_optimize/entities/inherited_bitmap.dart';
import 'package:parabeac_core/interpret_and_optimize/entities/pb_shared_instance.dart';
import 'package:parabeac_core/interpret_and_optimize/entities/subclasses/pb_intermediate_node.dart';
import 'package:parabeac_core/interpret_and_optimize/helpers/pb_symbol_storage.dart';
import 'package:parabeac_core/interpret_and_optimize/value_objects/pb_symbol_instance_overridable_value.dart';
import 'package:quick_log/quick_log.dart';
import 'package:parabeac_core/controllers/main_info.dart';
import 'package:recase/recase.dart';
Expand All @@ -16,8 +19,8 @@ class PBSymbolInstanceGenerator extends PBGenerator {
var log = Logger('Symbol Instance Generator');

@override
String generate(
PBIntermediateNode source, GeneratorContext generatorContext) {
String generate(PBIntermediateNode source,
GeneratorContext generatorContext) {
if (source is PBSharedInstanceIntermediateNode) {
var method_signature = source.functionCallName;
if (method_signature == null) {
Expand All @@ -36,21 +39,21 @@ class PBSymbolInstanceGenerator extends PBGenerator {
buffer.write('constraints,');
for (var param in source.sharedParamValues ?? []) {
switch (param.type) {
case PBSharedParameterValue:
//PBSharedParameterValue pbspv = param;
//switch (pbpsv.)
// TODO, maybe this points to static instances? Like Styles.g.dart that will be eventually generated,
// but what about prototype links?
case PBSharedInstanceIntermediateNode:
buffer.write('${param.name}: ');
buffer.write(genSymbolInstance(param.UUID, param.value, source.overrideValues));
break;
case InheritedBitmap:
buffer.write('${param.name}: \"assets/${param.value["_ref"]}\",');
break;
case TextStyle:
// hack to include import
// hack to include import
source.generator.manager.data.addImport(
'package:${MainInfo().projectName}/document/shared_props.g.dart');
'package:${MainInfo()
.projectName}/document/shared_props.g.dart');
buffer.write(
'${param.name}: ${SharedStyle_UUIDToName[param.value] ?? "TextStyle()"},');
'${param.name}: ${SharedStyle_UUIDToName[param.value] ??
"TextStyle()"},');
break;
default:
buffer.write('${param.name}: \"${param.value}\",');
Expand All @@ -66,4 +69,41 @@ class PBSymbolInstanceGenerator extends PBGenerator {
return buffer.toString();
}
}

String genSymbolInstance(String overrideUUID, String UUID,
List<PBSymbolInstanceOverridableValue> overrideValues,
{ int depth = 1 }) {
var masterSymbol = PBSymbolStorage().getSharedMasterNodeBySymbolID(UUID);
assert(masterSymbol !=
null, 'Could not find master symbol with UUID: ${UUID}');
var buffer = StringBuffer();
buffer.write('${masterSymbol.friendlyName}(constraints, ');
for (var ovrValue in overrideValues) {
var ovrUUIDStrings = ovrValue.UUID.split('/');
if ((ovrUUIDStrings.length == depth + 1) && (ovrUUIDStrings[depth-1] == overrideUUID)) {
var ovrUUID = ovrUUIDStrings[depth];
switch (ovrValue.type) {
case PBSharedInstanceIntermediateNode:
buffer.write(
genSymbolInstance(ovrValue.value, ovrUUID, overrideValues, depth: depth + 1));
break;
case InheritedBitmap:
var name = SN_UUIDtoVarName[ovrUUID + '_image'];
buffer.write('${name}: \"assets/${ovrValue.value["_ref"]}\",');
break;
case TextStyle:
var name = SN_UUIDtoVarName[ovrUUID + '_textStyle'];
buffer.write('${name}: ${SharedStyle_UUIDToName[ovrValue.value] ??
"TextStyle()"},');
break;
default:
var name = SN_UUIDtoVarName[ovrUUID];
buffer.write('${name}: \"${ovrValue.value}\",');
break;
}
}
}
buffer.write('),');
return buffer.toString();
}
}
18 changes: 2 additions & 16 deletions lib/generation/generators/symbols/pb_mastersym_gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,14 @@ class PBMasterSymbolGenerator extends PBGenerator {
@override
String generate(
PBIntermediateNode source, GeneratorContext generatorContext) {
generatorContext.sizingContext ??= SizingValueContext.LayoutBuilderValue;
generatorContext.sizingContext = SizingValueContext.LayoutBuilderValue;
var buffer = StringBuffer();
if (source is PBSharedMasterNode) {
if (source.child == null) {
return '';
}
var name;
try {
//Remove any special characters and leading numbers from the method name
name = source.name
.replaceAll(RegExp(r'[^\w]+'), '')
.replaceFirst(RegExp(r'^[\d]+'), '');
//Make first letter of method name capitalized
name = name[0].toLowerCase() + name.substring(1);
} catch (e, stackTrace) {
MainInfo().sentry.captureException(
exception: e,
stackTrace: stackTrace,
);
log.error(e.toString());
}
source.child.currentContext = source.currentContext;
// see if widget itself is overridden, need to pass
var generatedWidget =
source.child.generator.generate(source.child, generatorContext);
if (generatedWidget == null || generatedWidget.isEmpty) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ${manager.generateImports()}
class ${widgetName.pascalCase} extends StatelessWidget{
${node is PBSharedMasterNode ? 'final constraints;' : ''}
${overrideVars.isNotEmpty ? overrideVars : ''}
const ${widgetName.pascalCase}(${node is PBSharedMasterNode ? 'this.constraints,' : ''} {Key key, ${overrides.isNotEmpty ? overrides : ''}}) : super(key : key);
${widgetName.pascalCase}(${node is PBSharedMasterNode ? 'this.constraints,' : ''} {Key key, ${overrides.isNotEmpty ? overrides : ''}}) : super(key : key);
${manager.generateGlobalVariables()}
@override
Expand Down
1 change: 1 addition & 0 deletions lib/input/sketch/entities/layers/symbol_master.dart
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,5 @@ class SymbolMaster extends AbstractGroupLayer
// TODO: implement fromPBDF
throw UnimplementedError();
}

}
4 changes: 2 additions & 2 deletions lib/input/sketch/helper/symbol_node_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mixin SymbolNodeMixin {
String: 'str',
Style: 'sty',
InheritedBitmap: 'bm',
PBSharedParameterValue: 'sv',
PBSharedInstanceIntermediateNode: 'sv',
};

// should have been a Map<UUID, SketchNode> but iterate slowly through the list
Expand Down Expand Up @@ -81,7 +81,7 @@ mixin SymbolNodeMixin {
type = String;
break;
case 'symbolID':
type = PBSharedParameterValue;
type = PBSharedInstanceIntermediateNode;
break;
case 'image':
type = InheritedBitmap;
Expand Down
26 changes: 26 additions & 0 deletions lib/interpret_and_optimize/entities/pb_shared_master_node.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:parabeac_core/controllers/main_info.dart';
import 'package:parabeac_core/design_logic/design_node.dart';
import 'package:parabeac_core/generation/generators/symbols/pb_mastersym_gen.dart';
import 'package:parabeac_core/generation/prototyping/pb_prototype_node.dart';
Expand All @@ -9,9 +10,14 @@ import 'package:parabeac_core/interpret_and_optimize/entities/subclasses/pb_visu
import 'package:parabeac_core/interpret_and_optimize/helpers/pb_context.dart';
import 'package:parabeac_core/interpret_and_optimize/value_objects/pb_symbol_master_params.dart';
import 'package:parabeac_core/interpret_and_optimize/value_objects/point.dart';
import 'package:quick_log/quick_log.dart';

class PBSharedMasterNode extends PBVisualIntermediateNode
implements PBInheritedIntermediate {

///SERVICE
var log = Logger('PBSharedMasterNode');

@override
final originalRef;

Expand Down Expand Up @@ -39,6 +45,8 @@ class PBSharedMasterNode extends PBVisualIntermediateNode
List<PBSharedParameterProp> overridableProperties;

String friendlyName;

PBSharedMasterNode(
this.originalRef,
this.SYMBOL_ID,
Expand All @@ -49,6 +57,24 @@ class PBSharedMasterNode extends PBVisualIntermediateNode
PBContext currentContext,
}) : super(topLeftCorner, bottomRightCorner, currentContext, name,
UUID: originalRef.UUID ?? '') {

try {
//Remove any special characters and leading numbers from the method name
friendlyName = name
.replaceAll(RegExp(r'[^\w]+'), '')
.replaceAll(RegExp(r'/'), '')
.replaceFirst(RegExp(r'^[\d]+'), '');
//Make first letter of method name capitalized
friendlyName = friendlyName[0].toUpperCase() + friendlyName.substring(1);
} catch (e, stackTrace) {
MainInfo().sentry.captureException(
exception: e,
stackTrace: stackTrace,
);
log.error(e.toString());
}
;

if (originalRef is DesignNode && originalRef.prototypeNodeUUID != null) {
prototypeNode = PrototypeNode(originalRef?.prototypeNodeUUID);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/interpret_and_optimize/helpers/pb_symbol_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class PBSymbolStorage {
return true;
}

///Add [PBSharedMasterNode] tointo the storage, return `true` if added else
///Add [PBSharedMasterNode] into the storage, return `true` if added else
///`false` if it exists.
Future<bool> addSharedMasterNode(PBSharedMasterNode masterNode) async {
if (_pbSharedMasterNodes.containsKey(masterNode.UUID)) {
Expand All @@ -53,7 +53,7 @@ class PBSymbolStorage {
return true;
}

///Getting the symbol instace that contains the specific
///Getting the symbol instance that contains the specific
PBIntermediateNode getSymbolInstance(String id) {
return _pbSharedInstanceNodes[id];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class PBSharedInterAggregationService {
static final PBSharedInterAggregationService _singleInstance =
PBSharedInterAggregationService._internal();

///These are [PBSharedInstaceIntermediateNode] that have not found their [PBSharedMasterNode]; they are
///These are [PBSharedInstanceIntermediateNode] that have not found their [PBSharedMasterNode]; they are
///waiting to see their [PBSharedMasterNode] in order to populate their attributes.
List<PBSharedInstanceIntermediateNode> _unregSymQueue;
Iterable<PBSharedInstanceIntermediateNode> get unregSymQueue =>
Expand Down Expand Up @@ -55,7 +55,7 @@ class PBSharedInterAggregationService {
.removeWhere((prop) => prop == null || prop.value == null);
}

///Its going to check the [PBSharedInstanceIntermediateNode]s and the [PBSharedMasterNode]s that are comming through
///Its going to check the [PBSharedInstanceIntermediateNode]s and the [PBSharedMasterNode]s that are coming through
///the [PBSymbolStorage]. To see if we can find the [PBSharedMasterNode] that belongs to the [PBSharedInstanceIntermediateNode]
///that do not have their values solved.
void analyzeSharedNode(dynamic node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class PBSymbolLinkerService {
_aggregationService = PBSharedInterAggregationService();
}

// /Linking [PBSharedMasterNode] and [PBSharedInsstanceIntermediateNode] together; linking its
// /Linking [PBSharedMasterNode] and [PBSharedInstanceIntermediateNode] together; linking its
// /parameter and values.
Future<PBIntermediateNode> linkSymbols(PBIntermediateNode rootNode) async{
if(rootNode == null){
Expand Down
5 changes: 4 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ void main(List<String> args) async {
..addFlag('help',
help: 'Displays this help information.', abbr: 'h', negatable: false)
..addFlag('export-pbdl',
help: 'This flag outputs Parabeac Design Logic (PBDL) in JSON format.');
help: 'This flag outputs Parabeac Design Logic (PBDL) in JSON format.')
..addFlag('include-styles',
help: 'If this flag is set, it will output styles document');

//error handler using logger package
void handleError(String msg) {
Expand Down Expand Up @@ -93,6 +95,7 @@ ${parser.usage}
MainInfo().figmaProjectID = argResults['fig'];

var designType = 'sketch';
MainInfo().exportStyles = argResults['include-styles'];
var jsonOnly = argResults['export-pbdl'];

var configurationPath = argResults['config-path'];
Expand Down
4 changes: 3 additions & 1 deletion parabeac.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ main(List<String> args) async {
)
..addFlag('export-pbdl',
help:
'This flag outputs Parabeac Design Logic (PBDL) in JSON format. This flag is to be used along with Figma or Sketch conversion options.');
'This flag outputs Parabeac Design Logic (PBDL) in JSON format. This flag is to be used along with Figma or Sketch conversion options.')
..addFlag('include-styles',
help: 'If this flag is set, it will output styles document');

argResults = parser.parse(args);

Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: parabeac_core
description: A starting point for Dart libraries or applications.
version: 1.4.2
version: 1.4.3
# homepage: https://www.example.com

environment:
sdk: ">=2.7.0 <3.0.0"
Expand Down
Binary file modified test/assets/SymbolTest-simp.sketch
Binary file not shown.

0 comments on commit 1d1a276

Please sign in to comment.