Skip to content

Commit 7925dfd

Browse files
authored
chore(account-elements): setup account elements project (#6683)
1 parent ed849ca commit 7925dfd

File tree

11 files changed

+364
-112
lines changed

11 files changed

+364
-112
lines changed

commitlint.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const config: UserConfig = {
77
extends: ['@commitlint/config-conventional'],
88
rules: {
99
'type-enum': [2, 'always', [...conventional.rules['type-enum'][2], 'api', 'release']],
10-
'scope-enum': [2, 'always', ['connector', 'console', 'core', 'demo-app', 'test', 'phrases', 'schemas', 'shared', 'experience', 'experience-legacy', 'deps', 'deps-dev', 'cli', 'toolkit', 'cloud', 'app-insights', 'elements', 'translate', 'tunnel']],
10+
'scope-enum': [2, 'always', ['connector', 'console', 'core', 'demo-app', 'test', 'phrases', 'schemas', 'shared', 'experience', 'experience-legacy', 'deps', 'deps-dev', 'cli', 'toolkit', 'cloud', 'app-insights', 'elements', 'translate', 'tunnel', 'account-elements']],
1111
// Slightly increase the tolerance to allow the appending PR number
1212
...(isCi && { 'header-max-length': [2, 'always', 110] }),
1313
'body-max-line-length': [2, 'always', 110],

packages/account-elements/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Logto account elements
2+
3+
TBD

packages/account-elements/index.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Logto elements dev page</title>
8+
<script type="module" src="./src/index.ts"></script>
9+
</head>
10+
11+
<body>
12+
<logto-account-provider>
13+
Logto Account Provider
14+
</logto-account-provider>
15+
</body>
16+
17+
</html>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{
2+
"name": "@logto/elements",
3+
"version": "0.0.1",
4+
"description": "Logto account elements.",
5+
"author": "Silverhand Inc. <[email protected]>",
6+
"homepage": "https://github.com/logto-io/logto#readme",
7+
"license": "MPL-2.0",
8+
"type": "module",
9+
"private": true,
10+
"main": "dist/index.js",
11+
"module": "dist/index.js",
12+
"exports": {
13+
".": {
14+
"import": "./dist/index.js",
15+
"types": "./dist/index.d.ts"
16+
},
17+
"./react": {
18+
"import": "./dist/react.js",
19+
"types": "./dist/react.d.ts"
20+
}
21+
},
22+
"files": [
23+
"dist"
24+
],
25+
"repository": {
26+
"type": "git",
27+
"url": "git+https://github.com/logto-io/logto.git"
28+
},
29+
"scripts": {
30+
"precommit": "lint-staged",
31+
"build": "tsup",
32+
"start": "web-dev-server",
33+
"dev": "tsup --watch --no-splitting",
34+
"lint": "eslint --ext .ts src",
35+
"lint:report": "pnpm lint --format json --output-file report.json",
36+
"test": "echo \"No tests yet.\"",
37+
"test:ci": "pnpm run test --silent --coverage"
38+
},
39+
"engines": {
40+
"node": "^20.9.0"
41+
},
42+
"bugs": {
43+
"url": "https://github.com/logto-io/logto/issues"
44+
},
45+
"dependencies": {
46+
"@lit/context": "^1.1.2",
47+
"@lit/react": "^1.0.5",
48+
"@silverhand/essentials": "^2.9.1",
49+
"ky": "^1.2.3",
50+
"lit": "^3.1.4"
51+
},
52+
"devDependencies": {
53+
"@logto/schemas": "workspace:^1.20.0",
54+
"@silverhand/eslint-config": "6.0.1",
55+
"@silverhand/ts-config": "6.0.0",
56+
"@types/node": "^20.9.5",
57+
"@web/dev-server": "^0.4.6",
58+
"@web/dev-server-esbuild": "^1.0.2",
59+
"eslint": "^8.56.0",
60+
"lint-staged": "^15.0.0",
61+
"prettier": "^3.0.0",
62+
"tsup": "^8.1.0"
63+
},
64+
"eslintConfig": {
65+
"extends": "@silverhand",
66+
"ignorePatterns": [
67+
"src/generated/"
68+
],
69+
"rules": {
70+
"no-console": "error",
71+
"unicorn/prevent-abbreviations": [
72+
"error",
73+
{
74+
"replacements": {
75+
"var": false,
76+
"vars": false
77+
}
78+
}
79+
]
80+
}
81+
},
82+
"prettier": "@silverhand/eslint-config/.prettierrc"
83+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './providers/logto-account-provider.js';
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { html, LitElement } from 'lit';
2+
import { customElement } from 'lit/decorators.js';
3+
4+
const tagName = 'logto-account-provider';
5+
@customElement('logto-account-provider')
6+
export class LogtoAccountProvider extends LitElement {
7+
static tagName = tagName;
8+
9+
render() {
10+
return html`<slot></slot>`;
11+
}
12+
}
13+
14+
declare global {
15+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
16+
interface HTMLElementTagNameMap {
17+
[tagName]: LogtoAccountProvider;
18+
}
19+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { createComponent } from '@lit/react';
2+
3+
import { LogtoAccountProvider } from './index.js';
4+
5+
export const createReactComponents = (react: Parameters<typeof createComponent>[0]['react']) => {
6+
return {
7+
LogtoAccountProvider: createComponent({
8+
tagName: LogtoAccountProvider.tagName,
9+
elementClass: LogtoAccountProvider,
10+
react,
11+
}),
12+
};
13+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "@silverhand/ts-config/tsconfig.base",
3+
"compilerOptions": {
4+
"experimentalDecorators": true,
5+
"useDefineForClassFields": false,
6+
"noEmit": true
7+
},
8+
"include": [
9+
"src",
10+
"*.config.ts"
11+
]
12+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import fs from 'node:fs/promises';
2+
3+
import { defineConfig } from 'tsup';
4+
5+
export default defineConfig({
6+
entry: ['src/index.ts', 'src/react.ts'],
7+
format: 'esm',
8+
dts: true,
9+
clean: true,
10+
esbuildPlugins: [
11+
{
12+
name: 'transform-svg',
13+
setup: (build) => {
14+
build.onLoad({ filter: /\.svg$/ }, async (arguments_) => {
15+
const text = await fs.readFile(arguments_.path, 'utf8');
16+
return {
17+
contents: `import { html } from 'lit';\nexport default html\`${text}\`;`,
18+
};
19+
});
20+
},
21+
},
22+
],
23+
});
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// eslint-disable-next-line unicorn/prevent-abbreviations
2+
import { fileURLToPath } from 'node:url';
3+
4+
import { esbuildPlugin } from '@web/dev-server-esbuild';
5+
6+
const config = {
7+
open: true,
8+
watch: true,
9+
appIndex: 'index.html',
10+
nodeResolve: {
11+
exportConditions: ['development'],
12+
},
13+
plugins: [
14+
esbuildPlugin({
15+
ts: true,
16+
tsconfig: fileURLToPath(new URL('tsconfig.json', import.meta.url)),
17+
}),
18+
// Transform SVG files into Lit templates
19+
{
20+
name: 'transform-svg',
21+
transform(context) {
22+
if (context.path.endsWith('.svg')) {
23+
return {
24+
body: `import { html } from 'lit';\nexport default html\`${context.body}\`;`,
25+
headers: { 'content-type': 'application/javascript' },
26+
};
27+
}
28+
},
29+
},
30+
],
31+
};
32+
33+
export default config;

0 commit comments

Comments
 (0)