@tomjs/vite-plugin-vscode 5.0.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.iife.js +74 -74
- package/dist/index.js +6 -9
- package/package.json +22 -21
package/dist/client.iife.js
CHANGED
|
@@ -2,83 +2,83 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
//#region src/webview/client.ts
|
|
5
|
-
if (window.top === window.self) throw new Error("[vscode:client]: must run in vscode webview");
|
|
6
|
-
const TAG = "[@tomjs:vscode:client] ";
|
|
7
|
-
patchAcquireVsCodeApi();
|
|
8
|
-
function onDomReady(callback) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
function patchInitData(data) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
5
|
+
if (window.top === window.self) throw new Error("[vscode:client]: must run in vscode webview");
|
|
6
|
+
const TAG = "[@tomjs:vscode:client] ";
|
|
7
|
+
patchAcquireVsCodeApi();
|
|
8
|
+
function onDomReady(callback) {
|
|
9
|
+
if (document.readyState === "interactive" || document.readyState === "complete") callback();
|
|
10
|
+
else document.addEventListener("DOMContentLoaded", callback);
|
|
11
|
+
}
|
|
12
|
+
function patchInitData(data) {
|
|
13
|
+
onDomReady(() => {
|
|
14
|
+
console.log(TAG, "patch client style");
|
|
15
|
+
const { style, body, root } = data;
|
|
16
|
+
document.documentElement.style.cssText = root.cssText;
|
|
17
|
+
document.body.className = body.className;
|
|
18
|
+
Object.keys(body.dataset).forEach((key) => {
|
|
19
|
+
document.body.dataset[key] = body.dataset[key];
|
|
20
|
+
});
|
|
21
|
+
const defaultStyles = document.createElement("style");
|
|
22
|
+
defaultStyles.id = "_defaultStyles";
|
|
23
|
+
defaultStyles.textContent = style;
|
|
24
|
+
document.head.appendChild(defaultStyles);
|
|
20
25
|
});
|
|
21
|
-
const defaultStyles = document.createElement("style");
|
|
22
|
-
defaultStyles.id = "_defaultStyles";
|
|
23
|
-
defaultStyles.textContent = style;
|
|
24
|
-
document.head.appendChild(defaultStyles);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
const POST_MESSAGE_TYPE = "[vscode:client]:postMessage";
|
|
28
|
-
function patchAcquireVsCodeApi() {
|
|
29
|
-
class AcquireVsCodeApi {
|
|
30
|
-
postMessage(message) {
|
|
31
|
-
console.log(TAG, "mock acquireVsCodeApi.postMessage:", message);
|
|
32
|
-
window.parent.postMessage({
|
|
33
|
-
type: POST_MESSAGE_TYPE,
|
|
34
|
-
data: message
|
|
35
|
-
}, "*");
|
|
36
|
-
}
|
|
37
|
-
getState() {
|
|
38
|
-
console.log(TAG, "mock acquireVsCodeApi.getState");
|
|
39
|
-
const state = sessionStorage.getItem("vscodeState");
|
|
40
|
-
return state ? JSON.parse(state) : void 0;
|
|
41
|
-
}
|
|
42
|
-
setState(newState) {
|
|
43
|
-
console.log(TAG, "mock acquireVsCodeApi.setState:", newState);
|
|
44
|
-
sessionStorage.setItem("vscodeState", JSON.stringify(newState));
|
|
45
|
-
return newState;
|
|
46
|
-
}
|
|
47
26
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
else if (key === "v") document.execCommand("paste");
|
|
78
|
-
else if (key === "x") document.execCommand("cut");
|
|
79
|
-
else if (key === "z") document.execCommand("undo");
|
|
27
|
+
const POST_MESSAGE_TYPE = "[vscode:client]:postMessage";
|
|
28
|
+
function patchAcquireVsCodeApi() {
|
|
29
|
+
class AcquireVsCodeApi {
|
|
30
|
+
postMessage(message) {
|
|
31
|
+
console.log(TAG, "mock acquireVsCodeApi.postMessage:", message);
|
|
32
|
+
window.parent.postMessage({
|
|
33
|
+
type: POST_MESSAGE_TYPE,
|
|
34
|
+
data: message
|
|
35
|
+
}, "*");
|
|
36
|
+
}
|
|
37
|
+
getState() {
|
|
38
|
+
console.log(TAG, "mock acquireVsCodeApi.getState");
|
|
39
|
+
const state = sessionStorage.getItem("vscodeState");
|
|
40
|
+
return state ? JSON.parse(state) : void 0;
|
|
41
|
+
}
|
|
42
|
+
setState(newState) {
|
|
43
|
+
console.log(TAG, "mock acquireVsCodeApi.setState:", newState);
|
|
44
|
+
sessionStorage.setItem("vscodeState", JSON.stringify(newState));
|
|
45
|
+
return newState;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
console.log(TAG, "patch acquireVsCodeApi");
|
|
49
|
+
let api;
|
|
50
|
+
window.acquireVsCodeApi = () => {
|
|
51
|
+
if (!api) {
|
|
52
|
+
api = new AcquireVsCodeApi();
|
|
53
|
+
return api;
|
|
54
|
+
} else return api;
|
|
55
|
+
};
|
|
80
56
|
}
|
|
81
|
-
|
|
57
|
+
const INIT_TYPE = "[vscode:extension]:init";
|
|
58
|
+
window.addEventListener("message", (e) => {
|
|
59
|
+
const { type, data } = e.data || {};
|
|
60
|
+
if (!e.origin.startsWith("vscode-webview://") || type !== INIT_TYPE) return;
|
|
61
|
+
patchInitData(data);
|
|
62
|
+
});
|
|
63
|
+
const KEYBOARD_EVENT_TYPE = "[vscode:client]:commands";
|
|
64
|
+
const isMac = navigator.userAgent.includes("Macintosh");
|
|
65
|
+
document.addEventListener("keydown", (e) => {
|
|
66
|
+
console.log(e);
|
|
67
|
+
const { metaKey, shiftKey, ctrlKey, altKey, key } = e;
|
|
68
|
+
if (key === "F1") window.parent.postMessage({
|
|
69
|
+
type: KEYBOARD_EVENT_TYPE,
|
|
70
|
+
data: "F1"
|
|
71
|
+
}, "*");
|
|
72
|
+
else if (isMac && metaKey && !altKey && !ctrlKey) {
|
|
73
|
+
if (shiftKey) {
|
|
74
|
+
if (key === "z") document.execCommand("redo");
|
|
75
|
+
} else if (key === "a") document.execCommand("selectAll");
|
|
76
|
+
else if (key === "c") document.execCommand("copy");
|
|
77
|
+
else if (key === "v") document.execCommand("paste");
|
|
78
|
+
else if (key === "x") document.execCommand("cut");
|
|
79
|
+
else if (key === "z") document.execCommand("undo");
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
82
|
|
|
83
83
|
//#endregion
|
|
84
84
|
})();
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import { parse } from "node-html-parser";
|
|
|
10
10
|
import { build } from "tsdown";
|
|
11
11
|
import Logger from "@tomjs/logger";
|
|
12
12
|
|
|
13
|
-
//#region node_modules/.pnpm/tsdown@0.
|
|
13
|
+
//#region node_modules/.pnpm/tsdown@0.15.12_publint@0.3.15_typescript@5.8.3_unrun@0.2.14_synckit@0.11.11__vue-tsc@3.1.5_typescript@5.8.3_/node_modules/tsdown/esm-shims.js
|
|
14
14
|
const getFilename = () => fileURLToPath(import.meta.url);
|
|
15
15
|
const getDirname = () => path.dirname(getFilename());
|
|
16
16
|
const __dirname = /* @__PURE__ */ getDirname();
|
|
@@ -60,8 +60,7 @@ function resolveServerUrl(server) {
|
|
|
60
60
|
const protocol = options.https ? "https" : "http";
|
|
61
61
|
const devBase = server.config.base;
|
|
62
62
|
const path$1 = typeof options.open === "string" ? options.open : devBase;
|
|
63
|
-
|
|
64
|
-
return url;
|
|
63
|
+
return path$1.startsWith("http") ? path$1 : `${protocol}://${hostname}:${port}${path$1}`;
|
|
65
64
|
}
|
|
66
65
|
}
|
|
67
66
|
|
|
@@ -142,8 +141,7 @@ function genProdWebviewCode(cache, webview) {
|
|
|
142
141
|
link: "href"
|
|
143
142
|
};
|
|
144
143
|
Object.keys(tags).forEach((tag) => {
|
|
145
|
-
|
|
146
|
-
elements.forEach((element) => {
|
|
144
|
+
root.querySelectorAll(tag).forEach((element) => {
|
|
147
145
|
const attr = element.getAttribute(tags[tag]);
|
|
148
146
|
if (attr) element.setAttribute(tags[tag], `{{baseUri}}${attr}`);
|
|
149
147
|
element.setAttribute("nonce", "{{nonce}}");
|
|
@@ -152,12 +150,11 @@ function genProdWebviewCode(cache, webview) {
|
|
|
152
150
|
}
|
|
153
151
|
return root.removeWhitespace().toString();
|
|
154
152
|
}
|
|
155
|
-
const cacheCode = `const htmlCode = {
|
|
156
|
-
${Object.keys(cache).map((s) => `'${s}': \`${handleHtmlCode(cache[s])}\`,`).join("\n")}
|
|
157
|
-
};`;
|
|
158
153
|
const code = `import { Uri } from 'vscode';
|
|
159
154
|
|
|
160
|
-
${
|
|
155
|
+
${`const htmlCode = {
|
|
156
|
+
${Object.keys(cache).map((s) => `'${s}': \`${handleHtmlCode(cache[s])}\`,`).join("\n")}
|
|
157
|
+
};`}
|
|
161
158
|
|
|
162
159
|
function uuid() {
|
|
163
160
|
let text = '';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tomjs/vite-plugin-vscode",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "5.
|
|
4
|
+
"version": "5.1.0",
|
|
5
5
|
"description": "Use vue/react to develop 'vscode extension webview', supporting esm/cjs",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Tom Gao",
|
|
@@ -54,31 +54,32 @@
|
|
|
54
54
|
"lodash.clonedeep": "^4.5.0",
|
|
55
55
|
"lodash.merge": "^4.6.2",
|
|
56
56
|
"node-html-parser": "^7.0.1",
|
|
57
|
-
"tsdown": "~0.12
|
|
57
|
+
"tsdown": "~0.15.12"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@
|
|
61
|
-
"@
|
|
62
|
-
"@tomjs/
|
|
63
|
-
"@tomjs/
|
|
64
|
-
"@tomjs/
|
|
60
|
+
"@antfu/eslint-config": "^6.2.0",
|
|
61
|
+
"@commitlint/cli": "^20.1.0",
|
|
62
|
+
"@tomjs/commitlint": "^5.0.0",
|
|
63
|
+
"@tomjs/eslint": "^6.0.0",
|
|
64
|
+
"@tomjs/stylelint": "^7.0.0",
|
|
65
|
+
"@tomjs/tsconfig": "^2.1.0",
|
|
65
66
|
"@types/lodash.clonedeep": "^4.5.9",
|
|
66
67
|
"@types/lodash.merge": "^4.6.9",
|
|
67
|
-
"@types/node": "
|
|
68
|
-
"@vitejs/plugin-vue": "^
|
|
69
|
-
"cross-env": "^
|
|
70
|
-
"eslint": "^9.
|
|
71
|
-
"globals": "^16.
|
|
72
|
-
"lint-staged": "^16.
|
|
68
|
+
"@types/node": "20.19.25",
|
|
69
|
+
"@vitejs/plugin-vue": "^6.0.2",
|
|
70
|
+
"cross-env": "^10.1.0",
|
|
71
|
+
"eslint": "^9.39.1",
|
|
72
|
+
"globals": "^16.5.0",
|
|
73
|
+
"lint-staged": "^16.2.7",
|
|
73
74
|
"npm-run-all": "^4.1.5",
|
|
74
|
-
"publint": "^0.3.
|
|
75
|
-
"rimraf": "^6.
|
|
76
|
-
"simple-git-hooks": "^2.13.
|
|
77
|
-
"stylelint": "^16.
|
|
78
|
-
"tsx": "^4.20.
|
|
79
|
-
"typescript": "~5.
|
|
80
|
-
"vite": "^
|
|
81
|
-
"vue-tsc": "^
|
|
75
|
+
"publint": "^0.3.15",
|
|
76
|
+
"rimraf": "^6.1.2",
|
|
77
|
+
"simple-git-hooks": "^2.13.1",
|
|
78
|
+
"stylelint": "^16.26.1",
|
|
79
|
+
"tsx": "^4.20.6",
|
|
80
|
+
"typescript": "~5.8.3",
|
|
81
|
+
"vite": "^7.2.4",
|
|
82
|
+
"vue-tsc": "^3.1.5"
|
|
82
83
|
},
|
|
83
84
|
"scripts": {
|
|
84
85
|
"dev": "pnpm clean && tsdown --watch",
|