Proposal: Expressive spec
See original GitHub issueWhat problem does this feature solve?
We already have some issues with improving the spec:
- https://github.com/webzard-io/sunmao-ui/issues/251
- https://github.com/webzard-io/sunmao-ui/issues/211
With a more expressive spec, we can tell more about a component/trait/application to the user or the editor.
What does the proposed API look like?
Component
Metadata
To keep the metadata area clean and maintainable, we will only add one field annotations
to its schema.
The annotations will have a type of JSONSchemaObject
.
{
"name": "Table",
"description": "A Table component",
"annotations": {
"maintainer": "developer@sunmao-ui",
"git": {
"revision": "v1.0-hash",
"repo_url": "https://github.com/webzard-io/sunmao-ui"
},
"have_a_pricing_plan": true
}
}
ComponentSpec
properties
Since we are using JSON schema to describe properties, we will follow JSON schema to describe more information of a component.
I’m going to propose three ways to organize the information.
1: Without namespace
{
"width": {
"type": "number",
"title": "Width",
"description": "width of the component in pixel",
"widget": "WidthSlider"
}
}
2: With nested namespace
{
"width": {
"type": "number",
"editor": {
"title": "Width",
"description": "width of the component in pixel",
"widget": "WidthSlider"
}
}
}
3: With plain namespace
{
"width": {
"type": "number",
"editor:title": "Width",
"editor:description": "width of the component in pixel",
"editor:widget": "WidthSlider"
}
}
To tell the editor how to display property in the form, we define the following fields:
- title: will display as the label of the form control
- description: will display as the help text of the form control
- widget: will determine which form control will be used
- category: properties will be grouped by category in the form, properties without a category will fall back to the
basic
category.
Trait
Metadata
Same as the Component metadata.
TraitSpec
properties
Same as the ComponentSpec properties.
Application
Metadata
Same as the Component metadata.
To tell the runtime how to render the head of the HTML, we define the following rules of the annotation fields:
- title: will render
<title>
in the<head>
- meta: will render
<meta>
in the<head>
- link: will render
<link>
in the<head>
An example of application’s annotation:
{
"name": "Blog",
"description": "My Blog Website",
"annotations": {
"title": "sunmao-ui developer blog",
"meta": [
{
"name": "viewport",
"content": "width=device-width"
},
{
"name": "description",
"content": "the blog website to record our thought on the sunmao-ui project"
}
],
"link": [
{
"rel": "alternate icon",
"type": "image/png",
"href": "https://github.githubassets.com/favicons/favicon.png"
}
]
}
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (8 by maintainers)
An update:
How about fallback entities without
category
toadvance
instead ofbasic
? This pushes developers to define categories explicitly.I preffer 3: With plain namespace. It can avoid conflict when a property is an object and has a key called
title
ordescription
.