Skip to content

Commit a7d3035

Browse files
committed
feat: initial
1 parent e5c1242 commit a7d3035

22 files changed

+3264
-0
lines changed

.eslintrc.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**@type {import('eslint').Linter.Config} */
2+
// eslint-disable-next-line no-undef
3+
module.exports = {
4+
root: true,
5+
parser: '@typescript-eslint/parser',
6+
plugins: [
7+
'@typescript-eslint',
8+
],
9+
extends: [
10+
'eslint:recommended',
11+
'plugin:@typescript-eslint/recommended',
12+
],
13+
rules: {
14+
'semi': [2, "always"],
15+
'@typescript-eslint/no-unused-vars': 0,
16+
'@typescript-eslint/no-explicit-any': 0,
17+
'@typescript-eslint/explicit-module-boundary-types': 0,
18+
'@typescript-eslint/no-non-null-assertion': 0,
19+
}
20+
};

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.DS_Store
2+
.build
3+
build
4+
web_modules/
5+
node_modules/
6+
.idea/
7+
build/
8+
src/typings/vscode.d.ts
9+
src/typings/vscode.proposed.d.ts

README.md

Whitespace-only changes.

out/commands.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"use strict";
2+
var __importDefault = (this && this.__importDefault) || function (mod) {
3+
return (mod && mod.__esModule) ? mod : { "default": mod };
4+
};
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
exports.registerCommands = void 0;
7+
const hbuilderx_1 = __importDefault(require("hbuilderx"));
8+
function registerCommands(context) {
9+
const { webviewProvider, treeDataProvider } = context.ctx;
10+
context.subscriptions.push(hbuilderx_1.default.commands.registerCommand('codingPlugin.helloWorld', () => {
11+
hbuilderx_1.default.window.showInformationMessage('你好,这是我的第一个插件扩展。');
12+
// webviewProvider.panel.webView.postMessage('hhhhh');
13+
}));
14+
context.subscriptions.push(hbuilderx_1.default.commands.registerCommand('codingPlugin.treeItemClick', function (param) {
15+
hbuilderx_1.default.window.showInformationMessage('选中了TreeItem:' + param[0]);
16+
webviewProvider.update(param[0]);
17+
}));
18+
context.subscriptions.push(hbuilderx_1.default.window.createTreeView('codingPlugin.tree', {
19+
showCollapseAll: true,
20+
treeDataProvider
21+
}));
22+
}
23+
exports.registerCommands = registerCommands;

out/constants/tree.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.treeData = void 0;
4+
exports.treeData = [
5+
{
6+
name: '仓库'
7+
},
8+
{
9+
name: 'Root1',
10+
children: [
11+
{ name: 'child1' },
12+
{ name: 'child2' }
13+
]
14+
},
15+
{
16+
name: 'Root2',
17+
children: [
18+
{ name: 'child3' },
19+
{ name: 'child4' }
20+
]
21+
}
22+
];

out/extension.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"use strict";
2+
var __importDefault = (this && this.__importDefault) || function (mod) {
3+
return (mod && mod.__esModule) ? mod : { "default": mod };
4+
};
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
exports.deactivate = exports.activate = void 0;
7+
const tree_1 = __importDefault(require("./tree"));
8+
const webview_1 = __importDefault(require("./webview"));
9+
const commands_1 = require("./commands");
10+
const tree_2 = require("./constants/tree");
11+
function activate(context) {
12+
const webviewProvider = new webview_1.default();
13+
const treeDataProvider = new tree_1.default(tree_2.treeData);
14+
context.ctx = {
15+
webviewProvider,
16+
treeDataProvider
17+
};
18+
commands_1.registerCommands(context);
19+
}
20+
exports.activate = activate;
21+
function deactivate() {
22+
console.log('plugin deactivate');
23+
}
24+
exports.deactivate = deactivate;

out/tree.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"use strict";
2+
var __importDefault = (this && this.__importDefault) || function (mod) {
3+
return (mod && mod.__esModule) ? mod : { "default": mod };
4+
};
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
const hbuilderx_1 = __importDefault(require("hbuilderx"));
7+
class TreeDataProvider extends hbuilderx_1.default.TreeDataProvider {
8+
constructor(treeData) {
9+
super();
10+
this._treeData = treeData;
11+
}
12+
getChildren(element) {
13+
return new Promise(resolve => {
14+
if (!element) {
15+
resolve(this._treeData);
16+
}
17+
else {
18+
resolve(element.children);
19+
}
20+
});
21+
}
22+
getTreeItem(element) {
23+
return {
24+
label: element.name,
25+
collapsibleState: element.children ? 1 : 0,
26+
command: {
27+
command: element.children ? '' : 'codingPlugin.treeItemClick',
28+
arguments: [
29+
element.name
30+
]
31+
}
32+
};
33+
}
34+
}
35+
exports.default = TreeDataProvider;

out/webview.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"use strict";
2+
var __importDefault = (this && this.__importDefault) || function (mod) {
3+
return (mod && mod.__esModule) ? mod : { "default": mod };
4+
};
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
const hbuilderx_1 = __importDefault(require("hbuilderx"));
7+
const path_1 = __importDefault(require("path"));
8+
class WebviewProvider {
9+
constructor() {
10+
this.panel = this.createPanel();
11+
this.listen();
12+
}
13+
listen() {
14+
this.panel.webView.onDidReceiveMessage((message) => {
15+
console.log('webview receive message => ', message);
16+
});
17+
}
18+
createPanel() {
19+
const webviewPanel = hbuilderx_1.default.window.createWebView('codingPlugin.webview', {
20+
enableScripts: true
21+
});
22+
return webviewPanel;
23+
}
24+
update(itemId) {
25+
const webview = this.panel.webView;
26+
const fileInfo = hbuilderx_1.default.Uri.file(path_1.default.resolve(__dirname, '../out/webviews/main.js'));
27+
webview.html = `
28+
<body>
29+
<div style="max-width:200px;">
30+
<div id='root'></div>
31+
<button onclick="test()">测试</button>
32+
<div>${itemId}</div>
33+
</div>
34+
<script>
35+
window.__TEXT__ = '${itemId}'
36+
function test() {
37+
alert('abc')
38+
39+
window.fetch("https://api.github.com/search/repositories?q=react", {
40+
"method": "GET",
41+
"mode": "cors",
42+
"credentials": "include"
43+
}).then((res) => {
44+
res.json().then(data => alert(JSON.stringify(data.items[0])))
45+
})
46+
}
47+
</script>
48+
<script>
49+
window.addEventListener("message", (msg) => {
50+
console.log('msg 222 => ', msg);
51+
});
52+
</script>
53+
<script src='${fileInfo}'></script>
54+
</body>
55+
`;
56+
}
57+
}
58+
exports.default = WebviewProvider;

out/webviews/main.js

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

package.json

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
"name": "coding-hbuilderx",
3+
"description": "your extension description",
4+
"displayName": "your extension display name",
5+
"version": "0.0.0",
6+
"publisher": "your name",
7+
"engines": {
8+
"HBuilderX": "^2.7.0"
9+
},
10+
"categories": [
11+
"Other"
12+
],
13+
"main": "./out/extension",
14+
"activationEvents": [
15+
"onCommand:codingPlugin.helloWorld",
16+
"onView:codingPlugin.tree",
17+
"onView:codingPlugin.webview"
18+
],
19+
"contributes": {
20+
"commands": [
21+
{
22+
"command": "codingPlugin.helloWorld",
23+
"title": "Hello World"
24+
},
25+
{
26+
"command": "codingPlugin.treeItemClick",
27+
"title": "Click Tree Item"
28+
}
29+
],
30+
"menus": {
31+
"editor/context": [
32+
{
33+
"command": "codingPlugin.helloWorld",
34+
"group": "z_commands",
35+
"when": "editorTextFocus"
36+
},
37+
{
38+
"group": "z_commands"
39+
}
40+
]
41+
},
42+
"viewsContainers": {
43+
"activitybar": [
44+
{
45+
"id": "CODING",
46+
"title": "CODING"
47+
}
48+
],
49+
"rightside": [
50+
{
51+
"id": "WebviewContainerId",
52+
"title": "WEBVIEW"
53+
}
54+
]
55+
},
56+
"views": {
57+
"CODING": [
58+
{
59+
"id": "codingPlugin.tree",
60+
"name": "CODING"
61+
}
62+
],
63+
"WebviewContainerId": [
64+
{
65+
"id": "codingPlugin.webview",
66+
"title": "WEBVIEW"
67+
}
68+
]
69+
}
70+
},
71+
"extensionDependencies": [
72+
"plugin-manager"
73+
],
74+
"scripts": {
75+
"watch": "npm-run-all -p watch:*",
76+
"watch:extension": "tsc --watch -p ./src",
77+
"watch:webviews": "webpack --watch --mode development"
78+
},
79+
"dependencies": {
80+
"react": "^17.0.1",
81+
"react-dom": "^17.0.1"
82+
},
83+
"devDependencies": {
84+
"@types/node": "^14.14.7",
85+
"@types/react": "^16.9.56",
86+
"@types/react-dom": "^16.9.9",
87+
"@typescript-eslint/eslint-plugin": "^4.7.0",
88+
"@typescript-eslint/parser": "^4.7.0",
89+
"css-loader": "^5.0.1",
90+
"eslint": "^7.13.0",
91+
"npm-run-all": "^4.1.5",
92+
"style-loader": "^2.0.0",
93+
"ts-loader": "^8.0.11",
94+
"typescript": "^4.0.5",
95+
"webpack": "^5.4.0",
96+
"webpack-cli": "^4.2.0"
97+
}
98+
}

0 commit comments

Comments
 (0)