Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial draft of cem-* elements for rendering manifest data #1425

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion packages/site-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,11 @@
}
},
"dependencies": {
"@types/marked": "^4.0.8",
"@webcomponents/catalog-api": "^0.0.0",
"custom-elements-manifest": "^2.0.0",
"lit": "^2.6.0",
"lit-analyzer": "^1.2.1"
"lit-analyzer": "^1.2.1",
"marked": "^4.2.5"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Todo: I think we should make a separate package that has a markdown parser pre-configured with all the plugins we accept so we make sure it's consistent across uses.

}
}
41 changes: 17 additions & 24 deletions packages/site-client/src/pages/element/wco-element-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import {html, css} from 'lit';
import {customElement, property} from 'lit/decorators.js';
import {unsafeHTML} from 'lit/directives/unsafe-html.js';

import type {Package, Reference} from 'custom-elements-manifest/schema.js';
import {
Expand All @@ -16,6 +15,7 @@ import {
normalizeModulePath,
} from '@webcomponents/custom-elements-manifest-tools';
import {WCOPage} from '../../shared/wco-page.js';
import '../../shared/cem/cem-class-declaration.js';

export interface ElementData {
packageName: string;
Expand Down Expand Up @@ -80,14 +80,20 @@ export class WCOElementPage extends WCOPage {

#content {
grid-area: c;
padding: 1em;
}
`,
];

@property({attribute: false})
elementData?: ElementData;

// TODO(kschaaf) Use context to provide reference resolver
// @provide({context: cemReferenceResolver})
// referenceResolver = (ref: Reference) => {
// const {package: pkg, module, name} = ref;
// return `#${pkg}${module === undefined ? '' : `/${module}`}:${name}`;
// };

renderContent() {
if (this.elementData === undefined) {
return html`<div class="full-screen-error">No element to display</div>`;
Expand All @@ -98,7 +104,6 @@ export class WCOElementPage extends WCOPage {
declarationReference,
customElementExport,
manifest,
elementDescriptionHtml,
} = this.elementData;
const ceExportRef = parseReferenceString(customElementExport);
const declarationRef = parseReferenceString(declarationReference);
Expand All @@ -117,9 +122,6 @@ export class WCOElementPage extends WCOPage {
</div>`;
}

const fields = declaration.members?.filter((m) => m.kind === 'field');
const methods = declaration.members?.filter((m) => m.kind === 'method');

// TODO (justinfagnani): We need a better way to make a summary from a
// description, that's possibly markdown, word, and sentence boundary
// aware.
Expand All @@ -146,24 +148,15 @@ export class WCOElementPage extends WCOPage {
<h3>Install</h3>
<code>npm install ${packageName}</code>
</div>
<div id="content">
<p>${unsafeHTML(elementDescriptionHtml)}</p>

<h2>Usage</h2>
<pre><code>
import '${getElementImportSpecifier(packageName, ceExportRef)}';
</code></pre>

<h2>Fields</h2>
<ul>
${fields?.map((f) => html`<li>${f.name}: ${f.description}</li>`)}
</ul>

<h2>Methods</h2>
<ul>
${methods?.map((m) => html`<li>${m.name}: ${m.description}</li>`)}
</ul>
</div>
<cem-class-declaration id="content" .declaration=${declaration}>
<div slot="usage">
<h4>Usage</h4>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the title go in the element so it's standardized?

<pre><code>import '${getElementImportSpecifier(
packageName,
ceExportRef
)}';</code></pre>
</div>
</cem-class-declaration>
`;
}
}
Expand Down
Loading