Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@

### Fixes

- Placeholders (variances, lists, grids, pages) read JSON that leaves out
empty `allowedTypes` or `deniedTypes`, as JSON written before this
release could.
- `SpacerNode.fromJson` defaults `positioningMode` (align),
`aspectRatioLock` (false) and `reactions` ([]) like every other node, and
`GridViewNode.fromJson` defaults `isScrollable` (true) and
Expand Down
4 changes: 2 additions & 2 deletions lib/src/api/nodes/grid_view_node.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/src/api/nodes/list_view_node.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/src/api/nodes/page_view_node.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions lib/src/api/nodes/single_placeholder_node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ class SinglePlaceholderNode extends SceneNode
/// The node types that are allowed to be inside this [SinglePlaceholderNode].
/// Example: 'APP_BAR' for AppBarNode.
/// When empty, allow all types.
@JsonKey(readValue: readTypesOrEmpty)
List<String> allowedTypes;

/// The node types that are not allowed to be inside this
/// [SinglePlaceholderNode].
/// Example: "TEXT" for TextNode.
/// When empty, allow all types.
@JsonKey(readValue: readTypesOrEmpty)
List<String> deniedTypes;

/// If not null, this [SinglePlaceholderNode] will only accept nodes that do
Expand Down Expand Up @@ -89,3 +91,7 @@ class SinglePlaceholderNode extends SceneNode
_$SinglePlaceholderNodeToJson(this),
);
}

/// Reads [allowedTypes] or [deniedTypes] from [json], an empty list when the
/// key is missing: JSON that leaves empty lists out still reads.
Object? readTypesOrEmpty(Map json, String key) => json[key] ?? const <String>[];
4 changes: 2 additions & 2 deletions lib/src/api/nodes/single_placeholder_node.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/src/api/nodes/variance_node.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions test/placeholder_types_missing_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'package:codelessly_api/codelessly_api.dart';
import 'package:test/test.dart';

void main() {
test('placeholders read JSON that leaves out empty type lists', () {
for (final String type in ['variance', 'listView', 'gridView']) {
final Map<String, dynamic> json = {
'type': type,
'id': 'x',
'name': 'n',
'basicBoxLocal': [0, 0, 100, 100],
'children': <String>[],
'properties': <String, dynamic>{},
if (type == 'variance') ...{
'variants': [
{'id': 'default', 'name': 'Default', 'children': <String>[]},
],
'currentVariantId': 'default',
},
if (type == 'gridView')
'properties': {
'gridDelegate': {
'type': 'fixedCrossAxisCount',
'crossAxisCount': 2,
},
},
};
json.remove('allowedTypes');
json.remove('deniedTypes');
final node = NodeJsonConverter().fromJson(json) as SinglePlaceholderNode;
expect(node.allowedTypes, isEmpty, reason: type);
// A list keeps its own default; a variance reads it as empty.
if (type == 'variance') expect(node.deniedTypes, isEmpty);
if (type == 'listView') expect(node.deniedTypes, ['listView']);
}
});
}
Loading