Skip to content

Commit 750ae7f

Browse files
committed
codelessly_api 5.0.0: upstream JSON codegen, Flutter 3.47 parity (#34)
Move off the forked JSON codegen to json_annotation/json_serializable with a small defaults builder that keeps stored JSON unchanged; mirror current Flutter widget parameters and enums; default new nodes to Material 3 while legacy JSON keeps its look; fix uninitialized nodes, lossy copyWith and incomplete equality; register PlaceholderNode; add CI and tests.
1 parent 8cb8bdb commit 750ae7f

209 files changed

Lines changed: 18821 additions & 14948 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/ci.yml‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
jobs:
9+
check:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v7
13+
- uses: dart-lang/setup-dart@v1
14+
with:
15+
sdk: 3.13.5
16+
- run: dart pub get
17+
- run: dart pub get --directory tool/json_defaults_builder
18+
- name: Generated code is up to date
19+
run: |
20+
dart run build_runner build -d
21+
git diff --exit-code -- '*.g.dart'
22+
- run: dart format --set-exit-if-changed --output=none lib test tool
23+
- run: dart analyze --fatal-infos
24+
- run: dart test
25+
- run: dart pub publish --dry-run

‎.pubignore‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
tool/
2+
# Miscellaneous
3+
*.class
4+
*.log
5+
*.pyc
6+
*.swp
7+
.DS_Store
8+
.atom/
9+
.buildlog/
10+
.history
11+
.svn/
12+
13+
# IntelliJ related
14+
*.iml
15+
*.ipr
16+
*.iws
17+
.idea/
18+
19+
# The .vscode folder contains launch configuration and tasks you configure in
20+
# VS Code which you may wish to be included in version control, so this line
21+
# is commented out by default.
22+
#.vscode/
23+
24+
# Flutter/Dart/Pub related
25+
**/doc/api/
26+
.dart_tool/
27+
.flutter-plugins
28+
.flutter-plugins-dependencies
29+
.packages
30+
.pub-cache/
31+
.pub/
32+
build/
33+
34+
# Android related
35+
**/android/**/gradle-wrapper.jar
36+
**/android/.gradle
37+
**/android/captures/
38+
**/android/gradlew
39+
**/android/gradlew.bat
40+
**/android/local.properties
41+
**/android/**/GeneratedPluginRegistrant.java
42+
43+
# iOS/XCode related
44+
**/ios/**/*.mode1v3
45+
**/ios/**/*.mode2v3
46+
**/ios/**/*.moved-aside
47+
**/ios/**/*.pbxuser
48+
**/ios/**/*.perspectivev3
49+
**/ios/**/*sync/
50+
**/ios/**/.sconsign.dblite
51+
**/ios/**/.tags*
52+
**/ios/**/.vagrant/
53+
**/ios/**/DerivedData/
54+
**/ios/**/Icon?
55+
**/ios/**/Pods/
56+
**/ios/**/.symlinks/
57+
**/ios/**/profile
58+
**/ios/**/xcuserdata
59+
**/ios/.generated/
60+
**/ios/Flutter/App.framework
61+
**/ios/Flutter/Flutter.framework
62+
**/ios/Flutter/Flutter.podspec
63+
**/ios/Flutter/Generated.xcconfig
64+
**/ios/Flutter/app.flx
65+
**/ios/Flutter/app.zip
66+
**/ios/Flutter/flutter_assets/
67+
**/ios/Flutter/flutter_export_environment.sh
68+
**/ios/ServiceDefinitions.json
69+
**/ios/Runner/GeneratedPluginRegistrant.*
70+
71+
# Exceptions to above rules.
72+
!**/ios/**/default.mode1v3
73+
!**/ios/**/default.mode2v3
74+
!**/ios/**/default.pbxuser
75+
!**/ios/**/default.perspectivev3
76+
77+
pubspec.lock
78+
pubspec_overrides.yaml

‎CHANGELOG.md‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,84 @@
1+
## 5.0.0
2+
3+
### Breaking changes
4+
5+
- Require Dart 3.13.
6+
- Replace the forked `codelessly_json_annotation` and
7+
`codelessly_json_serializable` with the standard `json_annotation` and
8+
`json_serializable`. Custom nodes should import
9+
`package:json_annotation/json_annotation.dart`. `DateTimeConverter` is
10+
now exported by this package.
11+
- Upgrade to equatable 3, which removes `EquatableMixin`; models mix in
12+
`Equatable` instead.
13+
- Remove the unused blend and `value` constructor parameters of
14+
`LoadingIndicatorNode`, `ProgressBarNode` and `DividerNode`, which were
15+
silently discarded.
16+
- Remove the unused `automaticChevron` parameter of
17+
`ExpansionTileProperties.copyWith`.
18+
19+
### JSON
20+
21+
- Serialized JSON is unchanged: fields that equal their defaults are still
22+
omitted, now by a small build step in `tool/json_defaults_builder`.
23+
Golden tests pin the output against 4.4.0.
24+
- Cloud database query `whereFilters`/`orderByFilters` are omitted when
25+
empty; they read back as empty lists.
26+
27+
### Flutter parity
28+
29+
- Mirror new Flutter values: `TextAlignHorizontalEnum.start`/`end`,
30+
`ButtonTypeEnum.filled`/`filledTonal`, `FABLocation.endContained`,
31+
`TextInputTypeEnum.webSearch`/`twitter`,
32+
`AutovalidateModeC.onUnfocus`/`onUserInteractionIfError`,
33+
`SliderTrackShapeEnum.gapped`, `SliderValueIndicatorShape.drop`/
34+
`roundedRectangle` and `CShapeBorder.roundedSuperellipse`.
35+
- Add Flutter parameters that were missing:
36+
- `AppBarProperties.foregroundColor`, `scrolledUnderElevation`
37+
- `TabBarProperties.tabAlignment` (new `TabAlignmentC`), `dividerHeight`
38+
- `RadioProperties.side`, `innerRadius`, `backgroundColor`
39+
- `SliderProperties.showValueIndicator` (new `ShowValueIndicatorC`),
40+
`secondaryTrackValue`, `secondaryActiveTrackColor`, `padding`
41+
- `ListTileProperties.minTileHeight`, `titleAlignment` (new
42+
`ListTileTitleAlignmentC`)
43+
- `MaterialLoadingIndicatorProperties.strokeAlign`, `trackGap`
44+
- `ExpansionTileProperties.showTrailingIcon`, `shape`, `collapsedShape`,
45+
`cornerRadius`
46+
- `TextMixin.softWrap`, `textScaleFactor`
47+
- `MultiSourceIconModel.fill`, `weight`, `grade`, `opticalSize` (the
48+
Material Symbols variable-font axes)
49+
- `PageViewProperties.allowImplicitScrolling`
50+
- Document the Flutter replacements for deprecated `cacheExtent`
51+
(`scrollCacheExtent`) and `Radio.groupValue` (`RadioGroup`).
52+
- New nodes use Material 3 defaults: switches use Material 3, buttons are
53+
stadium-shaped with 24 px horizontal padding, FABs are rounded rectangles
54+
(radius 16) with Material 3 elevations, a 56 px extended height and 8 px
55+
icon spacing, list and expansion tiles use 16/24 px content padding, tab
56+
indicators size to the label, and navigation bars use elevation 3 (M3)
57+
and 8 (M2).
58+
- Designs saved before 5.0.0 keep their look: a missing key still reads as
59+
the old default, and re-saving them writes the same JSON. The new
60+
`JsonLegacyDefault` annotation supports this for non-literal defaults.
61+
62+
### Fixes
63+
64+
- Register `PlaceholderNode` with `NodeJsonConverter`; layouts containing
65+
one failed to deserialize.
66+
- `ListTileNode.empty`/`fromProperties` and `ExpansionTileNode.empty`
67+
no longer leave late fields uninitialized.
68+
- `FloatingActionButtonNode.empty` and `EmbeddedVideoNode.empty` use their
69+
own sizes.
70+
- `copyWith` keeps Divider `thickness`, Dropdown `enabled`/`dense`/
71+
`expanded`/`autoFocus`/`enableFeedback`, FAB `location`, M2 navigation
72+
bar notch settings.
73+
- Remove the `contentPadding` parameter of `InputDecorationModel.copyWith`,
74+
which was ignored; a text field's content padding is its node padding.
75+
- Equality includes previously ignored fields of ExpansionTile, grid
76+
delegates, Dropdown, Divider, FAB, ListTile, TabBar, icons, web views,
77+
submit actions, Vimeo videos, condition groups and visual density.
78+
- `TypedValue.toEdgeInsetsModel` converts numbers and lists again.
79+
- Add field access for `TextFieldProperties` and the navigation bar
80+
properties.
81+
182
## 4.4.0
283

384
- Add CornerRadius typedValue.

‎README.md‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ This is how you can create a custom `BaseNode`:
3535

3636
```dart
3737
import 'package:codelessly_api/codelessly_api.dart';
38-
import 'package:codelessly_json_annotation/codelessly_json_annotation.dart';
38+
import 'package:json_annotation/json_annotation.dart';
3939
4040
part 'custom_node.g.dart';
4141
@@ -44,7 +44,7 @@ class CustomNode extends BaseNode {
4444
@override
4545
final String type = 'custom_node';
4646
47-
MyCoolNode({
47+
CustomNode({
4848
required super.id,
4949
required super.name,
5050
required super.basicBoxLocal,
@@ -57,6 +57,9 @@ class CustomNode extends BaseNode {
5757
}
5858
```
5959

60+
Generate the serialization code with `dart run build_runner build`, using
61+
[json_serializable](https://pub.dev/packages/json_serializable).
62+
6063
All nodes must extend `BaseNode`. Please refer to the documentation inside `BaseNode` for more information.
6164

6265
Then, register your node with the `NodeJsonConverter` so that it can be properly deserialized from json. The
@@ -113,6 +116,22 @@ or image texture.
113116
opacity (`opacity`), among others. Depending on the type of paint, it might have properties like color (`color`),
114117
gradient transform (`gradientTransform`), gradient stops (`gradientStops`), or image transform (`imageTransform`).
115118

119+
### Flutter parity
120+
121+
Models track the Flutter release this version supports (3.47). A Flutter
122+
parameter is left out when it cannot be data or is already expressed
123+
elsewhere:
124+
125+
| Flutter parameter | Represented by |
126+
|---|---|
127+
| Size and padding parameters such as `ButtonStyle.minimumSize`/`fixedSize`, `InputDecoration.contentPadding` and `TabBar.padding` | The node's own box and `padding` |
128+
| `ScrollView.clipBehavior` and similar clip parameters | `ClipMixin.clipsContent` |
129+
| Callbacks and widgets, such as `itemExtentBuilder` and `prototypeItem` | Not representable as JSON; use `itemExtent` |
130+
131+
Defaults follow Material 3. Where a default changed from an earlier
132+
version, the old value still applies to JSON that omits the key (see
133+
`JsonLegacyDefault`), so saved designs keep their look.
134+
116135
## Contributing
117136

118137
Contributions are welcome! Please open an issue to start a discussion.

‎analysis_options.yaml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ analyzer:
88
missing_required_param: error
99
missing_return: error
1010
todo: ignore
11+
# Nodes and their properties are mutable by design: the editor updates
12+
# them in place. Equatable 3 marks itself @immutable, which would flag
13+
# every one of them.
14+
must_be_immutable: ignore
1115

1216
linter:
1317
rules:

‎build.yaml‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
targets:
22
$default:
33
builders:
4-
codelessly_json_serializable:
4+
json_serializable:
55
options:
6-
# The other properties are the same as default (https://pub.dev/packages/json_serializable#build-configuration).
7-
# explicit_to_json must be true for nested properties to work (like a Paint inside a Frame, toJson must be called in both)
6+
# explicit_to_json must be true for nested models (like a Paint inside a Frame) to serialize.
87
explicit_to_json: true
9-
# include_if_null should be false to avoid sending null properties to Firebase.
8+
# Null values are not written, to avoid sending null properties to Firebase.
109
include_if_null: false
11-
any_map: true # The squadron library for web requires dynamic maps.
12-
serialize_default_values: false
10+
# The squadron library for web requires dynamic maps.
11+
any_map: true

‎example/example.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
```dart
44
import 'package:codelessly_api/codelessly_api.dart';
5-
import 'package:codelessly_json_annotation/codelessly_json_annotation.dart';
5+
import 'package:json_annotation/json_annotation.dart';
66
77
part 'custom_node.g.dart';
88

‎lib/codelessly_api.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export 'src/api/converters.dart';
99
export 'src/api/extensions.dart';
1010
export 'src/api/field_access.dart';
1111
export 'src/api/generate_id.dart';
12+
export 'src/api/json_defaults.dart';
1213
export 'src/api/math_helper.dart';
1314
export 'src/api/mixins.dart';
1415
export 'src/api/models/models.dart';

0 commit comments

Comments
 (0)