diff --git a/README.md b/README.md index 8d9afbe0..dee5ebc9 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/SketchAssetConverter b/SketchAssetConverter index 8e424654..1b5effbd 160000 --- a/SketchAssetConverter +++ b/SketchAssetConverter @@ -1 +1 @@ -Subproject commit 8e424654c1228ffd3a767a9c36555840a4583e09 +Subproject commit 1b5effbd220ff03015bc4b288184005e4443f056 diff --git a/lib/controllers/main_info.dart b/lib/controllers/main_info.dart index 1c6cc4cf..6c0796c2 100644 --- a/lib/controllers/main_info.dart +++ b/lib/controllers/main_info.dart @@ -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', diff --git a/lib/generation/flutter_project_builder/flutter_project_builder.dart b/lib/generation/flutter_project_builder/flutter_project_builder.dart index 660d7b9c..2aeb7dcd 100644 --- a/lib/generation/flutter_project_builder/flutter_project_builder.dart +++ b/lib/generation/flutter_project_builder/flutter_project_builder.dart @@ -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) { diff --git a/lib/generation/generators/symbols/pb_instancesym_gen.dart b/lib/generation/generators/symbols/pb_instancesym_gen.dart index 4c7a7693..7f0999e1 100644 --- a/lib/generation/generators/symbols/pb_instancesym_gen.dart +++ b/lib/generation/generators/symbols/pb_instancesym_gen.dart @@ -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'; @@ -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) { @@ -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}\",'); @@ -66,4 +69,41 @@ class PBSymbolInstanceGenerator extends PBGenerator { return buffer.toString(); } } + + String genSymbolInstance(String overrideUUID, String UUID, + List 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(); + } } diff --git a/lib/generation/generators/symbols/pb_mastersym_gen.dart b/lib/generation/generators/symbols/pb_mastersym_gen.dart index ef180823..95c045ae 100644 --- a/lib/generation/generators/symbols/pb_mastersym_gen.dart +++ b/lib/generation/generators/symbols/pb_mastersym_gen.dart @@ -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) { diff --git a/lib/generation/generators/value_objects/template_strategy/stateless_template_strategy.dart b/lib/generation/generators/value_objects/template_strategy/stateless_template_strategy.dart index 7b08f8d3..6e39d7cc 100644 --- a/lib/generation/generators/value_objects/template_strategy/stateless_template_strategy.dart +++ b/lib/generation/generators/value_objects/template_strategy/stateless_template_strategy.dart @@ -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 diff --git a/lib/input/sketch/entities/layers/symbol_master.dart b/lib/input/sketch/entities/layers/symbol_master.dart index 3369abb2..8ae80423 100644 --- a/lib/input/sketch/entities/layers/symbol_master.dart +++ b/lib/input/sketch/entities/layers/symbol_master.dart @@ -260,4 +260,5 @@ class SymbolMaster extends AbstractGroupLayer // TODO: implement fromPBDF throw UnimplementedError(); } + } diff --git a/lib/input/sketch/helper/symbol_node_mixin.dart b/lib/input/sketch/helper/symbol_node_mixin.dart index 60e47f48..0b341919 100644 --- a/lib/input/sketch/helper/symbol_node_mixin.dart +++ b/lib/input/sketch/helper/symbol_node_mixin.dart @@ -17,7 +17,7 @@ mixin SymbolNodeMixin { String: 'str', Style: 'sty', InheritedBitmap: 'bm', - PBSharedParameterValue: 'sv', + PBSharedInstanceIntermediateNode: 'sv', }; // should have been a Map but iterate slowly through the list @@ -81,7 +81,7 @@ mixin SymbolNodeMixin { type = String; break; case 'symbolID': - type = PBSharedParameterValue; + type = PBSharedInstanceIntermediateNode; break; case 'image': type = InheritedBitmap; diff --git a/lib/interpret_and_optimize/entities/pb_shared_master_node.dart b/lib/interpret_and_optimize/entities/pb_shared_master_node.dart index 6bbc15e3..8cc1e2e0 100644 --- a/lib/interpret_and_optimize/entities/pb_shared_master_node.dart +++ b/lib/interpret_and_optimize/entities/pb_shared_master_node.dart @@ -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'; @@ -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; @@ -39,6 +45,8 @@ class PBSharedMasterNode extends PBVisualIntermediateNode List overridableProperties; + String friendlyName; + PBSharedMasterNode( this.originalRef, this.SYMBOL_ID, @@ -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); } diff --git a/lib/interpret_and_optimize/helpers/pb_symbol_storage.dart b/lib/interpret_and_optimize/helpers/pb_symbol_storage.dart index 5379d6a5..b2418b7e 100644 --- a/lib/interpret_and_optimize/helpers/pb_symbol_storage.dart +++ b/lib/interpret_and_optimize/helpers/pb_symbol_storage.dart @@ -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 addSharedMasterNode(PBSharedMasterNode masterNode) async { if (_pbSharedMasterNodes.containsKey(masterNode.UUID)) { @@ -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]; } diff --git a/lib/interpret_and_optimize/services/pb_shared_aggregation_service.dart b/lib/interpret_and_optimize/services/pb_shared_aggregation_service.dart index b101457e..1e32ae66 100644 --- a/lib/interpret_and_optimize/services/pb_shared_aggregation_service.dart +++ b/lib/interpret_and_optimize/services/pb_shared_aggregation_service.dart @@ -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 _unregSymQueue; Iterable get unregSymQueue => @@ -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) { diff --git a/lib/interpret_and_optimize/services/pb_symbol_linker_service.dart b/lib/interpret_and_optimize/services/pb_symbol_linker_service.dart index 497da1ed..2adee0ca 100644 --- a/lib/interpret_and_optimize/services/pb_symbol_linker_service.dart +++ b/lib/interpret_and_optimize/services/pb_symbol_linker_service.dart @@ -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 linkSymbols(PBIntermediateNode rootNode) async{ if(rootNode == null){ diff --git a/lib/main.dart b/lib/main.dart index 821841b1..09aa2aa6 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -58,7 +58,9 @@ void main(List 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) { @@ -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']; diff --git a/parabeac.dart b/parabeac.dart index 8141de4f..0c9043a8 100644 --- a/parabeac.dart +++ b/parabeac.dart @@ -37,7 +37,9 @@ main(List 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); diff --git a/pubspec.yaml b/pubspec.yaml index 67648461..1e3e036f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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" diff --git a/test/assets/SymbolTest-simp.sketch b/test/assets/SymbolTest-simp.sketch index 637e1760..e635621c 100644 Binary files a/test/assets/SymbolTest-simp.sketch and b/test/assets/SymbolTest-simp.sketch differ