-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathbase.ts
More file actions
88 lines (81 loc) · 2.45 KB
/
base.ts
File metadata and controls
88 lines (81 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { html, LitElement, type TemplateResult } from 'lit';
import { until } from 'lit/directives/until.js';
import {
emptyDataWarning,
getCustomElements,
getElementData,
getPublicFields,
getPublicMethods,
hasCustomElements,
ManifestMixin,
type Package
} from '@api-viewer/common/lib/index.js';
import { classMap } from 'lit/directives/class-map.js';
import { parse } from './utils/markdown.js';
import './layout.js';
async function renderDocs(
jsonFetched: Promise<Package | null>,
onSelect: (e: CustomEvent) => void,
only?: string[],
selected?: string
): Promise<TemplateResult> {
const manifest = await jsonFetched;
if (!hasCustomElements(manifest)) {
return emptyDataWarning;
}
const elements = getCustomElements(manifest, only);
const data = getElementData(manifest, elements, selected)!;
const props = getPublicFields(data.members);
const methods = getPublicMethods(data.members);
return html`
<header part="header">
<div part="header-title"><${data.name}></div>
<nav>
<label part="select-label">
<select
@change=${onSelect}
.value=${selected || ''}
?hidden=${elements.length === 1}
part="select"
>
${elements.map(
(tag) => html`<option value=${tag.name}>${tag.name}</option>`
)}
</select>
</label>
</nav>
</header>
<div class=${classMap({ deprecated: !!data.deprecated })}>
<div
?hidden=${data.deprecated === undefined || data.deprecated === false}
part="docs-deprecated-component"
>
${data.deprecated === true ? 'Deprecated' : data.deprecated}
</div>
<div ?hidden=${data.description === ''} part="docs-description">
${parse(data.description)}
</div>
</div>
<api-docs-layout
.name=${data.name}
.props=${props}
.attrs=${data.attributes ?? []}
.methods=${methods}
.events=${data.events ?? []}
.slots=${data.slots ?? []}
.cssParts=${data.cssParts ?? []}
.cssProps=${data.cssProperties ?? []}
part="docs-container"
></api-docs-layout>
`;
}
export class ApiDocsBase extends ManifestMixin(LitElement) {
protected render(): TemplateResult {
return html`${until(
renderDocs(this.jsonFetched, this._onSelect, this.only, this.selected)
)}`;
}
private _onSelect(e: Event): void {
this.selected = (e.target as HTMLSelectElement).value;
}
}