Skip to content

Commit 66b7e25

Browse files
committed
Initial commit
0 parents  commit 66b7e25

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+30503
-0
lines changed

.eleventy.cjs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const syntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight');
2+
3+
module.exports = function (eleventyConfig) {
4+
eleventyConfig.addPlugin(syntaxHighlight);
5+
eleventyConfig.addPassthroughCopy('docs-src/docs.css');
6+
eleventyConfig.addPassthroughCopy('docs-src/.nojekyll');
7+
eleventyConfig.addPassthroughCopy(
8+
'node_modules/@webcomponents/webcomponentsjs'
9+
);
10+
eleventyConfig.addPassthroughCopy('node_modules/lit/polyfill-support.js');
11+
return {
12+
dir: {
13+
input: 'docs-src',
14+
output: 'docs',
15+
},
16+
templateExtensionAliases: {
17+
'11ty.cjs': '11ty.js',
18+
'11tydata.cjs': '11tydata.js',
19+
},
20+
};
21+
};

.eslintignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules/*
2+
docs/*
3+
docs-src/*
4+
rollup-config.js
5+
custom-elements.json

.eslintrc.json

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"root": true,
3+
"extends": [
4+
"eslint:recommended",
5+
"plugin:@typescript-eslint/eslint-recommended",
6+
"plugin:@typescript-eslint/recommended"
7+
],
8+
"parser": "@typescript-eslint/parser",
9+
"parserOptions": {
10+
"ecmaVersion": 2020,
11+
"sourceType": "module"
12+
},
13+
"plugins": ["@typescript-eslint"],
14+
"env": {
15+
"browser": true
16+
},
17+
"rules": {
18+
"no-prototype-builtins": "off",
19+
"@typescript-eslint/ban-types": "off",
20+
"@typescript-eslint/explicit-function-return-type": "off",
21+
"@typescript-eslint/explicit-module-boundary-types": "off",
22+
"@typescript-eslint/no-explicit-any": "error",
23+
"@typescript-eslint/no-empty-function": "off",
24+
"@typescript-eslint/no-non-null-assertion": "off",
25+
"@typescript-eslint/no-unused-vars": [
26+
"warn",
27+
{
28+
"argsIgnorePattern": "^_"
29+
}
30+
]
31+
},
32+
"overrides": [
33+
{
34+
"files": ["rollup.config.js", "web-test-runner.config.js"],
35+
"env": {
36+
"node": true
37+
}
38+
},
39+
{
40+
"files": [
41+
"*_test.ts",
42+
"**/custom_typings/*.ts",
43+
"packages/lit-ssr/src/test/integration/tests/**",
44+
"packages/lit-ssr/src/lib/util/parse5-utils.ts"
45+
],
46+
"rules": {
47+
"@typescript-eslint/no-explicit-any": "off"
48+
}
49+
}
50+
]
51+
}

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
node_modules/
2+
/lib/
3+
/test/
4+
custom-elements.json
5+
# top level source
6+
my-element.js
7+
my-element.js.map
8+
my-element.d.ts
9+
my-element.d.ts.map

.prettierrc.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"trailingComma": "es5",
3+
"tabWidth": 2,
4+
"singleQuote": true,
5+
"bracketSpacing": false,
6+
"arrowParens": "always"
7+
}

.vscode/extensions.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
3+
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
4+
5+
// List of extensions which should be recommended for users of this workspace.
6+
"recommendations": ["runem.lit-plugin"],
7+
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
8+
"unwantedRecommendations": []
9+
}

LICENSE

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2019 Google LLC. All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
1. Redistributions of source code must retain the above copyright notice, this
9+
list of conditions and the following disclaimer.
10+
11+
2. Redistributions in binary form must reproduce the above copyright notice,
12+
this list of conditions and the following disclaimer in the documentation
13+
and/or other materials provided with the distribution.
14+
15+
3. Neither the name of the copyright holder nor the names of its
16+
contributors may be used to endorse or promote products derived from
17+
this software without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# LitElement TypeScript starter
2+
3+
This project includes a sample component using LitElement with TypeScript.
4+
5+
## Setup
6+
7+
Install dependencies:
8+
9+
```bash
10+
npm i
11+
```
12+
13+
## Build
14+
15+
This sample uses the TypeScript compiler to produce JavaScript that runs in modern browsers.
16+
17+
To build the JavaScript version of your component:
18+
19+
```bash
20+
npm run build
21+
```
22+
23+
To watch files and rebuild when the files are modified, run the following command in a separate shell:
24+
25+
```bash
26+
npm run build:watch
27+
```
28+
29+
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.
30+
31+
## Testing
32+
33+
This sample modern-web.dev's
34+
[@web/test-runner](https://www.npmjs.com/package/@web/test-runner) along with
35+
Mocha, Chai, and some related helpers for testing. See the
36+
[modern-web.dev testing documentation](https://modern-web.dev/docs/test-runner/overview) for
37+
more information.
38+
39+
Tests can be run with the `test` script:
40+
41+
```bash
42+
npm test
43+
```
44+
45+
## Dev Server
46+
47+
This sample uses modern-web.dev's [@web/dev-server](https://www.npmjs.com/package/@web/dev-server) for previewing the project without additional build steps. Web 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. See [modern-web.dev's Web Dev Server documentation](https://modern-web.dev/docs/dev-server/overview/) for more information.
48+
49+
To run the dev server and open the project in a new browser tab:
50+
51+
```bash
52+
npm run serve
53+
```
54+
55+
There is a development HTML file located at `/dev/index.html` that you can view at http://localhost:8000/dev/index.html.
56+
57+
## Editing
58+
59+
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:
60+
61+
- Syntax highlighting
62+
- Type-checking
63+
- Code completion
64+
- Hover-over docs
65+
- Jump to definition
66+
- Linting
67+
- Quick Fixes
68+
69+
The project is setup to reccomend lit-plugin to VS Code users if they don't already have it installed.
70+
71+
## Linting
72+
73+
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.
74+
75+
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`.
76+
77+
To lint the project run:
78+
79+
```bash
80+
npm run lint
81+
```
82+
83+
## Formatting
84+
85+
[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`.
86+
87+
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.
88+
89+
## Static Site
90+
91+
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).
92+
93+
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>
94+
95+
To build the site, run:
96+
97+
```bash
98+
npm run docs
99+
```
100+
101+
To serve the site locally, run:
102+
103+
```bash
104+
npm run docs:serve
105+
```
106+
107+
To watch the site files, and re-build automatically, run:
108+
109+
```bash
110+
npm run docs:watch
111+
```
112+
113+
The site will usually be served at http://localhost:8000.
114+
115+
## Bundling and minification
116+
117+
This starter project doesn't include any build-time optimizations like bundling or minification. We recommend publishing components as unoptimized JavaScript modules, and performing build-time optimizations at the application level. This gives build tools the best chance to deduplicate code, remove dead code, and so on.
118+
119+
For information on building application projects that include LitElement components, see [Build for production](https://lit-element.polymer-project.org/guide/build) on the LitElement site.
120+
121+
## More information
122+
123+
See [Get started](https://lit-element.polymer-project.org/guide/start) on the LitElement site for more information.

custom-elements.json

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"version": "experimental",
3+
"tags": [
4+
{
5+
"name": "my-element",
6+
"path": "./src/my-element.ts",
7+
"description": "An example element.",
8+
"attributes": [
9+
{
10+
"name": "name",
11+
"description": "The name to say \"Hello\" to.",
12+
"type": "string",
13+
"default": "\"World\""
14+
},
15+
{
16+
"name": "count",
17+
"description": "The number of times the button has been clicked.",
18+
"type": "number",
19+
"default": "0"
20+
}
21+
],
22+
"properties": [
23+
{
24+
"name": "name",
25+
"attribute": "name",
26+
"description": "The name to say \"Hello\" to.",
27+
"type": "string",
28+
"default": "\"World\""
29+
},
30+
{
31+
"name": "count",
32+
"attribute": "count",
33+
"description": "The number of times the button has been clicked.",
34+
"type": "number",
35+
"default": "0"
36+
},
37+
{
38+
"name": "renderRoot",
39+
"description": "Node or ShadowRoot into which element DOM should be rendered. Defaults\nto an open shadowRoot.",
40+
"type": "HTMLElement | ShadowRoot"
41+
},
42+
{
43+
"name": "isUpdatePending",
44+
"type": "boolean"
45+
},
46+
{
47+
"name": "hasUpdated",
48+
"type": "boolean"
49+
},
50+
{
51+
"name": "updateComplete",
52+
"description": "Returns a Promise that resolves when the element has completed updating.\nThe Promise value is a boolean that is `true` if the element completed the\nupdate without triggering another update. The Promise result is `false` if\na property was set inside `updated()`. If the Promise is rejected, an\nexception was thrown during the update.\n\nTo await additional asynchronous work, override the `getUpdateComplete`\nmethod. For example, it is sometimes useful to await a rendered element\nbefore fulfilling this Promise. To do this, first await\n`super.getUpdateComplete()`, then any subsequent state.",
53+
"type": "Promise<boolean>"
54+
}
55+
],
56+
"slots": [
57+
{
58+
"name": "",
59+
"description": "This element has a slot"
60+
}
61+
],
62+
"cssParts": [
63+
{
64+
"name": "button",
65+
"description": "The button"
66+
}
67+
]
68+
}
69+
]
70+
}

dev/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
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.

dev/index.html

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
3+
<html>
4+
<head>
5+
<meta charset="utf-8" />
6+
<title>&lt;my-element> Demo</title>
7+
<script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
8+
<script src="../node_modules/lit/polyfill-support.js"></script>
9+
<script type="module" src="../my-element.js"></script>
10+
<style>
11+
p {
12+
border: solid 1px blue;
13+
padding: 8px;
14+
}
15+
</style>
16+
</head>
17+
<body>
18+
<my-element>
19+
<p>This is child content</p>
20+
</my-element>
21+
</body>
22+
</html>

docs-src/.eleventyignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Ignore files with a leading underscore; useful for e.g. readmes in source documentation
2+
_*.md

docs-src/.nojekyll

Whitespace-only changes.

docs-src/_README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
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.
2+
3+
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".
4+
5+
To view the site locally, run `npm run docs:serve`.
6+
7+
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.

docs-src/_data/api.11tydata.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @license
3+
* Copyright 2021 Google LLC
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
const fs = require('fs');
8+
9+
module.exports = () => {
10+
const customElements = JSON.parse(
11+
fs.readFileSync('custom-elements.json', 'utf-8')
12+
);
13+
return {
14+
customElements,
15+
};
16+
};

0 commit comments

Comments
 (0)