Skip to content

Commit a7dc1ea

Browse files
committed
Update ReadMe 20230619
1 parent b2ff90f commit a7dc1ea

File tree

1 file changed

+68
-43
lines changed

1 file changed

+68
-43
lines changed

README.md

Lines changed: 68 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,104 @@
1-
## Codelessly API
1+
# Codelessly API
22

3-
This package provides a set of APIs for creating "Nodes" in Codelessly,
4-
a design-to-code tool that helps users import designs from Figma and convert
5-
them into working apps and websites. With these APIs, you can programmatically
6-
create your own nodes.
3+
> Flutter's layouts and widgets represented as models and JSON data.
74
8-
## Features
5+
This package is used by the Codelessly Editor and CloudUI SDK to render Flutter Widgets. These APIs enable developers to interact with and manipulate user interfaces in a structured manner. It can be used to define components, layouts, interactions, and styles, among other things, programmatically.
96

10-
This package contains tools to extend the default Codelessly api to create custom
11-
`BaseNode`s only. If you wish to create and register your nodes, along with their
12-
respective transformers to convert your custom `BaseNode`s into Flutter widgets
13-
you will need to use the `codelessly_sdk` package.
7+
This is a lower-level package for constructing an abstract, universal data representation of UI. If you're looking for the developer SDK, use the [Codelessly Cloud UI SDK](https://pub.dev/packages/codelessly_sdk).
148

15-
This package is built with pure Dart, not relying on Flutter.
16-
It is meant specifically for defining `BaseNode`s and nothing else, as it does not
17-
contain any tools for converting Nodes into Flutter widgets or for interacting
18-
with the Codelessly editor. It is intended to be used in conjunction with
19-
the `codelessly_sdk` package for those purposes.
9+
## About
2010

21-
In light of that, and to enable complete serialization of all nodes, this package
22-
contains a custom set of base classes that mirror Flutter's own models. Some of those
23-
include `Vec`, `RectC`, `SizeC`, `AlignC`, as well as most properties you would find
24-
in a given Flutter widget.
11+
> User Interfaces (UI) as data.
2512
26-
Classes that mirror Flutter tend to be suffixed with a `C` for `Codelessly` or `Model` to
27-
differentiate them from their Flutter counterparts like `AlignmentModel`
13+
This lower-level package establishes a foundation for an abstract, universally interpretable data representation of UI. The API is language-agnostic, written in pure Dart with no Flutter dependencies.
14+
15+
This universal approach allows for broad, diverse applications across different programming languages. The result is a library that supports the construction of complex UI structures, regardless of the programming language or development environment.
16+
17+
For example, we've translated this library to Javascript and Typescript and created a prototype SDK for building native web UIs. We were able to deploy the same UI to Flutter and HTML simultaneously.
18+
19+
Our goal is to continuously build a set of fundamental UI constructs that can express UI in HTML, SwiftUI, Android Compose, and eventually AI.
2820

29-
## Usage
21+
## Quick Start
3022

31-
Here is a minimal example of how to use this package to create a custom `BaseNode`:
23+
This package contains tools to create custom `BaseNodes`. To convert a custom `BaseNode` into UI, see the language specific Flutter implementation in the [Codelessly Cloud UI SDK](https://pub.dev/packages/codelessly_sdk) package.
3224

33-
Please read the code inside `BaseNode` to better understand what each property does, and
34-
refer to one of the many nodes under `codelessly_api/lib/api/nodes` for additional
35-
examples.
25+
This is how you can create a custom `BaseNode`:
3626

3727
```dart
3828
import 'package:codelessly_api/codelessly_api.dart';
3929
import 'package:json_annotation/json_annotation.dart';
4030
41-
part 'my_cool_node.g.dart';
31+
part 'custom_node.g.dart';
4232
43-
/// At it's core, this is the most basic example of how to create a complete
44-
/// [BaseNode].
4533
@JsonSerializable()
46-
class MyCoolNode extends BaseNode {
34+
class CustomNode extends BaseNode {
4735
@override
48-
final String type = 'my_cool_node';
36+
final String type = 'custom_node';
4937
5038
MyCoolNode({
5139
required super.id,
5240
required super.name,
5341
required super.basicBoxLocal,
5442
});
5543
56-
factory MyCoolNode.fromJson(Map json) => _$MyCoolNodeFromJson(json);
44+
factory CustomNode.fromJson(Map json) => _$CustomNodeFromJson(json);
5745
5846
@override
59-
Map toJson() => _$MyCoolNodeToJson(this);
47+
Map toJson() => _$CustomNodeToJson(this);
6048
}
6149
```
6250

63-
Make sure to register your node with the `NodeJsonConverter` so that it can be
64-
properly deserialized from json. The NodeJsonConverter will deserialize any
65-
registered nodes into their proper types.
51+
All nodes must extend `BaseNode`. Please refer to the documentation inside `BaseNode` for more information.
52+
53+
Then, register your node with the `NodeJsonConverter` so that it can be properly deserialized from json. The NodeJsonConverter will deserialize any registered nodes into their proper types.
6654

6755
```
68-
NodeJsonConverter.registerNode('my_cool_node', MyCoolNode.fromJson);
56+
NodeJsonConverter.registerNode('custom_node', CustomNode.fromJson);
6957
```
7058

71-
## Additional information
59+
For more examples, see [`codelessly_api/lib/api/nodes`](https://github.com/Codelessly/CodelesslyAPI/tree/main/lib/src/api/nodes)
60+
61+
## Key Concepts
62+
63+
### Base Classes
64+
65+
The base classes provided by the CodelesslyAPI include `Vec`, `RectC`, `SizeC`, `AlignC`, and others. They mirror Flutter's own models and offer functionalities that represent essential building blocks for Flutter widgets.
66+
67+
These classes encapsulate key properties and behaviors needed for vector representations (`Vec`), rectangular shapes (`RectC`), sizes (`SizeC`), and alignment specifications (`AlignC`). Each class is equipped with serialization and deserialization capabilities, allowing them to be conveniently converted to and from JSON format. These classes collectively provide a foundation for defining and manipulating UI elements in Flutter applications.
68+
69+
Classes that mirror Flutter tend to be suffixed with a `C` for `Codelessly` or `Model` to
70+
differentiate them from their Flutter counterparts like `RectC`.
71+
72+
- **Vec**: This class represents a two-dimensional vector with x and y coordinates.
73+
- **RectC**: This class represents a rectangle with a top-left position and a size. The position is represented as a `Vec` object, while the size is represented as a `SizeC` object.
74+
75+
### Components
76+
77+
Components represent the building blocks of the user interface. They can be anything from a single button to a complex form or even an entire webpage.
78+
79+
- `ComponentModel`: A single component that holds properties of the component (`type`), its unique identifier (`id`), and actions associated with it (`action`).
80+
81+
### Actions
82+
83+
Actions define what should happen when a user interacts with a component in a certain way (for example, clicking a button or submitting a form).
84+
85+
- `ActionModel`: Holds information about an action to perform on a user interaction. It defines the type of the action (`type`), which can be things like navigating to a page, opening a link, submitting a form, etc.
86+
87+
### Paint
88+
89+
The `PaintModel` is used to define styles that can be applied to components. It can represent a solid color, gradient, or image texture.
90+
91+
- `PaintModel`: Defines the style properties such as the type of paint (`type`), its visibility (`visible`), and its opacity (`opacity`), among others. Depending on the type of paint, it might have properties like color (`color`), gradient transform (`gradientTransform`), gradient stops (`gradientStops`), or image transform (`imageTransform`).
92+
93+
## Contributing
94+
95+
Contributions are welcome! Please open an issue to start a discussion.
96+
97+
## Acknowledgments
98+
99+
Special thanks to the Flutter community for providing the inspiration and foundation for this project.
72100

73-
If you have any questions or run into any issues, you can file a support ticket through the Codelessly website or
74-
contact the Codelessly team directly. We welcome contributions to this package and encourage you to submit any issues or
75-
pull requests through the
76-
GitHub repository.
101+
## Contact Us
77102

78-
You can contact us on our [Website](https://codelessly.com/) or join us on
103+
You can contact us on our [website](https://codelessly.com/) or join us on
79104
our [Discord Server](https://discord.gg/Bzaz7zmY6q).

0 commit comments

Comments
 (0)