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 #416 from Parabeac/release/1.4.6
Browse files Browse the repository at this point in the history
Release/1.4.6
  • Loading branch information
mergify[bot] committed May 7, 2021
2 parents 1e427b8 + 360fa1f commit 3905e1c
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,23 @@ class FlutterProjectBuilder {
if (mainTree.sharedStyles != null &&
mainTree.sharedStyles.isNotEmpty &&
MainInfo().exportStyles) {
await Directory('${pathToFlutterProject}lib/document/')
.create(recursive: true)
.then((value) {
try {
Directory('${pathToFlutterProject}lib/document/')
.createSync(recursive: true);
var s = File('${pathToFlutterProject}lib/document/shared_props.g.dart')
.openWrite(mode: FileMode.write, encoding: utf8);

s.write('''import 'dart:ui';
import 'package:flutter/material.dart';
''');
for (var sharedStyle in mainTree.sharedStyles) {
s.write(sharedStyle.generate() + '\n');
}
s.close();
}).catchError((e) {
await s.close();
} catch (e) {
log.error(e.toString());
});
}
}
await Future.wait(PBStateManagementLinker().stateQueue, eagerError: true);
await generationConfiguration.generateProject(mainTree);
Expand Down
34 changes: 29 additions & 5 deletions lib/generation/generators/symbols/pb_instancesym_gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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/pb_shared_master_node.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';
Expand Down Expand Up @@ -49,16 +50,19 @@ class PBSymbolInstanceGenerator extends PBGenerator {
for (var param in source.sharedParamValues ?? []) {
switch (param.type) {
case PBSharedInstanceIntermediateNode:
buffer.write('${param.name}: ');
buffer.write(genSymbolInstance(
param.UUID, param.value, source.overrideValues));
String siString = genSymbolInstance(
param.UUID, param.value, source.overrideValues);
if (siString != '') {
buffer.write('${param.name}: ');
buffer.write(siString);
}
break;
case InheritedBitmap:
buffer.write('${param.name}: \"assets/${param.value["_ref"]}\",');
break;
case TextStyle:
// hack to include import
source.generator.manager.data.addImport(
source.currentContext.treeRoot.data.addImport(
'package:${MainInfo().projectName}/document/shared_props.g.dart');
buffer.write(
'${param.name}: ${SharedStyle_UUIDToName[param.value] ?? "TextStyle()"},');
Expand All @@ -82,7 +86,27 @@ class PBSymbolInstanceGenerator extends PBGenerator {
String genSymbolInstance(String overrideUUID, String UUID,
List<PBSymbolInstanceOverridableValue> overrideValues,
{int depth = 1}) {
var masterSymbol = PBSymbolStorage().getSharedMasterNodeBySymbolID(UUID);
if ((UUID == null) || (UUID == '')) {
return '';
}

var masterSymbol;
var nodeFound = PBSymbolStorage().getAllSymbolById(UUID);
if (nodeFound is PBSharedMasterNode) {
masterSymbol = nodeFound;
} else if (nodeFound is PBSharedInstanceIntermediateNode) {
// If storage found an instance, get its master
masterSymbol =
PBSymbolStorage().getSharedMasterNodeBySymbolID(nodeFound.SYMBOL_ID);
} else {
// Try to find master by looking for the master's SYMBOL_ID
masterSymbol = PBSymbolStorage().getSharedMasterNodeBySymbolID(UUID);
}
// file could have override names that don't exist? That's really odd, but we have a file that does that.
if (masterSymbol == null) {
return '';
}

assert(masterSymbol != null,
'Could not find master symbol with UUID: ${UUID}');
var buffer = StringBuffer();
Expand Down
4 changes: 2 additions & 2 deletions lib/generation/generators/util/pb_input_formatter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class PBInputFormatter {
var result = input;
// TODO: set a temporal name
result = (result.isEmpty) ? 'tempName' : result;
result = _removeFirstDigits(result);
result = removeFirstDigits(result);
result = result.trim();
var spaceChar = (spaceToUnderscore) ? '_' : '';
result = result.replaceAll(r'[\s\./_+?]+', spaceChar);
Expand All @@ -43,7 +43,7 @@ class PBInputFormatter {
return result;
}

static String _removeFirstDigits(String str) =>
static String removeFirstDigits(String str) =>
str.startsWith(RegExp(r'^[\d]+'))
? str.replaceFirstMapped(RegExp(r'^[\d]+'), (e) => '')
: str;
Expand Down
9 changes: 5 additions & 4 deletions lib/input/sketch/entities/layers/symbol_master.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:parabeac_core/design_logic/design_node.dart';
import 'package:parabeac_core/design_logic/pb_shared_instance_design_node.dart';
import 'package:parabeac_core/generation/generators/util/pb_input_formatter.dart';
import 'package:parabeac_core/input/sketch/entities/abstract_sketch_node_factory.dart';
import 'package:parabeac_core/input/sketch/entities/layers/abstract_group_layer.dart';
import 'package:parabeac_core/input/sketch/entities/layers/abstract_layer.dart';
Expand Down Expand Up @@ -144,9 +145,10 @@ class SymbolMaster extends AbstractGroupLayer
userInfo,
style,
maintainScrollPosition) {
this.name = name?.replaceAll(RegExp(r'[\s_\+]'), '');
// ?.replaceFirst(RegExp(r'^([\d]|_)+'), '');
// someElement/default
if (name != null) {
this.name = name?.replaceAll(RegExp(r'[\s_\+]'), '');
this.name = PBInputFormatter.removeFirstDigits(name);
}
}

@override
Expand Down Expand Up @@ -260,5 +262,4 @@ class SymbolMaster extends AbstractGroupLayer
// TODO: implement fromPBDF
throw UnimplementedError();
}

}
2 changes: 1 addition & 1 deletion lib/input/sketch/entities/style/shared_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SharedStyle with PBColorMixin {
this.name,
this.style,
}) {
name = name.pascalCase;
name = name.camelCase;
SharedStyle_UUIDToName[UUID] = name.replaceAll(RegExp(r'[^A-Za-z0-9_]',), '');
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'package:parabeac_core/interpret_and_optimize/entities/inherited_scaffold.dart';
import 'package:parabeac_core/interpret_and_optimize/entities/interfaces/pb_inherited_intermediate.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/entities/subclasses/pb_layout_intermediate_node.dart';
import 'package:parabeac_core/interpret_and_optimize/entities/subclasses/pb_visual_intermediate_node.dart';
import 'package:parabeac_core/interpret_and_optimize/helpers/pb_symbol_storage.dart';

class PBIntermediateNodeSearcherService {
///Searching for a [PBIntermediateNode] by their unique identifier. If no [PBIntermediateNode] is found
Expand All @@ -27,6 +29,13 @@ class PBIntermediateNodeSearcherService {

if (currentNode is PBInheritedIntermediate && currentNode.UUID == uuid) {
return currentNode;
} else if (currentNode is PBSharedInstanceIntermediateNode) {
// Traverse intermediate node to find UUID
var master = PBSymbolStorage()
.getSharedMasterNodeBySymbolID(currentNode.SYMBOL_ID);
if (master != null) {
stack.add(master);
}
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ import 'package:parabeac_core/interpret_and_optimize/entities/subclasses/pb_inte
import 'package:parabeac_core/interpret_and_optimize/entities/pb_shared_instance.dart';
import 'package:parabeac_core/interpret_and_optimize/helpers/pb_symbol_storage.dart';
import 'package:parabeac_core/interpret_and_optimize/services/intermediate_node_searcher_service.dart';
import 'package:quick_log/quick_log.dart';

class PBSharedInterAggregationService {
PBSymbolStorage _symbolStorage;

var log = Logger('PBSharedInterAggregationService');

static final PBSharedInterAggregationService _singleInstance =
PBSharedInterAggregationService._internal();

///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 =>
_unregSymQueue;

Expand Down Expand Up @@ -43,9 +47,14 @@ class PBSharedInterAggregationService {
void gatherSharedParameters(
PBSharedMasterNode sharedMasterNode, PBIntermediateNode rootChildNode) {
for (var prop in sharedMasterNode.overridableProperties) {
var targetUUID = _findLastOf(prop?.UUID, '/');
prop.value = PBIntermediateNodeSearcherService.searchNodeByUUID(
rootChildNode, prop?.UUID);
if (prop.type == PBSharedInstanceIntermediateNode) {
rootChildNode, targetUUID);
if (prop.value == null) {
// add Designer Warning here, not even sure if this is the designers fault or not
log.warning('UUID: ${targetUUID} not found in searchNodeByUUID');
}
if ((prop.value != null) && (prop.type == PBSharedInstanceIntermediateNode)) {
///if the [PBSharedMasterNode] contains [PBSharedInstanceIntermediateNode] as parameters
///then its going gather the information of its [PBSharedMasterNode].
gatherSharedValues(prop.value);
Expand Down Expand Up @@ -85,7 +94,8 @@ class PBSharedInterAggregationService {
instanceIntermediateNode.sharedParamValues.map((v) {
for (var symParam in masterNode.overridableProperties) {
if (symParam.propertyName == v.overrideName) {
return PBSharedParameterValue(symParam.type, v.value, symParam.UUID, symParam.propertyName);
return PBSharedParameterValue(
symParam.type, v.value, symParam.UUID, symParam.propertyName);
}
}
return null;
Expand All @@ -100,4 +110,13 @@ class PBSharedInterAggregationService {

PBSharedMasterNode _searchMasterNode(String masterUUID) =>
_symbolStorage.getSharedMasterNodeBySymbolID(masterUUID);

/// Method that splits `target` according to `delimeter`
/// and returns the last entry in the list.
String _findLastOf(String target, String delimeter) {
if (target == null || delimeter == null) {
return '';
}
return target.split(delimeter).last;
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: parabeac_core
description: A starting point for Dart libraries or applications.
version: 1.4.5
version: 1.4.6
# homepage: https://www.example.com

environment:
Expand Down
Binary file modified test/assets/SymbolTest-simp.sketch
Binary file not shown.
Binary file added test/assets/Unit Design System.sketch
Binary file not shown.

0 comments on commit 3905e1c

Please sign in to comment.