Skip to content

Commit

Permalink
New version based on lit-element-starter-ts.
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Evans committed Apr 10, 2020
1 parent 6f85e79 commit 54c0c7c
Show file tree
Hide file tree
Showing 43 changed files with 13,150 additions and 1,601 deletions.
17 changes: 17 additions & 0 deletions .eleventy.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");

module.exports = function(eleventyConfig) {
eleventyConfig.addPlugin(syntaxHighlight);
eleventyConfig.addPassthroughCopy("docs-src/docs.css");
eleventyConfig.addPassthroughCopy("docs-src/.nojekyll");
return {
dir: {
input: "docs-src",
output: "docs"
},
templateExtensionAliases: {
"11ty.cjs": "11ty.js",
"11tydata.cjs": "11tydata.js"
}
};
};
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/*
docs/*
docs-src/*
rollup-config.js
19 changes: 19 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": [
"eslint:recommended"
],
"env": {
"browser": true,
"mocha": true
},
"globals": {
"chai": "readonly"
},
"parser": "babel-eslint",
"parserOptions": {
"sourceType": "module"
},
"rules": {
"no-unexpected-multiline": "off"
}
}
14 changes: 8 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
node_modules/
dist/
build/
/node_modules/
/lib/
/test/

*.js.map
*.d.ts
*.d.ts.map
# top level source
my-element.js
my-element.js.map
my-element.d.ts
my-element.d.ts.map
7 changes: 7 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"singleQuote": true,
"bracketSpacing": false,
"arrowParens": "always"
}
13 changes: 13 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp

// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"runem.lit-plugin"
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": [

]
}
28 changes: 28 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
BSD 3-Clause License

Copyright (c) 2019, The Polymer Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
110 changes: 96 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,112 @@
# LitElement JavaScript starter
# LitElement TypeScript starter

This directory includes a sample component project using LitElement.
This project includes a sample component using LitElement with TypeScript.

This sample uses [ES dev server](https://github.com/open-wc/open-wc/tree/master/packages/es-dev-server)
for previewing the project without a build step. ES dev server handles resolving Node-style
import specifiers, which aren't supported in browsers. It also automatically transpiles code
and adds polyfills to support older browsers.
## Setup

Install dependencies:

## Setup
```bash
npm i
```

## Build

This sample uses the TypeScript compiler to produce JavaScript that runs in modern browsers.

To build the JavaScript version of your component:

```bash
npm run build
```

To watch files and rebuild when the files are modified, run the following command in a separate shell:

```bash
npm run build:watch
```

Both the TypeScript compiler and lit-analyzer are configured to be very strict. You may want to change `tsconfig.json` to make them less strict.

Install dependencies
## Testing

This sample uses Karma, Chai, Mocha, and the open-wc test helpers for testing. See the [open-wc testing documentation](https://open-wc.org/testing/testing.html) for more information.

Tests can be run with the `test` script:

```bash
npm -i
npm test
```

## Preview
## Dev Server

This sample uses open-wc's [es-dev-server](https://github.com/open-wc/open-wc/tree/master/packages/es-dev-server) for previewing the project without additional build steps. ES dev server handles resolving Node-style "bare" import specifiers, which aren't supported in browsers. It also automatically transpiles JavaScript and adds polyfills to support older browsers.

Run the dev server and open the project in a new browser tab:
To run the dev server and open the project in a new browser tab:

```bash
npm start
npm run serve
```

There is a development HTML file located at `/dev/index.html` that you can view at http://localhost:8000/dev/index.html.

## Editing

If you use VS Code, we highly reccomend the [lit-plugin extension](https://marketplace.visualstudio.com/items?itemName=runem.lit-plugin), which enables some extremely useful features for lit-html templates:
- Syntax highlighting
- Type-checking
- Code completion
- Hover-over docs
- Jump to definition
- Linting
- Quick Fixes

The project is setup to reccomend lit-plugin to VS Code users if they don't already have it installed.

## Linting

Linting of TypeScript files is provided by [ESLint](eslint.org) and [TypeScript ESLint](https://github.com/typescript-eslint/typescript-eslint). In addition, [lit-analyzer](https://www.npmjs.com/package/lit-analyzer) is used to type-check and lint lit-html templates with the same engine and rules as lit-plugin.

The rules are mostly the recommended rules from each project, but some have been turned off to make LitElement usage easier. The recommended rules are pretty strict, so you may want to relax them by editing `.eslintrc.json` and `tsconfig.json`.

To lint the project run:

```bash
npm run lint
```

## Formatting

[Prettier](https://prettier.io/) is used for code formatting. It has been pre-configured according to the Polymer Project's style. You can change this in `.prettierrc.json`.

Prettier has not been configured to run when commiting files, but this can be added with Husky and and `pretty-quick`. See the [prettier.io](https://prettier.io/) site for instructions.

## Static Site

This project includes a simple website generated with the [eleventy](11ty.dev) static site generator and the templates and pages in `/docs-src`. The site is generated to `/docs` and intended to be checked in so that GitHub pages can serve the site [from `/docs` on the master branch](https://help.github.com/en/github/working-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site).

To enable the site go to the GitHub settings and change the GitHub Pages &quot;Source&quot; setting to &quot;master branch /docs folder&quot;.</p>

To build the site, run:

```bash
npm run docs
```

To serve the site locally, run:

```bash
npm run docs:serve
```

To watch the site files, and re-build automatically, run:

```bash
npm run docs:watch
```

The site will usually be served at http://localhost:8000.

## More information

See [Get started](https://lit-element.polymer-project.org/guide/start) on the LitElement site for
more information.
See [Get started](https://lit-element.polymer-project.org/guide/start) on the LitElement site for more information.
51 changes: 51 additions & 0 deletions custom-elements.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"version": "experimental",
"tags": [
{
"name": "my-element",
"description": "An example element.",
"attributes": [
{
"name": "name",
"description": "The name to say \"Hello\" to.",
"type": "string",
"default": "\"World\""
},
{
"name": "count",
"description": "The number of times the button has been clicked.",
"type": "number",
"default": "0"
}
],
"properties": [
{
"name": "name",
"attribute": "name",
"description": "The name to say \"Hello\" to.",
"type": "string",
"default": "\"World\""
},
{
"name": "count",
"attribute": "count",
"description": "The number of times the button has been clicked.",
"type": "number",
"default": "0"
}
],
"slots": [
{
"name": "",
"description": "This element has a slot"
}
],
"cssParts": [
{
"name": "button",
"description": "The button"
}
]
}
]
}
9 changes: 0 additions & 9 deletions demo.html

This file was deleted.

2 changes: 2 additions & 0 deletions dev/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

This directory contains HTML files containing your element for development. By running `npm run build:watch` and `npm run serve` you can edit and see changes without bundling.
20 changes: 20 additions & 0 deletions dev/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!doctype html>

<html>
<head>
<meta charset="utf-8">
<title>&lt;my-element> Demo</title>
<script type="module" src="../my-element.js"></script>
<style>
p {
border: solid 1px blue;
padding: 8px;
}
</style>
</head>
<body>
<my-element>
<p>This is child content</p>
</my-element>
</body>
</html>
Empty file added docs-src/.nojekyll
Empty file.
7 changes: 7 additions & 0 deletions docs-src/_README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This directory containts the sources for the static site contained in the /docs/ directory. The site is based on the [eleventy](11ty.dev) static site generator.

The site is intended to be used with GitHub pages. To enable the site go to the GitHub settings and change the GitHub Pages "Source" setting to "master branch /docs folder".

To view the site locally, run `npm run docs:serve`.

To edit the site, add to or edit the files in this directory then run `npm run docs` to build the site. The built files must be checked in and pushed to GitHub to appear on GitHub pages.
8 changes: 8 additions & 0 deletions docs-src/_data/api.11tydata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const fs = require('fs');

module.exports = () => {
const customElements = JSON.parse(fs.readFileSync('custom-elements.json', 'utf-8'));
return {
customElements,
};
};
35 changes: 35 additions & 0 deletions docs-src/_includes/example.11ty.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const page = require('./page.11ty.cjs');
const relative = require('./relative-path.cjs');

/**
* This template extends the page template and adds an examples list.
*/
module.exports = function(data) {

return page({
...data,
content: renderExample(data),
});
};

const renderExample = ({name, content, collections, page}) => {
return `
<h1>Example: ${name}</h1>
<section class="examples">
<nav class="collection">
<ul>
${collections.example === undefined
? ''
: collections.example.map((post) => `
<li class=${post.url === page.url ? 'selected' : ''}>
<a href="${relative(page.url, post.url)}">${post.data.description.replace('<', '&lt;')}</a>
</li>
`).join('')}
</ul>
</nav>
<div>
${content}
</div>
</section>
`;
};
9 changes: 9 additions & 0 deletions docs-src/_includes/footer.11ty.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = function(data) {
return `
<footer>
<p>
Made with
<a href="https://github.com/PolymerLabs/lit-element-starter-js">lit-element-starter-js</a>
</p>
</footer>`;
};
7 changes: 7 additions & 0 deletions docs-src/_includes/header.11ty.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = function(data) {
return `
<header>
<h1>&lt;my-element></h1>
<h2>A web component just for me.</h2>
</header>`;
};
Loading

0 comments on commit 54c0c7c

Please sign in to comment.