@tomjs/vite-plugin-vscode 3.1.1 → 3.2.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.
@@ -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();
@@ -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.0",
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
  }