@xth26/dsh-plan-build-mode 0.3.0 → 0.3.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/lib/client.js DELETED
@@ -1,141 +0,0 @@
1
- window.__ModuleLoader__.load({ id: "@xth26/dsh-plan-build-mode", factory: (require) => {
2
- var module = { exports: {} }; var exports = module.exports;
3
- "use strict";
4
- /**
5
- * Browser half of `dsh-plan-build-mode`.
6
- *
7
- * Adds a global keyboard shortcut that toggles OpenCode Plan / Build mode by
8
- * executing the host `/plan-build` command against the current session. The
9
- * bundle is a pure listener: it renders nothing and occupies no Slot seat.
10
- *
11
- * The services are consumed through locally declared structural faces rather
12
- * than cross-plugin imports on purpose — a browser bundle must not compile a
13
- * require() edge into the loader module table (bundle purity), and these
14
- * shapes are small and stable. The default combo is kept deliberately complex
15
- * (three modifiers) so it collides with no terminal or browser built-in.
16
- *
17
- * @module dsh-plan-build-mode/client
18
- */
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.inject = exports.name = exports.DEFAULT_SHORTCUT = void 0;
21
- exports.parseShortcutCombo = parseShortcutCombo;
22
- exports.shortcutMatches = shortcutMatches;
23
- exports.resolveCombos = resolveCombos;
24
- exports.apply = apply;
25
- /** Default shortcut; keep in sync with DEFAULT_SHORTCUT in ../helpers.ts. */
26
- exports.DEFAULT_SHORTCUT = 'ctrl+alt+shift+p';
27
- /** Client plugin name. */
28
- exports.name = 'plan-build-mode-client';
29
- /**
30
- * Services required at runtime: the commands Remote for `/plan-build` and the
31
- * session list for the current session id.
32
- */
33
- exports.inject = ['remote', 'remote.commands', 'sessions'];
34
- /**
35
- * Parse a `ctrl+alt+shift+p` style combo. Requires at least one of ctrl/alt
36
- * and exactly one key; returns undefined for malformed or modifier-less
37
- * combos (mirrors the dsh-tui combo grammar).
38
- */
39
- function parseShortcutCombo(raw) {
40
- const parts = String(raw ?? '')
41
- .toLowerCase()
42
- .split('+')
43
- .map(part => part.trim())
44
- .filter(part => part !== '');
45
- if (parts.length < 2)
46
- return undefined;
47
- let ctrl = false;
48
- let alt = false;
49
- let shift = false;
50
- let key;
51
- for (const part of parts) {
52
- if (part === 'ctrl' || part === 'control') {
53
- ctrl = true;
54
- }
55
- else if (part === 'alt' || part === 'meta' || part === 'option') {
56
- alt = true;
57
- }
58
- else if (part === 'shift') {
59
- shift = true;
60
- }
61
- else if (part === 'space') {
62
- if (key !== undefined)
63
- return undefined;
64
- key = ' ';
65
- }
66
- else if ([...part].length === 1) {
67
- if (key !== undefined)
68
- return undefined;
69
- key = part;
70
- }
71
- else {
72
- return undefined;
73
- }
74
- }
75
- if (key === undefined)
76
- return undefined;
77
- if (!ctrl && !alt)
78
- return undefined;
79
- return { ctrl, alt, shift, key };
80
- }
81
- /** Exact modifier + key match against a keydown event. The mac cmd (meta)
82
- * modifier is never part of a spelled combo, so any meta press is a miss. */
83
- function shortcutMatches(combo, event) {
84
- if (event.metaKey)
85
- return false;
86
- if (event.ctrlKey !== combo.ctrl)
87
- return false;
88
- if (event.altKey !== combo.alt)
89
- return false;
90
- if (event.shiftKey !== combo.shift)
91
- return false;
92
- return event.key.toLowerCase() === combo.key;
93
- }
94
- /** Resolve configured combos to parsed form, dropping malformed entries. */
95
- function resolveCombos(configured) {
96
- const raw = configured === undefined
97
- ? [exports.DEFAULT_SHORTCUT]
98
- : typeof configured === 'string'
99
- ? [configured]
100
- : [...configured];
101
- return raw
102
- .map(parseShortcutCombo)
103
- .filter((combo) => combo !== undefined);
104
- }
105
- /**
106
- * Client plugin body: one global keydown listener that runs `/plan-build`
107
- * against the current session. Inert without a current session, during IME
108
- * composition, and on non-matching combos.
109
- * @param ctx - client root context.
110
- * @param config - optional config subset (shortcut combos).
111
- */
112
- function apply(ctx, config = {}) {
113
- const combos = resolveCombos(config.shortcut);
114
- if (combos.length === 0)
115
- return;
116
- ctx.effect(() => {
117
- const onKeyDown = (event) => {
118
- if (event.isComposing)
119
- return;
120
- for (const combo of combos) {
121
- if (!shortcutMatches(combo, event))
122
- continue;
123
- const sessionId = ctx.sessions.list.getSnapshot().current;
124
- if (sessionId === undefined)
125
- return;
126
- event.preventDefault();
127
- void ctx.remote.commands.execute(sessionId, '/plan-build', []).then((result) => {
128
- if (!result.ok && result.error !== undefined) {
129
- console.warn(`[plan-build-mode] shortcut failed (${result.error.code}): ${result.error.message}`);
130
- }
131
- });
132
- return;
133
- }
134
- };
135
- window.addEventListener('keydown', onKeyDown);
136
- return () => {
137
- window.removeEventListener('keydown', onKeyDown);
138
- };
139
- });
140
- }
141
- return module.exports; } });