Skip to content

Commit

Permalink
Added webview Vite Reactjs to inventory
Browse files Browse the repository at this point in the history
  • Loading branch information
Fryingpannn committed Oct 12, 2024
1 parent 46fc74b commit 44cecd3
Show file tree
Hide file tree
Showing 20 changed files with 9,975 additions and 529 deletions.
5,053 changes: 5,053 additions & 0 deletions extensions/pearai-inventory/package-lock.json

Large diffs are not rendered by default.

22 changes: 15 additions & 7 deletions extensions/pearai-inventory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@
"commands": [
{
"command": "pearai-inventory.helloWorld",
"title": "Hello World"
"title": "Hello World PearAI Inventory"
}
]
},
"scripts": {
"install:all": "npm install && cd webview-ui && npm install",
"start:webview": "cd webview-ui && npm run start",
"build:webview": "cd webview-ui && npm run build",
"vscode:prepublish": "yarn run package",
"compile": "yarn run check-types && yarn run lint && node esbuild.js",
"watch": "npm-run-all -p watch:*",
"watch": "tsc -watch -p ./",
"watch:esbuild": "node esbuild.js --watch",
"watch:tsc": "tsc --noEmit --watch --project tsconfig.json",
"package": "yarn run check-types && yarn run lint && node esbuild.js --production",
Expand All @@ -34,16 +37,21 @@
"test": "vscode-test"
},
"devDependencies": {
"@types/vscode": "^1.94.0",
"@types/mocha": "^10.0.8",
"@types/node": "20.x",
"@types/vscode": "^1.94.0",
"@typescript-eslint/eslint-plugin": "^8.7.0",
"@typescript-eslint/parser": "^8.7.0",
"eslint": "^9.11.1",
"@vscode/test-cli": "^0.0.10",
"@vscode/test-electron": "^2.4.1",
"esbuild": "^0.24.0",
"eslint": "^9.11.1",
"npm-run-all": "^4.1.5",
"typescript": "^5.6.2",
"@vscode/test-cli": "^0.0.10",
"@vscode/test-electron": "^2.4.1"
"typescript": "^5.6.2"
},
"dependencies": {
"@vscode/webview-ui-toolkit": "^1.4.0",
"nanoid": "^5.0.7",
"react-icons": "^5.3.0"
}
}
78 changes: 51 additions & 27 deletions extensions/pearai-inventory/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,56 @@
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from "vscode";
import { PearInventoryPanel } from "./panels/PearInventoryPanel";
import { commands } from "vscode";

export class PearInventoryExtension {
private outputChannel: vscode.OutputChannel;
private pearInventoryPanel: PearInventoryPanel | null = null;

constructor(
private context: vscode.ExtensionContext,
outputChannel: vscode.OutputChannel,
) {
this.outputChannel = outputChannel;
}

async activate() {
this.outputChannel.appendLine("Pear activation started");

// this.pearInventoryPanel = new PearInventoryPanel(this.context, this.context.extensionUri);

// this.context.subscriptions.push(
// vscode.window.registerWebviewViewProvider("pearai.overlayWebview", this.pearInventoryPanel)
// );

outputChannel.appendLine("Pear Inventory extension activated");
console.log("Pear Inventory extension activated");
}

async deactivate(): Promise<void> {
// await this.pearInventoryPanel?.deactivate();
}
}

let outputChannel: vscode.OutputChannel;
let extension: PearInventoryExtension;

// This method is called when your extension is activated
// Your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {
// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
console.log(
'Congratulations, your extension "pearai-inventory" is now active!',
);

// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
const disposable = vscode.commands.registerCommand(
"pearai-inventory.helloWorld",
() => {
// The code you place here will be executed every time your command is executed
// Display a message box to the user
vscode.window.showInformationMessage(
"PEARAI !!",
);
},
);

context.subscriptions.push(disposable);
console.log("Activating Pear extension");
outputChannel = vscode.window.createOutputChannel("Pear");
outputChannel.appendLine("Activating Pear extension");

// extension = new PearInventoryExtension(context, outputChannel);
// extension.activate();

const showPearInventoryCommand = commands.registerCommand("pearai-inventory.helloWorld", () => {
PearInventoryPanel.render(context.extensionUri);
});

console.log("Activating!");
context.subscriptions.push(showPearInventoryCommand);
}

// This method is called when your extension is deactivated
export function deactivate() {}
export async function deactivate(): Promise<void> {
// await extension.deactivate();
console.log("Pear extension deactivated");
}
6 changes: 4 additions & 2 deletions extensions/pearai-inventory/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"module": "Node16",
"target": "ES2022",
"lib": [
"ES2022"
"ES2022",
"dom"
],
"sourceMap": true,
"rootDir": "src",
Expand All @@ -12,5 +13,6 @@
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
}
},
"exclude" : ["node_modules", "webview-ui"]
}
50 changes: 50 additions & 0 deletions extensions/pearai-inventory/webview-ui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@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 tseslint.config({
languageOptions: {
// other options...
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
},
})
```

- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked`
- Optionally add `...tseslint.configs.stylisticTypeChecked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config:

```js
// eslint.config.js
import react from 'eslint-plugin-react'

export default tseslint.config({
// Set the react version
settings: { react: { version: '18.3' } },
plugins: {
// Add the react plugin
react,
},
rules: {
// other rules...
// Enable its recommended rules
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
},
})
```
28 changes: 28 additions & 0 deletions extensions/pearai-inventory/webview-ui/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'

export default tseslint.config(
{ ignores: ['dist'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
)
13 changes: 13 additions & 0 deletions extensions/pearai-inventory/webview-ui/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
Loading

0 comments on commit 44cecd3

Please sign in to comment.