Skip to content

Commit 85548bd

Browse files
committed
wip: manifest v1 and lit 2
1 parent cc52856 commit 85548bd

37 files changed

+836
-852
lines changed

package.json

+5-6
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,10 @@
4444
"!lib/fixtures"
4545
],
4646
"dependencies": {
47-
"@types/dompurify": "^2.0.4",
48-
"dompurify": "^2.0.15",
47+
"@types/dompurify": "^2.3.1",
48+
"dompurify": "^2.3.3",
4949
"highlight-ts": "9.12.1-2",
50-
"lit-element": "^2.0.0",
51-
"lit-html": "^1.0.0",
50+
"lit": "^2.0.2",
5251
"marked": "^2.0.0",
5352
"tslib": "^2.3.1"
5453
},
@@ -61,10 +60,10 @@
6160
"@web/rollup-plugin-html": "^1.10.1",
6261
"deepmerge": "4.2.2",
6362
"eslint": "^8.0.0",
64-
"eslint-config-airbnb-base": "^14.2.0",
63+
"eslint-config-airbnb-base": "^14.2.1",
6564
"eslint-config-prettier": "^8.3.0",
6665
"eslint-plugin-import": "^2.25.2",
67-
"eslint-plugin-lit": "1.3.0",
66+
"eslint-plugin-lit": "1.6.1",
6867
"eslint-plugin-prettier": "^4.0.0",
6968
"eslint-plugin-wc": "^1.3.2",
7069
"lint-staged": "^11.2.3",

src/api-demo-base.ts

+19-10
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
1-
import { LitElement, html, property, TemplateResult } from 'lit-element';
2-
import { until } from 'lit-html/directives/until.js';
3-
import { ElementPromise } from './lib/types.js';
1+
import type * as Manifest from 'custom-elements-manifest/schema';
2+
import type { TemplateResult } from 'lit';
3+
4+
import { LitElement, html } from 'lit';
5+
import { property } from 'lit/decorators.js';
6+
import { until } from 'lit/directives/until.js';
47
import { ApiViewerMixin, emptyDataWarning } from './api-viewer-mixin.js';
58
import './api-demo-content.js';
9+
import { getElements } from './lib/utils.js';
610

711
async function renderDemo(
8-
jsonFetched: ElementPromise,
12+
jsonFetched: Promise<Manifest.Package | null>,
913
selected?: string,
1014
id?: number,
1115
exclude = ''
1216
): Promise<TemplateResult> {
13-
const elements = await jsonFetched;
17+
const elements = await getElements(jsonFetched);
1418

1519
const index = elements.findIndex((el) => el.name === selected);
1620

1721
return elements.length
1822
? html`
1923
<api-demo-content
20-
.elements="${elements}"
21-
.selected="${index >= 0 ? index : 0}"
22-
.exclude="${exclude}"
23-
.vid="${id}"
24+
.elements=${elements}
25+
.selected=${index >= 0 ? index : 0}
26+
.exclude=${exclude}
27+
.vid=${id}
2428
></api-demo-content>
2529
`
2630
: emptyDataWarning;
@@ -42,7 +46,12 @@ export class ApiDemoBase extends ApiViewerMixin(LitElement) {
4246
protected render(): TemplateResult {
4347
return html`
4448
${until(
45-
renderDemo(this.jsonFetched, this.selected, this._id, this.excludeKnobs)
49+
renderDemo(
50+
Promise.resolve(this.jsonFetched ?? null),
51+
this.selected,
52+
this._id,
53+
this.excludeKnobs
54+
)
4655
)}
4756
`;
4857
}

src/api-demo-content.ts

+26-22
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
1-
import {
2-
LitElement,
3-
html,
4-
customElement,
5-
property,
6-
TemplateResult
7-
} from 'lit-element';
8-
import { ElementInfo } from './lib/types.js';
1+
import type * as Manifest from 'custom-elements-manifest/schema';
2+
import type { TemplateResult } from 'lit';
3+
4+
import { LitElement, html } from 'lit';
5+
import { customElement, property } from 'lit/decorators.js';
6+
97
import { EMPTY_ELEMENT } from './lib/constants.js';
108
import './api-viewer-demo.js';
119

1210
@customElement('api-demo-content')
1311
export class ApiDemoContent extends LitElement {
14-
@property({ attribute: false }) elements: ElementInfo[] = [];
12+
@property({ attribute: false }) elements: Manifest.CustomElement[] = [];
1513

1614
@property({ type: Number }) selected = 0;
1715

1816
@property() exclude = '';
1917

2018
@property({ type: Number }) vid?: number;
2119

22-
protected createRenderRoot() {
20+
protected createRenderRoot(): this {
2321
return this;
2422
}
2523

2624
protected render(): TemplateResult {
2725
const { elements, selected, exclude, vid } = this;
2826

29-
const { name, properties, slots, events, cssProperties } = {
27+
const {
28+
name,
29+
members = [],
30+
slots,
31+
events,
32+
cssProperties
33+
} = {
3034
...EMPTY_ELEMENT,
3135
...(elements[selected] || {})
3236
};
@@ -42,26 +46,26 @@ export class ApiDemoContent extends LitElement {
4246
<nav>
4347
<label part="select-label">
4448
<select
45-
@change="${this._onSelect}"
46-
.value="${String(selected)}"
47-
?hidden="${elements.length === 1}"
49+
@change=${this._onSelect}
50+
.value=${String(selected)}
51+
?hidden=${elements.length === 1}
4852
part="select"
4953
>
5054
${elements.map(
51-
(tag, idx) => html`<option value="${idx}">${tag.name}</option>`
55+
(tag, idx) => html`<option value=${idx}>${tag.name}</option>`
5256
)}
5357
</select>
5458
</label>
5559
</nav>
5660
</header>
5761
<api-viewer-demo
58-
.name="${name}"
59-
.props="${properties}"
60-
.slots="${slots}"
61-
.events="${events}"
62-
.cssProps="${cssProps}"
63-
.exclude="${exclude}"
64-
.vid="${vid}"
62+
.name=${name}
63+
.props=${members.filter((x) => x.kind === 'field')}
64+
.slots=${slots}
65+
.events=${events}
66+
.cssProps=${cssProps}
67+
.exclude=${exclude}
68+
.vid=${vid}
6569
></api-viewer-demo>
6670
`;
6771
}

0 commit comments

Comments
 (0)