vite-plugin-opencode-assistant 1.0.12 → 1.0.13
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/es/client/index.js +42 -0
- package/lib/client/index.js +42 -0
- package/lib/client.js +1722 -1685
- package/package.json +4 -4
package/es/client/index.js
CHANGED
|
@@ -41,6 +41,24 @@ import { createApp, ref, watch, onMounted, h, computed } from "vue";
|
|
|
41
41
|
import { OpenCodeWidget } from "@vite-plugin-opencode-assistant/components";
|
|
42
42
|
import "@vite-plugin-opencode-assistant/components/style.css";
|
|
43
43
|
import { CONFIG_DATA_ATTR } from "@vite-plugin-opencode-assistant/shared";
|
|
44
|
+
function parseHotkey(hotkeyStr) {
|
|
45
|
+
if (!hotkeyStr) return { ctrl: true, shift: false, alt: false, key: "k" };
|
|
46
|
+
const parts = hotkeyStr.toLowerCase().split("+");
|
|
47
|
+
const key = parts.pop();
|
|
48
|
+
return {
|
|
49
|
+
ctrl: parts.includes("ctrl") || parts.includes("cmd") || parts.includes("meta"),
|
|
50
|
+
shift: parts.includes("shift"),
|
|
51
|
+
alt: parts.includes("alt"),
|
|
52
|
+
key: key || "k"
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function matchHotkey(e, hotkeyConfig) {
|
|
56
|
+
const ctrlMatch = hotkeyConfig.ctrl ? e.ctrlKey || e.metaKey : !(e.ctrlKey || e.metaKey);
|
|
57
|
+
const shiftMatch = hotkeyConfig.shift ? e.shiftKey : !e.shiftKey;
|
|
58
|
+
const altMatch = hotkeyConfig.alt ? e.altKey : !e.altKey;
|
|
59
|
+
const keyMatch = e.key.toLowerCase() === hotkeyConfig.key.toLowerCase();
|
|
60
|
+
return ctrlMatch && shiftMatch && altMatch && keyMatch;
|
|
61
|
+
}
|
|
44
62
|
function utf8ToBase64(str) {
|
|
45
63
|
const bytes = new TextEncoder().encode(str);
|
|
46
64
|
const binString = Array.from(bytes, (byte) => String.fromCodePoint(byte)).join("");
|
|
@@ -250,6 +268,8 @@ const App = {
|
|
|
250
268
|
}
|
|
251
269
|
return false;
|
|
252
270
|
});
|
|
271
|
+
const mainHotkey = parseHotkey(hotkey);
|
|
272
|
+
const selectHotkey = parseHotkey("ctrl+p");
|
|
253
273
|
onMounted(() => {
|
|
254
274
|
if (servicesStarted) {
|
|
255
275
|
loadSessions();
|
|
@@ -279,6 +299,25 @@ const App = {
|
|
|
279
299
|
if (document.head) {
|
|
280
300
|
titleObserver.observe(document.head, { childList: true, subtree: true });
|
|
281
301
|
}
|
|
302
|
+
const handleKeydown = (e) => {
|
|
303
|
+
if (matchHotkey(e, mainHotkey)) {
|
|
304
|
+
e.preventDefault();
|
|
305
|
+
handleToggle(!open.value);
|
|
306
|
+
}
|
|
307
|
+
if (matchHotkey(e, selectHotkey)) {
|
|
308
|
+
e.preventDefault();
|
|
309
|
+
const win = window;
|
|
310
|
+
if (win.__VUE_INSPECTOR__) {
|
|
311
|
+
selectMode.value = !selectMode.value;
|
|
312
|
+
} else {
|
|
313
|
+
showNotification("Vue Inspector \u672A\u52A0\u8F7D\uFF0C\u65E0\u6CD5\u4F7F\u7528\u5143\u7D20\u9009\u62E9\u529F\u80FD");
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
document.addEventListener("keydown", handleKeydown);
|
|
318
|
+
return () => {
|
|
319
|
+
document.removeEventListener("keydown", handleKeydown);
|
|
320
|
+
};
|
|
282
321
|
});
|
|
283
322
|
const handleToggle = (val) => __async(null, null, function* () {
|
|
284
323
|
if (lazy && !servicesStarted && val) {
|
|
@@ -329,6 +368,9 @@ const App = {
|
|
|
329
368
|
"onUpdate:open": handleToggle,
|
|
330
369
|
"onUpdate:selectMode": (val) => {
|
|
331
370
|
selectMode.value = val;
|
|
371
|
+
if (!val && !open.value) {
|
|
372
|
+
open.value = true;
|
|
373
|
+
}
|
|
332
374
|
},
|
|
333
375
|
"onUpdate:sessionListCollapsed": (val) => {
|
|
334
376
|
sessionListCollapsed.value = val;
|
package/lib/client/index.js
CHANGED
|
@@ -41,6 +41,24 @@ var import_vue = require("vue");
|
|
|
41
41
|
var import_components = require("@vite-plugin-opencode-assistant/components");
|
|
42
42
|
var import_style = require("@vite-plugin-opencode-assistant/components/style.css");
|
|
43
43
|
var import_shared = require("@vite-plugin-opencode-assistant/shared");
|
|
44
|
+
function parseHotkey(hotkeyStr) {
|
|
45
|
+
if (!hotkeyStr) return { ctrl: true, shift: false, alt: false, key: "k" };
|
|
46
|
+
const parts = hotkeyStr.toLowerCase().split("+");
|
|
47
|
+
const key = parts.pop();
|
|
48
|
+
return {
|
|
49
|
+
ctrl: parts.includes("ctrl") || parts.includes("cmd") || parts.includes("meta"),
|
|
50
|
+
shift: parts.includes("shift"),
|
|
51
|
+
alt: parts.includes("alt"),
|
|
52
|
+
key: key || "k"
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function matchHotkey(e, hotkeyConfig) {
|
|
56
|
+
const ctrlMatch = hotkeyConfig.ctrl ? e.ctrlKey || e.metaKey : !(e.ctrlKey || e.metaKey);
|
|
57
|
+
const shiftMatch = hotkeyConfig.shift ? e.shiftKey : !e.shiftKey;
|
|
58
|
+
const altMatch = hotkeyConfig.alt ? e.altKey : !e.altKey;
|
|
59
|
+
const keyMatch = e.key.toLowerCase() === hotkeyConfig.key.toLowerCase();
|
|
60
|
+
return ctrlMatch && shiftMatch && altMatch && keyMatch;
|
|
61
|
+
}
|
|
44
62
|
function utf8ToBase64(str) {
|
|
45
63
|
const bytes = new TextEncoder().encode(str);
|
|
46
64
|
const binString = Array.from(bytes, (byte) => String.fromCodePoint(byte)).join("");
|
|
@@ -250,6 +268,8 @@ const App = {
|
|
|
250
268
|
}
|
|
251
269
|
return false;
|
|
252
270
|
});
|
|
271
|
+
const mainHotkey = parseHotkey(hotkey);
|
|
272
|
+
const selectHotkey = parseHotkey("ctrl+p");
|
|
253
273
|
(0, import_vue.onMounted)(() => {
|
|
254
274
|
if (servicesStarted) {
|
|
255
275
|
loadSessions();
|
|
@@ -279,6 +299,25 @@ const App = {
|
|
|
279
299
|
if (document.head) {
|
|
280
300
|
titleObserver.observe(document.head, { childList: true, subtree: true });
|
|
281
301
|
}
|
|
302
|
+
const handleKeydown = (e) => {
|
|
303
|
+
if (matchHotkey(e, mainHotkey)) {
|
|
304
|
+
e.preventDefault();
|
|
305
|
+
handleToggle(!open.value);
|
|
306
|
+
}
|
|
307
|
+
if (matchHotkey(e, selectHotkey)) {
|
|
308
|
+
e.preventDefault();
|
|
309
|
+
const win = window;
|
|
310
|
+
if (win.__VUE_INSPECTOR__) {
|
|
311
|
+
selectMode.value = !selectMode.value;
|
|
312
|
+
} else {
|
|
313
|
+
showNotification("Vue Inspector \u672A\u52A0\u8F7D\uFF0C\u65E0\u6CD5\u4F7F\u7528\u5143\u7D20\u9009\u62E9\u529F\u80FD");
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
document.addEventListener("keydown", handleKeydown);
|
|
318
|
+
return () => {
|
|
319
|
+
document.removeEventListener("keydown", handleKeydown);
|
|
320
|
+
};
|
|
282
321
|
});
|
|
283
322
|
const handleToggle = (val) => __async(null, null, function* () {
|
|
284
323
|
if (lazy && !servicesStarted && val) {
|
|
@@ -329,6 +368,9 @@ const App = {
|
|
|
329
368
|
"onUpdate:open": handleToggle,
|
|
330
369
|
"onUpdate:selectMode": (val) => {
|
|
331
370
|
selectMode.value = val;
|
|
371
|
+
if (!val && !open.value) {
|
|
372
|
+
open.value = true;
|
|
373
|
+
}
|
|
332
374
|
},
|
|
333
375
|
"onUpdate:sessionListCollapsed": (val) => {
|
|
334
376
|
sessionListCollapsed.value = val;
|