Skip to content

Commit ce28539

Browse files
committed
feat: add auto-sync widget
1 parent caea397 commit ce28539

21 files changed

+601
-3
lines changed

package-lock.json

Lines changed: 42 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/auto-sync/manifest.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "auto-sync",
3+
"id": "1443742630333209915",
4+
"api": "1.0.0",
5+
"main": "dist/index.js",
6+
"ui": "dist/index.html",
7+
"capabilities": [],
8+
"enableProposedApi": false,
9+
"documentAccess": "dynamic-page",
10+
"editorType": ["figma"],
11+
"containsWidget": true,
12+
"widgetApi": "1.0.0",
13+
"networkAccess": {
14+
"allowedDomains": ["none"]
15+
}
16+
}

packages/auto-sync/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "@db-ui/auto-sync",
3+
"version": "1.0.0",
4+
"description": "",
5+
"workspaces": [
6+
"widget/*"
7+
],
8+
"scripts": {
9+
"build": "npm-run-all -p build:*",
10+
"build:code": "npm run build -w=auto-sync-widget -- --minify",
11+
"build:ui": "npm run build -w=auto-sync-ui -- --minify",
12+
"dev": "npm-run-all -p dev:*",
13+
"dev:code": "npm run dev -w=auto-sync-widget",
14+
"dev:ui": "npm run dev -w=auto-sync-ui"
15+
},
16+
"author": "",
17+
"license": "MIT"
18+
}

packages/auto-sync/ui/.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import js from '@eslint/js'
2+
import globals from 'globals'
3+
import reactHooks from 'eslint-plugin-react-hooks'
4+
import reactRefresh from 'eslint-plugin-react-refresh'
5+
import tseslint from 'typescript-eslint'
6+
7+
export default tseslint.config(
8+
{ ignores: ['dist'] },
9+
{
10+
extends: [js.configs.recommended, ...tseslint.configs.recommended],
11+
files: ['**/*.{ts,tsx}'],
12+
languageOptions: {
13+
ecmaVersion: 2020,
14+
globals: globals.browser,
15+
},
16+
plugins: {
17+
'react-hooks': reactHooks,
18+
'react-refresh': reactRefresh,
19+
},
20+
rules: {
21+
...reactHooks.configs.recommended.rules,
22+
'react-refresh/only-export-components': [
23+
'warn',
24+
{ allowConstantExport: true },
25+
],
26+
},
27+
},
28+
)

packages/auto-sync/ui/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vite + React + TS</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script type="module" src="/src/main.tsx"></script>
12+
</body>
13+
</html>

packages/auto-sync/ui/package.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "auto-sync-ui",
3+
"private": true,
4+
"version": "0.0.0",
5+
"type": "module",
6+
"scripts": {
7+
"dev": "npm run build -- --watch",
8+
"build": "tsc -b && vite build --minify esbuild --emptyOutDir=false --target=ES6",
9+
"lint": "eslint ."
10+
},
11+
"dependencies": {
12+
"@db-ui/react-components": "^0.5.5",
13+
"highlight.js": "^11.10.0",
14+
"react": "^18.3.1",
15+
"react-dom": "^18.3.1",
16+
"prettier": "3.3.3"
17+
},
18+
"devDependencies": {
19+
"@eslint/js": "^9.13.0",
20+
"@types/react": "^18.3.12",
21+
"@types/react-dom": "^18.3.1",
22+
"@vitejs/plugin-react": "^4.3.3",
23+
"autoprefixer": "^10.4.20",
24+
"eslint": "^9.13.0",
25+
"eslint-plugin-react-hooks": "^5.0.0",
26+
"eslint-plugin-react-refresh": "^0.4.14",
27+
"globals": "^15.11.0",
28+
"postcss": "^8.4.49",
29+
"tailwindcss": "^3.4.15",
30+
"typescript": "~5.6.2",
31+
"typescript-eslint": "^8.11.0",
32+
"vite": "^5.4.10",
33+
"vite-plugin-singlefile": "^0.13.3"
34+
}
35+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
plugins: {
3+
tailwindcss: {},
4+
autoprefixer: {},
5+
},
6+
}

packages/auto-sync/ui/src/App.tsx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import "./index.css";
2+
import { useEffect, useState } from "react";
3+
import { isDataMessage } from "./utils/plugin-message.ts";
4+
import { PluginMessage } from "shared/data.ts";
5+
6+
const defaultTime: number = 30;
7+
8+
const App = () => {
9+
const [syncName, setSyncName] = useState<string>();
10+
const [time, setTime] = useState<number>(defaultTime);
11+
12+
useEffect(() => {
13+
onmessage = (event: MessageEvent) => {
14+
const message: PluginMessage<any> = event.data.pluginMessage;
15+
if (isDataMessage(message)) {
16+
setSyncName(message.data);
17+
}
18+
};
19+
});
20+
21+
useEffect(() => {
22+
const interval = setInterval(() => {
23+
setTime((current) => current - 1);
24+
}, 1000);
25+
26+
return () => clearInterval(interval);
27+
});
28+
29+
useEffect(() => {
30+
if (time === 0) {
31+
parent.postMessage({ pluginMessage: { type: "refresh" } }, "*");
32+
setTime(defaultTime);
33+
}
34+
}, [time]);
35+
36+
return (
37+
<div className="flex text-center w-full h-full">
38+
<span className="m-auto flex justify-between gap-fix-sm">
39+
<strong>{syncName}: </strong>
40+
<em>{time}</em>
41+
</span>
42+
</div>
43+
);
44+
};
45+
46+
export default App;

packages/auto-sync/ui/src/index.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@tailwind base;
2+
@tailwind components;
3+
@tailwind utilities;

0 commit comments

Comments
 (0)