Skip to content

Commit

Permalink
feat(side):lit temp support sidepanel
Browse files Browse the repository at this point in the history
  • Loading branch information
guocaoyi committed Oct 8, 2023
1 parent 928933f commit 8f319eb
Show file tree
Hide file tree
Showing 21 changed files with 233 additions and 67 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ Summary

## 0.8.8 [2023.10.08]

- feat: support side panel for chrome extension(vanilla \ preact \ svelte \ solid \ inferno)
- feat: support side panel for chrome extension(vanilla \ preact \ svelte \ solid \ inferno \ lit)

## 0.8.7 [2023.10.03]

- feat: support side panel for chrome extension(react & vue)
- feat: support side panel for chrome extension(react \ vue)
- merge: merge pull requests

## 0.8.4 [2023.03.23]
Expand Down
6 changes: 2 additions & 4 deletions template-lit-js/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Chrome Extension + Lit + JS + Vite App - Options</title>
<link rel="stylesheet" href="./src/index.css" />
<script type="module" src="./src/options/index.js"></script>
</head>
<body>
<options>
<h1>Vite + Lit</h1>
</options>
<options-panel></options-panel>
<script type="module" src="./src/options/index.js"></script>
</body>
</html>
6 changes: 3 additions & 3 deletions template-lit-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
"fmt": "prettier --write '**/*.{js,json,css,scss,md}'"
},
"dependencies": {
"lit": "^2.2.6"
"lit": "^2.8.0"
},
"devDependencies": {
"@crxjs/vite-plugin": "^2.0.0-beta.19",
"prettier": "^2.7.1",
"vite": "^2.9.13"
"prettier": "^3.0.3",
"vite": "^3.2.7"
}
}
6 changes: 2 additions & 4 deletions template-lit-js/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Chrome Extension + Lit + JS + Vite App - Popup</title>
<link rel="stylesheet" href="./src/index.css" />
<script type="module" src="/src/popup/index.js"></script>
</head>
<body>
<popup>
<h1>Vite + Lit</h1>
</popup>
<popup-panel></popup-panel>
<script type="module" src="./src/popup/index.js"></script>
</body>
</html>
14 changes: 14 additions & 0 deletions template-lit-js/sidepanel.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/icons/logo.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Chrome Extension + Lit + JS + Vite App - Side Panel</title>
<link rel="stylesheet" href="./src/index.css" />
</head>
<body>
<side-panel></side-panel>
<script type="module" src="./src/sidepanel/index.js"></script>
</body>
</html>
8 changes: 0 additions & 8 deletions template-lit-js/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@
-webkit-text-size-adjust: 100%;
}

body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}

@media (prefers-color-scheme: light) {
:root {
color: #213547;
Expand Down
5 changes: 4 additions & 1 deletion template-lit-js/src/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ export default defineManifest({
js: ['src/content/index.js'],
},
],
side_panel: {
default_path: 'sidepanel.html',
},
web_accessible_resources: [
{
resources: ['img/logo-16.png', 'img/logo-34.png', 'img/logo-48.png', 'img/logo-128.png'],
matches: [],
},
],
permissions: [],
permissions: ['sidePanel'],
})
6 changes: 2 additions & 4 deletions template-lit-js/src/options/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ export class Options extends LitElement {
<h6>v 0.0.0</h6>
<slot></slot>
<a href="https://www.npmjs.com/package/create-chrome-ext" target="_blank"
>Generator by ${this.crx}</a
>
Expand Down Expand Up @@ -59,7 +57,7 @@ export class Options extends LitElement {
h6 {
font-size: 0.5rem;
color: #333333;
color: #cccccc;
margin: 0.5rem;
}
Expand All @@ -79,4 +77,4 @@ export class Options extends LitElement {
}
}

window.customElements.define('options', Options)
window.customElements.define('options-panel', Options)
6 changes: 2 additions & 4 deletions template-lit-js/src/popup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ export class Popup extends LitElement {
<h6>v 0.0.0</h6>
<slot></slot>
<a href="https://www.npmjs.com/package/create-chrome-ext" target="_blank"
>Generator by ${this.crx}</a
>
Expand Down Expand Up @@ -59,7 +57,7 @@ export class Popup extends LitElement {
h6 {
font-size: 0.5rem;
color: #333333;
color: #cccccc;
margin: 0.5rem;
}
Expand All @@ -79,4 +77,4 @@ export class Popup extends LitElement {
}
}

window.customElements.define('popup', Popup)
window.customElements.define('popup-panel', Popup)
80 changes: 80 additions & 0 deletions template-lit-js/src/sidepanel/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { html, css, LitElement } from 'lit'

/**
* Side Panel
*/
export class Sidepanel extends LitElement {
static get properties() {
return {
crx: { type: String },
}
}

constructor() {
super()
this.crx = 'create-chrome-ext'
}

render() {
return html`
<main>
<h3>Side Panel Page!</h3>
<h6>v 0.0.0</h6>
<a href="https://www.npmjs.com/package/create-chrome-ext" target="_blank"
>Generator by ${this.crx}</a
>
</main>
`
}

static get styles() {
return css`
:root {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu,
Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}
:global(body) {
min-width: 20rem;
}
main {
text-align: center;
padding: 1em;
margin: 0 auto;
}
h3 {
color: #3355ff;
text-transform: uppercase;
font-size: 1.5rem;
font-weight: 200;
line-height: 1.2rem;
margin: 2rem auto;
}
h6 {
font-size: 0.5rem;
color: #cccccc;
margin: 0.5rem;
}
a {
font-size: 0.5rem;
margin: 0.5rem;
color: #cccccc;
text-decoration: none;
}
@media (min-width: 480px) {
h3 {
max-width: none;
}
}
`
}
}

window.customElements.define('side-panel', Sidepanel)
29 changes: 14 additions & 15 deletions template-lit-js/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@ import { crx } from '@crxjs/vite-plugin'
import manifest from './src/manifest.js'

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
return {
build: {
emptyOutDir: true,
outDir: 'build',
rollupOptions: {
input: {
options: path.resolve('options.html'),
popup: path.resolve('popup.html'),
},
output: {
chunkFileNames: 'assets/chunk-[hash].js',
},
export default defineConfig({
build: {
emptyOutDir: true,
outDir: 'build',
rollupOptions: {
input: {
options: path.resolve('options.html'),
popup: path.resolve('popup.html'),
sidepanel: path.resolve('sidepanel.html'),
},
output: {
chunkFileNames: 'assets/chunk-[hash].js',
},
},
plugin: [crx({ manifest })],
}
},
plugins: [crx({ manifest })],
})
4 changes: 2 additions & 2 deletions template-lit-ts/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
<link rel="stylesheet" href="./src/index.css" />
</head>
<body>
<options>
<lit-options>
<h1>Vite + Lit</h1>
</options>
</lit-options>
<script type="module" src="./src/options/index.ts"></script>
</body>
</html>
10 changes: 5 additions & 5 deletions template-lit-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
"fmt": "prettier --write '**/*.{ts,json,css,scss,md}'"
},
"dependencies": {
"lit": "^2.2.6"
"lit": "^2.8.0"
},
"devDependencies": {
"@crxjs/vite-plugin": "^2.0.0-beta.19",
"@types/chrome": "^0.0.236",
"@types/chrome": "^0.0.246",
"path": "^0.12.7",
"prettier": "^2.7.1",
"typescript": "^4.6.4",
"vite": "^2.9.13"
"prettier": "^3.0.3",
"typescript": "^5.2.2",
"vite": "^3.2.7"
}
}
4 changes: 2 additions & 2 deletions template-lit-ts/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
<link rel="stylesheet" href="./src/index.css" />
</head>
<body>
<popup>
<lit-popup>
<h1>Vite + Lit</h1>
</popup>
</lit-popup>
<script type="module" src="./src/popup/index.ts"></script>
</body>
</html>
14 changes: 14 additions & 0 deletions template-lit-ts/sidepanel.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/icons/logo.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Chrome Extension + Lit + TS + Vite App - Side Panel</title>
<link rel="stylesheet" href="./src/index.css" />
</head>
<body>
<side-panel></side-panel>
<script type="module" src="./src/sidepanel/index.ts"></script>
</body>
</html>
8 changes: 0 additions & 8 deletions template-lit-ts/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@
-webkit-text-size-adjust: 100%;
}

body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}

@media (prefers-color-scheme: light) {
:root {
color: #213547;
Expand Down
5 changes: 4 additions & 1 deletion template-lit-ts/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ export default defineManifest({
js: ['src/content/index.ts'],
},
],
side_panel: {
default_path: 'sidepanel.html',
},
web_accessible_resources: [
{
resources: ['img/logo-16.png', 'img/logo-34.png', 'img/logo-48.png', 'img/logo-128.png'],
matches: [],
},
],
permissions: [],
permissions: ['sidePanel'],
})
4 changes: 2 additions & 2 deletions template-lit-ts/src/options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { customElement, property } from 'lit/decorators.js'
/**
* options
*/
@customElement('options')
@customElement('options-panel')
export class Options extends LitElement {
@property()
crx = 'create-chrome-ext'
Expand Down Expand Up @@ -73,6 +73,6 @@ export class Options extends LitElement {

declare global {
interface HTMLElementTagNameMap {
options: Options
'options-panel': Options
}
}
4 changes: 2 additions & 2 deletions template-lit-ts/src/popup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { customElement, property } from 'lit/decorators.js'
/**
* popup
*/
@customElement('popup')
@customElement('popup-panel')
export class Popup extends LitElement {
@property()
crx = 'create-chrome-ext'
Expand Down Expand Up @@ -73,6 +73,6 @@ export class Popup extends LitElement {

declare global {
interface HTMLElementTagNameMap {
popup: Popup
'popup-panel': Popup
}
}
Loading

0 comments on commit 8f319eb

Please sign in to comment.