Skip to content

Commit

Permalink
(#85) migrate VSCode ext to use react
Browse files Browse the repository at this point in the history
  • Loading branch information
mario4tier committed Apr 17, 2024
1 parent 08f29f9 commit 3918f58
Show file tree
Hide file tree
Showing 51 changed files with 3,986 additions and 3,648 deletions.
1 change: 1 addition & 0 deletions typescript/vscode-extension/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
out
.vscode-test/
webview-ui.svelte/

# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

Expand Down
Binary file added typescript/vscode-extension/media/logo_128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions typescript/vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "suibase",
"displayName": "suibase",
"description": "Streamline Sui Move development and testing.",
"icon": "media/logo_128.png",
"version": "0.0.1",
"repository": "https://github.com/ChainMovers/suibase",
"engines": {
Expand Down Expand Up @@ -54,7 +55,7 @@
{
"id": "suibaseSidebar",
"title": "Suibase",
"icon": "media/dep.svg"
"icon": "media/logo_128.png"
}
]
},
Expand All @@ -63,7 +64,7 @@
{
"id": "explorerView",
"name": "Suibase",
"icon": "media/dep.svg",
"icon": "media/logo_128.svg",
"contextualTitle": "Suibase",
"type": "webview"
}
Expand Down
18 changes: 9 additions & 9 deletions typescript/vscode-extension/src/bases/BaseWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class BaseWebview implements vscode.WebviewViewProvider {
this.extensionUri = BaseWebview.context.extensionUri;
this.extensionUris = [
Uri.joinPath(BaseWebview.context.extensionUri, "out"),
Uri.joinPath(BaseWebview.context.extensionUri, "webview-ui/public/build"),
Uri.joinPath(BaseWebview.context.extensionUri, "webview-ui/build"),
Uri.joinPath(BaseWebview.context.extensionUri, "webview-ui/node_modules/@vscode/codicons/dist"),
];
}
Expand Down Expand Up @@ -197,10 +197,10 @@ export class BaseWebview implements vscode.WebviewViewProvider {
}

// The CSS file from the Svelte build output
const stylesUri = getUri(webview, this.extensionUri, ["webview-ui", "public", "build", "bundle.css"]);
const stylesUri = getUri(webview, this.extensionUri, ["webview-ui", "build", "assets", "index.css"]);

// The JS file from the Svelte build output
const scriptUri = getUri(webview, this.extensionUri, ["webview-ui", "public", "build", "bundle.js"]);
const scriptUri = getUri(webview, this.extensionUri, ["webview-ui", "build", "assets", "index.js"]);

// The icon library being used.
const iconsUri = getUri(webview, this.extensionUri, [
Expand All @@ -222,20 +222,20 @@ export class BaseWebview implements vscode.WebviewViewProvider {
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hello World</title>
<title>Webview-UI</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="Content-Security-Policy" content="default-src ${cspSource}; connect-src http://localhost:*; font-src ${cspSource}; style-src ${cspSource} 'unsafe-inline'; img-src ${cspSource}; script-src ${cspSource} 'strict-dynamic' 'nonce-${nonce}'">
<link rel="stylesheet" type="text/css" href="${stylesUri}">
<link rel="stylesheet" type="text/css" href="${iconsUri}" />
<link rel="stylesheet" type="text/css" href="${iconsUri}" />
</head>
<body>
<script nonce="${nonce}">
var suibase_view_key = '${this.key}';
</script>
<script defer nonce="${nonce}" src="${scriptUri}"></script>
</head>
<body>
<div id="root"></div>
<script type="module" nonce="${nonce}" src="${scriptUri}"></script>
</body>
</html>
`;
Expand Down
3 changes: 2 additions & 1 deletion typescript/vscode-extension/src/common/SuibaseData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export class SuibaseGlobalStates {

public uiSelectedContext: string = "DSUI";
public uiSelectedContextCallback: (newUiSelectedContext: string) => void = (
newUiSelectedContext: string
// eslint-disable-next-line
_newUiSelectedContext: string
) => {};

public serialize(): string {
Expand Down
18 changes: 18 additions & 0 deletions typescript/vscode-extension/webview-ui/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
}
22 changes: 19 additions & 3 deletions typescript/vscode-extension/webview-ui/.gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
/public/build/
dist
dist-ssr
build
build-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
34 changes: 27 additions & 7 deletions typescript/vscode-extension/webview-ui/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
# `webview-ui` Directory
# React + TypeScript + Vite

This directory contains all of the code that will be executed within the webview context. It can be thought of as the place where all the "frontend" code of a webview is contained.
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Types of content that can be contained here:
Currently, two official plugins are available:

- Frontend framework code (i.e. Svelte, Vue, SolidJS, React, etc.)
- JavaScript files
- CSS files
- Assets / resources (i.e. images, illustrations, etc.)
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
export default {
// other rules...
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
tsconfigRootDir: __dirname,
},
}
```

- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1,582 changes: 1,582 additions & 0 deletions typescript/vscode-extension/webview-ui/build/assets/index.js

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions typescript/vscode-extension/webview-ui/build/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Dev Root</title>
<script nonce="${nonce}">
var suibase_view_key = '${this.key}';
</script>

<script type="module" crossorigin src="/assets/index.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index.css">
</head>
<body>
<div id="root"></div>
</body>
</html>
1 change: 1 addition & 0 deletions typescript/vscode-extension/webview-ui/build/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions typescript/vscode-extension/webview-ui/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Dev Root</title>
<script nonce="${nonce}">
var suibase_view_key = '${this.key}';
</script>

</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
51 changes: 23 additions & 28 deletions typescript/vscode-extension/webview-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,32 @@
{
"name": "suibase",
"version": "0.0.1",
"name": "webview-ui",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"build": "rollup -c",
"dev": "rollup -c -w",
"start": "sirv public --no-clear",
"check": "svelte-check --tsconfig ./tsconfig.json"
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"@vscode/codicons": "^0.0.33",
"@vscode/webview-ui-toolkit": "^1.4.0",
"async-mutex": "^0.4.1",
"await-to-js": "^3.0.0",
"dayjs": "^1.11.10",
"sirv-cli": "^2.0.2",
"svelte-preprocess-react": "^0.17.0"
"@estruyf/vscode": "^1.1.0",
"@vscode/webview-ui-toolkit": "^1.2.2",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^17.1.0",
"@rollup/plugin-node-resolve": "^11.2.1",
"@rollup/plugin-typescript": "^8.5.0",
"@tsconfig/svelte": "^2.0.1",
"@types/vscode-webview": "^1.57.5",
"rollup": "^2.79.1",
"rollup-plugin-css-only": "^3.1.0",
"rollup-plugin-livereload": "^2.0.5",
"rollup-plugin-svelte": "^7.2.0",
"rollup-plugin-terser": "^7.0.2",
"svelte": "^4.2.14",
"svelte-check": "^3.6.9",
"svelte-preprocess": "^5.1.3",
"tslib": "^2.6.2",
"typescript": "^5.4.5"
"@types/react": "^18.2.66",
"@types/react-dom": "^18.2.22",
"@types/vscode-webview": "^1.57.0",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
"@vitejs/plugin-react": "^4.2.1",
"eslint": "^8.57.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.6",
"typescript": "^5.2.2",
"vite": "^5.2.0"
}
}
}
Loading

0 comments on commit 3918f58

Please sign in to comment.