@tomjs/vite-plugin-vscode 3.1.1 → 3.2.1

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/README.md CHANGED
@@ -236,10 +236,12 @@ The `recommended` option is used to set the default configuration and behavior,
236
236
  Inject [@tomjs/vscode-extension-webview](https://github.com/tomjs/vscode-extension-webview) into vscode extension code and web client code, so that `webview` can support `HMR` during the development stage.
237
237
 
238
238
  - vite serve
239
- - extension: Inject `import __getWebviewHtml__ from '@tomjs/vscode-extension-webview';` above the file that calls the `__getWebviewHtml__` method
240
- - web: Add `<script>` tag to index.html and inject `@tomjs/vscode-extension-webview/client` code
239
+ - extension: Inject `import __getWebviewHtml__ from '@tomjs/vite-plugin-vscode/webview';` at the top of the file that calls the `__getWebviewHtml__` method
240
+ - web: Add `<script>` tag to index.html and inject `@tomjs/vite-plugin-vscode/client` code
241
241
  - vite build
242
- - extension: Inject `import __getWebviewHtml__ from '@tomjs/vite-plugin-vscode-inject';` above the file that calls the `__getWebviewHtml__` method If is string, will set inject method name. Default is `__getWebviewHtml__`.
242
+ - extension: Inject `import __getWebviewHtml__ from '@tomjs/vite-plugin-vscode-inject';` at the top of the file that calls the `__getWebviewHtml__` method
243
+
244
+ If is string, will set inject method name. Default is `__getWebviewHtml__`.
243
245
 
244
246
  #### devtools
245
247
 
package/README.zh_CN.md CHANGED
@@ -241,10 +241,12 @@ const value = await acquireVsCodeApi().getState();
241
241
  在 vscode 扩展代码和 web 客户端代码中注入 [@tomjs/vscode-extension-webview](https://github.com/tomjs/vscode-extension-webview),使 `webview` 在开发阶段能够支持 `HMR`。
242
242
 
243
243
  - vite serve
244
- - extension: 在调用 `__getWebviewHtml__` 方法的文件上方注入 `import __getWebviewHtml__ from '@tomjs/vscode-extension-webview';`
244
+ - extension: 在调用 `__getWebviewHtml__` 方法的文件顶部注入 `import __getWebviewHtml__ from '@tomjs/vscode-extension-webview';`
245
245
  - web: 在 index.html 中添加 `<script>` 标签,注入 `@tomjs/vscode-extension-webview/client` 代码
246
246
  - vite build
247
- - extension: 在调用 `__getWebviewHtml__` 方法的文件上方注入 `import __getWebviewHtml__ from '@tomjs/vite-plugin-vscode-inject';` 如果为字符串,则设置注入方法名,默认为 `__getWebviewHtml__`。
247
+ - extension: 在调用 `__getWebviewHtml__` 方法的文件顶部注入 `import __getWebviewHtml__ from '@tomjs/vite-plugin-vscode-inject';`
248
+
249
+ 如果为字符串,则设置注入方法名,默认为 `__getWebviewHtml__`。
248
250
 
249
251
  #### devtools
250
252
 
@@ -72,6 +72,31 @@
72
72
  }
73
73
  patchInitData(data);
74
74
  });
75
+ var KEYBOARD_EVENT_TYPE = "[vscode:client]:commands";
76
+ var isMac = navigator.userAgent.indexOf("Macintosh") >= 0;
77
+ document.addEventListener("keydown", (e) => {
78
+ console.log(e);
79
+ const { metaKey, shiftKey, ctrlKey, altKey, key } = e;
80
+ if (key === "F1") {
81
+ window.parent.postMessage({ type: KEYBOARD_EVENT_TYPE, data: "F1" }, "*");
82
+ } else if (isMac && metaKey && !altKey && !ctrlKey) {
83
+ if (shiftKey) {
84
+ if (key === "z") {
85
+ document.execCommand("redo");
86
+ }
87
+ } else if (key === "a") {
88
+ document.execCommand("selectAll");
89
+ } else if (key === "c") {
90
+ document.execCommand("copy");
91
+ } else if (key === "v") {
92
+ document.execCommand("paste");
93
+ } else if (key === "x") {
94
+ document.execCommand("cut");
95
+ } else if (key === "z") {
96
+ document.execCommand("undo");
97
+ }
98
+ }
99
+ });
75
100
  }
76
101
  });
77
102
  require_client();
package/dist/index.d.mts CHANGED
@@ -54,16 +54,17 @@ interface PluginOptions {
54
54
  */
55
55
  recommended?: boolean;
56
56
  /**
57
- * Inject [@tomjs/vscode-extension-webview](https://github.com/tomjs/vscode-extension-webview) into vscode extension code and web client code, so that webview can support HMR during the development stage.
57
+ * Inject code into vscode extension code and web client code, so that webview can support HMR during the development stage.
58
58
  *
59
59
  * - vite serve
60
- * - extension: Inject `import __getWebviewHtml__ from '@tomjs/vscode-extension-webview';` above the file that calls the `__getWebviewHtml__` method
61
- * - web: Add `<script>` tag to index.html and inject `@tomjs/vscode-extension-webview/client` code
60
+ * - extension: Inject `import __getWebviewHtml__ from '@tomjs/vite-plugin-vscode/webview';` at the top of the file that calls the `__getWebviewHtml__` method
61
+ * - web: Add `<script>` tag to index.html and inject `@tomjs/vite-plugin-vscode/client` code
62
62
  * - vite build
63
- * - extension: Inject `import __getWebviewHtml__ from '@tomjs/vite-plugin-vscode-inject';` above the file that calls the `__getWebviewHtml__` method
63
+ * - extension: Inject `import __getWebviewHtml__ from '@tomjs/vite-plugin-vscode-inject';` at the top of the file that calls the `__getWebviewHtml__` method
64
64
  *
65
65
  * If is string, will set inject method name. Default is '__getWebviewHtml__'.
66
66
  *
67
+ *
67
68
  * @example
68
69
  * extension file
69
70
  * ```ts
package/dist/index.d.ts CHANGED
@@ -54,16 +54,17 @@ interface PluginOptions {
54
54
  */
55
55
  recommended?: boolean;
56
56
  /**
57
- * Inject [@tomjs/vscode-extension-webview](https://github.com/tomjs/vscode-extension-webview) into vscode extension code and web client code, so that webview can support HMR during the development stage.
57
+ * Inject code into vscode extension code and web client code, so that webview can support HMR during the development stage.
58
58
  *
59
59
  * - vite serve
60
- * - extension: Inject `import __getWebviewHtml__ from '@tomjs/vscode-extension-webview';` above the file that calls the `__getWebviewHtml__` method
61
- * - web: Add `<script>` tag to index.html and inject `@tomjs/vscode-extension-webview/client` code
60
+ * - extension: Inject `import __getWebviewHtml__ from '@tomjs/vite-plugin-vscode/webview';` at the top of the file that calls the `__getWebviewHtml__` method
61
+ * - web: Add `<script>` tag to index.html and inject `@tomjs/vite-plugin-vscode/client` code
62
62
  * - vite build
63
- * - extension: Inject `import __getWebviewHtml__ from '@tomjs/vite-plugin-vscode-inject';` above the file that calls the `__getWebviewHtml__` method
63
+ * - extension: Inject `import __getWebviewHtml__ from '@tomjs/vite-plugin-vscode-inject';` at the top of the file that calls the `__getWebviewHtml__` method
64
64
  *
65
65
  * If is string, will set inject method name. Default is '__getWebviewHtml__'.
66
66
  *
67
+ *
67
68
  * @example
68
69
  * extension file
69
70
  * ```ts
@@ -8,6 +8,6 @@ interface WebviewHtmlDevOptions {
8
8
  *
9
9
  * @param options serverUrl string or object options
10
10
  */
11
- declare function getHtml(options: string | WebviewHtmlDevOptions): string;
11
+ declare function getWebviewHtml(options: string | WebviewHtmlDevOptions): string;
12
12
 
13
- export { WebviewHtmlDevOptions, getHtml as default, getHtml };
13
+ export { WebviewHtmlDevOptions, getWebviewHtml as default, getWebviewHtml };
package/dist/webview.d.ts CHANGED
@@ -8,6 +8,6 @@ interface WebviewHtmlDevOptions {
8
8
  *
9
9
  * @param options serverUrl string or object options
10
10
  */
11
- declare function getHtml(options: string | WebviewHtmlDevOptions): string;
11
+ declare function getWebviewHtml(options: string | WebviewHtmlDevOptions): string;
12
12
 
13
- export { WebviewHtmlDevOptions, getHtml as default, getHtml };
13
+ export { WebviewHtmlDevOptions, getWebviewHtml as default, getWebviewHtml };
package/dist/webview.js CHANGED
@@ -102,6 +102,16 @@ var template_default = `<!doctype html>
102
102
  console.log(TAG + ' received:', e.data);
103
103
  if (type === '[vscode:client]:postMessage') {
104
104
  getApi().postMessage(data);
105
+ } else if (type === '[vscode:client]:commands') {
106
+ if (data === 'F1') {
107
+ window.dispatchEvent(
108
+ new KeyboardEvent('keydown', {
109
+ key: 'F1',
110
+ keyCode: 112,
111
+ code: 'F1',
112
+ }),
113
+ );
114
+ }
105
115
  }
106
116
  }
107
117
  }
@@ -179,7 +189,7 @@ var template_default = `<!doctype html>
179
189
  `;
180
190
 
181
191
  // src/webview/webview.ts
182
- function getHtml(options) {
192
+ function getWebviewHtml(options) {
183
193
  const opts = {
184
194
  serverUrl: ""
185
195
  };
@@ -190,8 +200,8 @@ function getHtml(options) {
190
200
  }
191
201
  return template_default.replace(new RegExp("{{serverUrl}}", "g"), opts.serverUrl);
192
202
  }
193
- var webview_default = getHtml;
203
+ var webview_default = getWebviewHtml;
194
204
 
195
205
 
196
206
 
197
- exports.default = webview_default; exports.getHtml = getHtml;
207
+ exports.default = webview_default; exports.getWebviewHtml = getWebviewHtml;
package/dist/webview.mjs CHANGED
@@ -102,6 +102,16 @@ var template_default = `<!doctype html>
102
102
  console.log(TAG + ' received:', e.data);
103
103
  if (type === '[vscode:client]:postMessage') {
104
104
  getApi().postMessage(data);
105
+ } else if (type === '[vscode:client]:commands') {
106
+ if (data === 'F1') {
107
+ window.dispatchEvent(
108
+ new KeyboardEvent('keydown', {
109
+ key: 'F1',
110
+ keyCode: 112,
111
+ code: 'F1',
112
+ }),
113
+ );
114
+ }
105
115
  }
106
116
  }
107
117
  }
@@ -179,7 +189,7 @@ var template_default = `<!doctype html>
179
189
  `;
180
190
 
181
191
  // src/webview/webview.ts
182
- function getHtml(options) {
192
+ function getWebviewHtml(options) {
183
193
  const opts = {
184
194
  serverUrl: ""
185
195
  };
@@ -190,8 +200,8 @@ function getHtml(options) {
190
200
  }
191
201
  return template_default.replace(new RegExp("{{serverUrl}}", "g"), opts.serverUrl);
192
202
  }
193
- var webview_default = getHtml;
203
+ var webview_default = getWebviewHtml;
194
204
  export {
195
205
  webview_default as default,
196
- getHtml
206
+ getWebviewHtml
197
207
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomjs/vite-plugin-vscode",
3
- "version": "3.1.1",
3
+ "version": "3.2.1",
4
4
  "description": "Use vue/react to develop 'vscode extension webview', supporting esm/cjs",
5
5
  "keywords": [
6
6
  "vite",
@@ -100,7 +100,7 @@
100
100
  "build": "pnpm clean && tsup",
101
101
  "clean": "rimraf ./dist",
102
102
  "lint": "run-s lint:eslint lint:stylelint lint:prettier",
103
- "lint:eslint": "eslint \"{src,scripts,examples}/**/*.ts\" *.{js,cjs,ts} --fix --cache",
103
+ "lint:eslint": "eslint \"{src,scripts,examples}/**/*.ts\" *.{cjs,ts} --fix --cache",
104
104
  "lint:stylelint": "stylelint \"examples/**/*.{css,scss,less,vue,html}\" --fix --cache",
105
105
  "lint:prettier": "prettier --write ."
106
106
  }