Skip to content

Commit 6a00acf

Browse files
authored
docs: add schema example (#91)
1 parent 3957ced commit 6a00acf

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

README.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,104 @@ evolution of the schema. The schema follows [semver](https://semver.org/) versio
4141

4242
This version will not always match the npm package version, as some changes to the npm package might not have changes to the schema. We will publish a list of schema versions and their associated npm versions and git tags.
4343

44+
## Example
45+
46+
Given the following source code in directory `my-project`:
47+
48+
`my-project/my-element.js`:
49+
```js
50+
/**
51+
* This is the description of the class
52+
*/
53+
export class MyElement extends HTMLElement {
54+
static get observedAttributes() {
55+
return ['disabled'];
56+
}
57+
58+
set disabled(val) {
59+
this.__disabled = val;
60+
}
61+
get disabled() {
62+
return this.__disabled;
63+
}
64+
65+
fire() {
66+
this.dispatchEvent(new Event('disabled-changed'));
67+
}
68+
}
69+
70+
customElements.define('my-element', MyElement);
71+
```
72+
73+
The manifest would look like:
74+
75+
`my-project/custom-elements.json`:
76+
```json
77+
{
78+
"schemaVersion": "1.0.0",
79+
"readme": "README.md",
80+
"modules": [
81+
{
82+
"kind": "javascript-module",
83+
"path": "my-project/my-element.js",
84+
"declarations": [
85+
{
86+
"kind": "class",
87+
"description": "This is the description of the class",
88+
"name": "MyElement",
89+
"members": [
90+
{
91+
"kind": "field",
92+
"name": "disabled"
93+
},
94+
{
95+
"kind": "method",
96+
"name": "fire"
97+
}
98+
],
99+
"events": [
100+
{
101+
"name": "disabled-changed",
102+
"type": {
103+
"text": "Event"
104+
}
105+
}
106+
],
107+
"attributes": [
108+
{
109+
"name": "disabled"
110+
}
111+
],
112+
"superclass": {
113+
"name": "HTMLElement"
114+
},
115+
"tagName": "my-element",
116+
"customElement": true
117+
}
118+
],
119+
"exports": [
120+
{
121+
"kind": "js",
122+
"name": "MyElement",
123+
"declaration": {
124+
"name": "MyElement",
125+
"module": "my-project/my-element.js"
126+
}
127+
},
128+
{
129+
"kind": "custom-element-definition",
130+
"name": "my-element",
131+
"declaration": {
132+
"name": "MyElement",
133+
"module": "my-project/my-element.js"
134+
}
135+
}
136+
]
137+
}
138+
]
139+
}
140+
```
141+
44142
# Motivation
45143

46144
Many tools need some machine-readable descriptions of custom elements: IDEs, documentation viewers, linters, graphical design tools, etc.

0 commit comments

Comments
 (0)