@alexsun-top/opencode-chat-room 0.8.3 → 0.8.5
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/CHANGELOG.md +7 -1
- package/README.md +5 -5
- package/README.zh-CN.md +5 -5
- package/cli.ts +1 -1
- package/dist/cli.js +35 -16
- package/package.json +15 -9
- package/packages/chat-room-channeld/README.md +3 -2
- package/packages/chat-room-channeld/src/inbound.ts +3 -6
- package/packages/chat-room-channeld/src/pg/sql.mjs +157 -142
- package/packages/chat-room-channeld/src/pg/sql.mts +175 -0
- package/packages/chat-room-channeld/src/pg/worker.mjs +107 -99
- package/packages/chat-room-channeld/src/pg/worker.mts +166 -0
- package/plugin.ts +1 -1
- package/server/assets/chat/admin-badge.js +1 -1
- package/server/assets/chat/admin.js +16 -10
- package/server/assets/chat/announcements.js +12 -2
- package/server/assets/chat/attachment-store.js +15 -6
- package/server/assets/chat/attachments.js +48 -33
- package/server/assets/chat/chat-background.js +8 -14
- package/server/assets/chat/clipboard.js +2 -1
- package/server/assets/chat/confirm-dialog.js +3 -3
- package/server/assets/chat/copy-action.js +1 -2
- package/server/assets/chat/diagram-viewer.js +7 -9
- package/server/assets/chat/doc-preview.js +19 -12
- package/server/assets/chat/editor.js +87 -61
- package/server/assets/chat/events.js +49 -34
- package/server/assets/chat/files.js +45 -13
- package/server/assets/chat/history-loader.js +5 -3
- package/server/assets/chat/image-zoom.js +21 -17
- package/server/assets/chat/install-prompt.js +10 -9
- package/server/assets/chat/integration-account-schema.js +5 -3
- package/server/assets/chat/integration-editor.js +2 -2
- package/server/assets/chat/integration-values.js +17 -11
- package/server/assets/chat/integrations.js +138 -81
- package/server/assets/chat/join-requests.js +20 -13
- package/server/assets/chat/markdown-footnotes.js +8 -8
- package/server/assets/chat/markdown.js +48 -38
- package/server/assets/chat/members.js +48 -25
- package/server/assets/chat/mentions.js +39 -12
- package/server/assets/chat/message-cache.js +2 -2
- package/server/assets/chat/message-polling.js +40 -21
- package/server/assets/chat/message-window.js +10 -6
- package/server/assets/chat/messages.js +70 -46
- package/server/assets/chat/office-preview.js +3 -3
- package/server/assets/chat/palette.js +45 -29
- package/server/assets/chat/panels.js +19 -1
- package/server/assets/chat/pwa.js +5 -4
- package/server/assets/chat/questions.js +25 -22
- package/server/assets/chat/recall.js +39 -21
- package/server/assets/chat/receipts.js +9 -7
- package/server/assets/chat/reminders.js +25 -8
- package/server/assets/chat/replies.js +34 -15
- package/server/assets/chat/resource-format.js +2 -2
- package/server/assets/chat/room-list.js +2 -2
- package/server/assets/chat/room-watcher.js +8 -4
- package/server/assets/chat/rooms.js +51 -40
- package/server/assets/chat/search.js +8 -6
- package/server/assets/chat/settings.js +16 -14
- package/server/assets/chat/shiki.js +1 -1
- package/server/assets/chat/shortcuts.js +3 -3
- package/server/assets/chat/side-pane.js +4 -3
- package/server/assets/chat/state.js +65 -37
- package/server/assets/chat/system-events.js +6 -5
- package/server/assets/chat/system-messages.js +15 -15
- package/server/assets/chat/task-form.js +5 -5
- package/server/assets/chat/task-row.js +1 -1
- package/server/assets/chat/tasks.js +41 -28
- package/server/assets/chat/window-controls.js +3 -2
- package/server/assets/conversation.css +14 -2
- package/server/assets/doc-preview.css +6 -0
- package/server/assets/office/THIRD-PARTY-NOTICES.txt +23 -1
- package/server/assets/office/licenses/docx-preview-HEADER.txt +6 -0
- package/server/assets/office/licenses/echarts-LICENSE-d3.txt +27 -0
- package/server/assets/office/licenses/echarts-NOTICE.txt +5 -0
- package/server/assets/office/licenses/immediate-LICENSE.txt +20 -0
- package/server/assets/office/licenses/lie-LICENSE.txt +7 -0
- package/server/assets/office/licenses/pako-LICENSE.txt +21 -0
- package/server/assets/office/licenses/pako-ZLIB.txt +18 -0
- package/server/assets/office/licenses/setimmediate-LICENSE.txt +20 -0
- package/server/chat.html +1 -0
- package/server/sw.js +3 -1
- package/skills/chatroom/SKILL.md +9 -0
- package/src/README.md +1 -1
- package/src/agent/agent-receipts.ts +12 -4
- package/src/center/center-client.ts +1 -1
- package/src/state/pg-sql.mjs +157 -142
- package/src/state/pg-sql.mts +175 -0
- package/src/state/pg-worker.mjs +107 -99
- package/src/state/pg-worker.mts +166 -0
- package/src/state/store.ts +21 -7
- package/src/tui/app-types.mjs +1 -0
- package/src/tui/app-types.mts +175 -0
- package/src/tui/app.mjs +426 -423
- package/src/tui/app.mts +500 -0
- package/src/tui/config.mjs +166 -158
- package/src/tui/config.mts +247 -0
- package/src/tui/http.mjs +239 -206
- package/src/tui/http.mts +412 -0
- package/src/tui/i18n.mjs +17 -20
- package/src/tui/i18n.mts +42 -0
- package/src/tui/info-app.mjs +431 -427
- package/src/tui/info-app.mts +500 -0
- package/src/tui/info-content.mjs +205 -199
- package/src/tui/info-content.mts +341 -0
- package/src/tui/join-app.mjs +75 -64
- package/src/tui/join-app.mts +99 -0
- package/src/tui/locales/en.mjs +302 -320
- package/src/tui/locales/en.mts +349 -0
- package/src/tui/locales/zh-CN.mjs +302 -320
- package/src/tui/locales/zh-CN.mts +349 -0
- package/src/tui/main.mjs +219 -213
- package/src/tui/main.mts +255 -0
- package/src/tui/markdown.mjs +128 -272
- package/src/tui/markdown.mts +152 -0
- package/src/tui/mentions.mjs +181 -184
- package/src/tui/mentions.mts +251 -0
- package/src/tui/message-app.mjs +181 -173
- package/src/tui/message-app.mts +213 -0
- package/src/tui/message-view.mjs +90 -111
- package/src/tui/message-view.mts +151 -0
- package/src/tui/messages.mjs +55 -49
- package/src/tui/messages.mts +106 -0
- package/src/tui/palette-app.mjs +364 -344
- package/src/tui/palette-app.mts +388 -0
- package/src/tui/palette.mjs +100 -98
- package/src/tui/palette.mts +176 -0
- package/src/tui/prefs.mjs +56 -63
- package/src/tui/prefs.mts +126 -0
- package/src/tui/reminder-app.mjs +191 -181
- package/src/tui/reminder-app.mts +228 -0
- package/src/tui/room-settings-app.mjs +257 -242
- package/src/tui/room-settings-app.mts +301 -0
- package/src/tui/session.mjs +30 -29
- package/src/tui/session.mts +51 -0
- package/src/tui/settings-app.mjs +151 -138
- package/src/tui/settings-app.mts +179 -0
- package/src/tui/ui-content.mjs +426 -421
- package/src/tui/ui-content.mts +499 -0
- package/src/tui/ui-help.mjs +58 -67
- package/src/tui/ui-help.mts +87 -0
- package/src/tui/ui-mentions.mjs +34 -36
- package/src/tui/ui-mentions.mts +60 -0
- package/src/tui/ui-overlay-view.mjs +259 -267
- package/src/tui/ui-overlay-view.mts +322 -0
- package/src/tui/ui-suggest-view.mjs +54 -57
- package/src/tui/ui-suggest-view.mts +78 -0
- package/src/tui/ui-suggest.mjs +164 -167
- package/src/tui/ui-suggest.mts +248 -0
- package/src/tui/ui-theme.mjs +52 -57
- package/src/tui/ui-theme.mts +98 -0
- package/src/tui/ui-view.mjs +267 -275
- package/src/tui/ui-view.mts +308 -0
- package/src/tui/ui.mjs +372 -359
- package/src/tui/ui.mts +440 -0
- package/src/tui/wire.mjs +215 -0
- package/src/tui/wire.mts +383 -0
package/src/tui/ui.mjs
CHANGED
|
@@ -1,384 +1,397 @@
|
|
|
1
1
|
// OpenTUI controller: keys, focus, theme changes and view syncing.
|
|
2
2
|
// Renderable construction lives in ui-view.mjs, state mapping in ui-content.mjs.
|
|
3
3
|
import { CliRenderEvents } from "@opentui/core";
|
|
4
|
-
import {
|
|
5
|
-
syncComposer,
|
|
6
|
-
syncFocus,
|
|
7
|
-
syncHeader,
|
|
8
|
-
syncLayout,
|
|
9
|
-
syncMessages,
|
|
10
|
-
syncPalette,
|
|
11
|
-
syncRooms,
|
|
12
|
-
syncStatus,
|
|
13
|
-
} from "./ui-content.mjs";
|
|
4
|
+
import { syncComposer, syncFocus, syncHeader, syncLayout, syncMessages, syncPalette, syncRooms, syncStatus, } from "./ui-content.mjs";
|
|
14
5
|
import { createTheme } from "./ui-theme.mjs";
|
|
15
6
|
import { syncHelp } from "./ui-help.mjs";
|
|
16
7
|
import { createView } from "./ui-view.mjs";
|
|
17
8
|
import { handleSuggestKey, syncSuggest } from "./ui-suggest.mjs";
|
|
18
9
|
import { syncMentionHighlights } from "./ui-mentions.mjs";
|
|
19
10
|
import { setLanguage } from "./i18n.mjs";
|
|
20
|
-
|
|
21
11
|
const printable = (key) => {
|
|
22
|
-
|
|
23
|
-
|
|
12
|
+
const char = Array.from(key.sequence ?? "")[0];
|
|
13
|
+
const code = char === undefined ? -1 : char.codePointAt(0) ?? -1;
|
|
14
|
+
return code >= 0x20 && code !== 0x7f;
|
|
24
15
|
};
|
|
25
|
-
|
|
26
16
|
export class Tui {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
this.pendingScrollTo = null;
|
|
43
|
-
this.pendingBottom = false;
|
|
44
|
-
this.pendingRoomScroll = null;
|
|
45
|
-
this.syncingComposer = false;
|
|
46
|
-
this.syncingPalette = false;
|
|
47
|
-
this.paletteInputMode = false;
|
|
48
|
-
this.detailSignature = "";
|
|
49
|
-
this.suggestKind = null;
|
|
50
|
-
this.suggestSnapshot = null;
|
|
51
|
-
this.suggestItems = [];
|
|
52
|
-
this.suggestSelected = 0;
|
|
53
|
-
this.suggestTrigger = null;
|
|
54
|
-
this.suggestQuery = "";
|
|
55
|
-
this.suggestDismissed = null;
|
|
56
|
-
this.mentionStyles = new Map();
|
|
57
|
-
this.mentionSignature = "";
|
|
58
|
-
this.mentionTypeId = null;
|
|
59
|
-
|
|
60
|
-
Object.assign(this, createView(renderer, this.theme));
|
|
61
|
-
this.textarea.onContentChange = () => {
|
|
62
|
-
if (this.syncingComposer) return;
|
|
63
|
-
this.app.setDraft(this.textarea.plainText);
|
|
64
|
-
syncSuggest(this, this.app.state);
|
|
65
|
-
syncMentionHighlights(this, this.app.state);
|
|
66
|
-
this.renderer.requestRender();
|
|
67
|
-
};
|
|
68
|
-
this.paletteInput.onContentChange = () => {
|
|
69
|
-
if (this.syncingPalette) return;
|
|
70
|
-
const palette = this.app.state.palette;
|
|
71
|
-
if (!palette) return;
|
|
72
|
-
if (palette.mode === "prompt") this.app.setPalettePrompt(this.paletteInput.value);
|
|
73
|
-
else this.app.setPaletteQuery(this.paletteInput.value);
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
this.onKey = (key) => this.handleKey(key);
|
|
77
|
-
this.onResize = () => this.sync();
|
|
78
|
-
this.onTheme = (mode) => {
|
|
79
|
-
if (!this.themeState.set(mode)) return;
|
|
80
|
-
this.app.state.theme = this.themeState.mode;
|
|
81
|
-
this.roomSignature = "";
|
|
82
|
-
this.messageSignature = "";
|
|
83
|
-
this.helpSignature = "";
|
|
84
|
-
this.sync();
|
|
85
|
-
};
|
|
86
|
-
this.onFrame = () => {
|
|
87
|
-
let changed = false;
|
|
88
|
-
if (this.pendingRoomScroll) {
|
|
89
|
-
this.roomScroll.scrollChildIntoView(this.pendingRoomScroll);
|
|
90
|
-
this.pendingRoomScroll = null;
|
|
91
|
-
changed = true;
|
|
92
|
-
}
|
|
93
|
-
if (this.pendingScrollTo) {
|
|
94
|
-
this.scrollBox.scrollChildIntoView(this.pendingScrollTo);
|
|
17
|
+
constructor(renderer, app) {
|
|
18
|
+
this.renderer = renderer;
|
|
19
|
+
this.app = app;
|
|
20
|
+
this.themeState = createTheme(renderer, app.state.theme);
|
|
21
|
+
this.theme = this.themeState.theme;
|
|
22
|
+
app.state.theme = this.themeState.mode;
|
|
23
|
+
this.focusKey = null;
|
|
24
|
+
this.roomSignature = "";
|
|
25
|
+
this.messageSignature = "";
|
|
26
|
+
this.helpSignature = "";
|
|
27
|
+
this.syntaxStyles = new Map();
|
|
28
|
+
this.messageBlocks = [];
|
|
29
|
+
this.selectedRoomID = null;
|
|
30
|
+
this.hoverRoomId = null;
|
|
31
|
+
this.roomRows = new Map();
|
|
95
32
|
this.pendingScrollTo = null;
|
|
96
|
-
changed = true;
|
|
97
|
-
} else if (this.pendingBottom) {
|
|
98
33
|
this.pendingBottom = false;
|
|
99
|
-
this.
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
if (key.name === "escape") {
|
|
174
|
-
key.preventDefault();
|
|
175
|
-
this.app.clearOrBlur();
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
if ((key.meta || key.option) && key.name === "home") {
|
|
179
|
-
key.preventDefault();
|
|
180
|
-
this.scrollToStart();
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
if ((key.meta || key.option) && key.name === "end") {
|
|
184
|
-
key.preventDefault();
|
|
185
|
-
this.scrollToEnd();
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
if (key.name === "pageup" || key.name === "pagedown") {
|
|
189
|
-
key.preventDefault();
|
|
190
|
-
this.app.clearHighlight();
|
|
191
|
-
this.scrollBox.scrollBy(key.name === "pageup" ? -0.5 : 0.5, "viewport");
|
|
192
|
-
this.renderer.requestRender();
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
if (state.focus === "composer") {
|
|
197
|
-
if (key.name === "return") {
|
|
198
|
-
key.preventDefault();
|
|
199
|
-
this.app.setDraft(this.textarea.plainText);
|
|
200
|
-
void this.app.send();
|
|
201
|
-
}
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
if (key.name === "up" || key.name === "down") {
|
|
206
|
-
key.preventDefault();
|
|
207
|
-
this.app.moveSelection(key.name === "up" ? -1 : 1);
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
if (key.name === "return") {
|
|
211
|
-
key.preventDefault();
|
|
212
|
-
void this.app.openSelected();
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
if (key.sequence === "?") {
|
|
216
|
-
key.preventDefault();
|
|
217
|
-
this.app.toggleHelp();
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
if (key.sequence === "q") {
|
|
221
|
-
key.preventDefault();
|
|
222
|
-
this.app.quit();
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
if (!key.ctrl && !key.meta && printable(key)) {
|
|
226
|
-
key.preventDefault();
|
|
227
|
-
// Focusing the composer in this handler must not let the same key reach
|
|
228
|
-
// the now-focused textarea twice or split the first character.
|
|
229
|
-
key.stopPropagation();
|
|
230
|
-
this.app.appendDraft(key.sequence);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
handlePaletteKey(key) {
|
|
235
|
-
const palette = this.app.state.palette;
|
|
236
|
-
if (!palette) return;
|
|
237
|
-
if ((key.name === "space" && (key.meta || key.option)) || (key.name === "p" && key.ctrl)) {
|
|
238
|
-
key.preventDefault();
|
|
239
|
-
this.app.closePalette();
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
if (key.name === "escape") {
|
|
243
|
-
key.preventDefault();
|
|
244
|
-
if (palette.mode === "confirm") this.app.cancelConfirm();
|
|
245
|
-
else if (palette.mode === "detail") this.app.backFromDetail();
|
|
246
|
-
else this.app.closePalette();
|
|
247
|
-
return;
|
|
34
|
+
this.pendingRoomScroll = null;
|
|
35
|
+
this.syncingComposer = false;
|
|
36
|
+
this.syncingPalette = false;
|
|
37
|
+
this.paletteInputMode = false;
|
|
38
|
+
this.detailSignature = "";
|
|
39
|
+
this.suggestKind = null;
|
|
40
|
+
this.suggestSnapshot = null;
|
|
41
|
+
this.suggestItems = [];
|
|
42
|
+
this.suggestSelected = 0;
|
|
43
|
+
this.suggestTrigger = null;
|
|
44
|
+
this.suggestQuery = "";
|
|
45
|
+
this.suggestDismissed = null;
|
|
46
|
+
this.mentionStyles = new Map();
|
|
47
|
+
this.mentionSignature = "";
|
|
48
|
+
this.mentionTypeId = null;
|
|
49
|
+
Object.assign(this, createView(renderer, this.theme));
|
|
50
|
+
this.textarea.onContentChange = () => {
|
|
51
|
+
if (this.syncingComposer)
|
|
52
|
+
return;
|
|
53
|
+
this.app.setDraft(this.textarea.plainText);
|
|
54
|
+
syncSuggest(this, this.app.state);
|
|
55
|
+
syncMentionHighlights(this, this.app.state);
|
|
56
|
+
this.renderer.requestRender();
|
|
57
|
+
};
|
|
58
|
+
this.paletteInput.onContentChange = () => {
|
|
59
|
+
if (this.syncingPalette)
|
|
60
|
+
return;
|
|
61
|
+
const palette = this.app.state.palette;
|
|
62
|
+
if (!palette)
|
|
63
|
+
return;
|
|
64
|
+
if (palette.mode === "prompt")
|
|
65
|
+
this.app.setPalettePrompt(this.paletteInput.value);
|
|
66
|
+
else
|
|
67
|
+
this.app.setPaletteQuery(this.paletteInput.value);
|
|
68
|
+
};
|
|
69
|
+
this.onKey = (key) => this.handleKey(key);
|
|
70
|
+
this.onResize = () => this.sync();
|
|
71
|
+
this.onTheme = (mode) => {
|
|
72
|
+
if (!this.themeState.set(mode))
|
|
73
|
+
return;
|
|
74
|
+
this.app.state.theme = this.themeState.mode;
|
|
75
|
+
this.roomSignature = "";
|
|
76
|
+
this.messageSignature = "";
|
|
77
|
+
this.helpSignature = "";
|
|
78
|
+
this.sync();
|
|
79
|
+
};
|
|
80
|
+
this.onFrame = () => {
|
|
81
|
+
let changed = false;
|
|
82
|
+
if (this.pendingRoomScroll) {
|
|
83
|
+
this.roomScroll.scrollChildIntoView(this.pendingRoomScroll);
|
|
84
|
+
this.pendingRoomScroll = null;
|
|
85
|
+
changed = true;
|
|
86
|
+
}
|
|
87
|
+
if (this.pendingScrollTo) {
|
|
88
|
+
this.scrollBox.scrollChildIntoView(this.pendingScrollTo);
|
|
89
|
+
this.pendingScrollTo = null;
|
|
90
|
+
changed = true;
|
|
91
|
+
}
|
|
92
|
+
else if (this.pendingBottom) {
|
|
93
|
+
this.pendingBottom = false;
|
|
94
|
+
this.scrollBox.scrollTop = Math.max(0, this.messageContent.height - this.scrollBox.viewport.height);
|
|
95
|
+
changed = true;
|
|
96
|
+
}
|
|
97
|
+
if (changed)
|
|
98
|
+
this.renderer.requestRender();
|
|
99
|
+
};
|
|
100
|
+
renderer.keyInput.on("keypress", this.onKey);
|
|
101
|
+
renderer.on(CliRenderEvents.RESIZE, this.onResize);
|
|
102
|
+
renderer.on(CliRenderEvents.THEME_MODE, this.onTheme);
|
|
103
|
+
renderer.on(CliRenderEvents.FRAME, this.onFrame);
|
|
104
|
+
this.unsubscribe = app.subscribe(() => this.sync());
|
|
105
|
+
this.sync();
|
|
248
106
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
this.app.cancelConfirm();
|
|
256
|
-
}
|
|
257
|
-
return;
|
|
107
|
+
destroy() {
|
|
108
|
+
this.unsubscribe?.();
|
|
109
|
+
this.renderer.keyInput.off("keypress", this.onKey);
|
|
110
|
+
this.renderer.off(CliRenderEvents.RESIZE, this.onResize);
|
|
111
|
+
this.renderer.off(CliRenderEvents.THEME_MODE, this.onTheme);
|
|
112
|
+
this.renderer.off(CliRenderEvents.FRAME, this.onFrame);
|
|
258
113
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
this.paletteDetailScroll.scrollBy(-0.5, "viewport");
|
|
114
|
+
scrollToStart() {
|
|
115
|
+
this.app.clearHighlight();
|
|
116
|
+
this.scrollBox.scrollTop = 0;
|
|
263
117
|
this.renderer.requestRender();
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
this.
|
|
118
|
+
}
|
|
119
|
+
scrollToEnd() {
|
|
120
|
+
this.app.clearHighlight();
|
|
121
|
+
this.scrollBox.scrollTop = Math.max(0, this.messageContent.height - this.scrollBox.viewport.height);
|
|
267
122
|
this.renderer.requestRender();
|
|
268
|
-
} else if (key.sequence === "d" && palette.kind === "announcements") {
|
|
269
|
-
key.preventDefault();
|
|
270
|
-
this.app.askDeleteAnnouncement(palette.detail?.title);
|
|
271
|
-
} else if (key.sequence === "e" && palette.kind === "settings") {
|
|
272
|
-
key.preventDefault();
|
|
273
|
-
this.app.openSettingsEditor();
|
|
274
|
-
} else if (palette.kind === "room-settings") {
|
|
275
|
-
if (key.sequence === "r") {
|
|
276
|
-
key.preventDefault();
|
|
277
|
-
this.app.startRoomRename();
|
|
278
|
-
} else if (key.sequence === "d") {
|
|
279
|
-
key.preventDefault();
|
|
280
|
-
this.app.startRoomDescription();
|
|
281
|
-
} else if (key.sequence === "j") {
|
|
282
|
-
key.preventDefault();
|
|
283
|
-
this.app.askRoomJoinPolicy();
|
|
284
|
-
} else if (key.sequence === "x") {
|
|
285
|
-
key.preventDefault();
|
|
286
|
-
this.app.askDeleteRoom();
|
|
287
|
-
}
|
|
288
|
-
} else if (key.name === "return") {
|
|
289
|
-
key.preventDefault();
|
|
290
|
-
}
|
|
291
|
-
return;
|
|
292
123
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
this.app.
|
|
297
|
-
|
|
298
|
-
key.
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
if (
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
124
|
+
handleKey(key) {
|
|
125
|
+
if (key.eventType === "release")
|
|
126
|
+
return;
|
|
127
|
+
const state = this.app.state;
|
|
128
|
+
const palette = state.palette;
|
|
129
|
+
if (key.name === "c" && key.ctrl) {
|
|
130
|
+
key.preventDefault();
|
|
131
|
+
this.app.quit();
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (palette) {
|
|
135
|
+
this.handlePaletteKey(key);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (state.focus === "composer" && handleSuggestKey(this, key, state))
|
|
139
|
+
return;
|
|
140
|
+
if ((key.name === "space" && (key.meta || key.option)) || (key.name === "p" && key.ctrl)) {
|
|
141
|
+
key.preventDefault();
|
|
142
|
+
this.app.openPalette();
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (key.name === "r" && key.ctrl) {
|
|
146
|
+
key.preventDefault();
|
|
147
|
+
void this.app.refreshRooms();
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (state.help) {
|
|
151
|
+
if (key.name === "escape" || key.sequence === "?") {
|
|
152
|
+
key.preventDefault();
|
|
153
|
+
this.app.toggleHelp();
|
|
154
|
+
}
|
|
155
|
+
else if (key.name === "tab") {
|
|
156
|
+
key.preventDefault();
|
|
157
|
+
this.app.toggleHelp();
|
|
158
|
+
this.app.toggleFocus();
|
|
159
|
+
}
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (key.name === "tab") {
|
|
163
|
+
key.preventDefault();
|
|
164
|
+
this.app.toggleFocus();
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (key.name === "escape") {
|
|
168
|
+
key.preventDefault();
|
|
169
|
+
this.app.clearOrBlur();
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
if ((key.meta || key.option) && key.name === "home") {
|
|
173
|
+
key.preventDefault();
|
|
174
|
+
this.scrollToStart();
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
if ((key.meta || key.option) && key.name === "end") {
|
|
178
|
+
key.preventDefault();
|
|
179
|
+
this.scrollToEnd();
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
if (key.name === "pageup" || key.name === "pagedown") {
|
|
183
|
+
key.preventDefault();
|
|
184
|
+
this.app.clearHighlight();
|
|
185
|
+
this.scrollBox.scrollBy(key.name === "pageup" ? -0.5 : 0.5, "viewport");
|
|
186
|
+
this.renderer.requestRender();
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (state.focus === "composer") {
|
|
190
|
+
if (key.name === "return") {
|
|
191
|
+
key.preventDefault();
|
|
192
|
+
this.app.setDraft(this.textarea.plainText);
|
|
193
|
+
void this.app.send();
|
|
194
|
+
}
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (key.name === "up" || key.name === "down") {
|
|
198
|
+
key.preventDefault();
|
|
199
|
+
this.app.moveSelection(key.name === "up" ? -1 : 1);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (key.name === "return") {
|
|
203
|
+
key.preventDefault();
|
|
204
|
+
void this.app.openSelected();
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
if (key.sequence === "?") {
|
|
208
|
+
key.preventDefault();
|
|
209
|
+
this.app.toggleHelp();
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
if (key.sequence === "q") {
|
|
213
|
+
key.preventDefault();
|
|
214
|
+
this.app.quit();
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
if (!key.ctrl && !key.meta && printable(key)) {
|
|
218
|
+
key.preventDefault();
|
|
219
|
+
// Focusing the composer in this handler must not let the same key reach
|
|
220
|
+
// the now-focused textarea twice or split the first character.
|
|
221
|
+
key.stopPropagation();
|
|
222
|
+
this.app.appendDraft(key.sequence);
|
|
331
223
|
}
|
|
332
|
-
}
|
|
333
|
-
return;
|
|
334
|
-
}
|
|
335
|
-
if (key.name === "tab") {
|
|
336
|
-
key.preventDefault();
|
|
337
|
-
this.app.togglePaletteScope();
|
|
338
|
-
return;
|
|
339
|
-
}
|
|
340
|
-
if (key.name === "up" || key.name === "down") {
|
|
341
|
-
key.preventDefault();
|
|
342
|
-
this.app.movePalette(key.name === "up" ? -1 : 1);
|
|
343
|
-
return;
|
|
344
|
-
}
|
|
345
|
-
if (key.name === "pageup" || key.name === "pagedown") {
|
|
346
|
-
key.preventDefault();
|
|
347
|
-
this.app.movePalette(key.name === "pageup" ? -5 : 5);
|
|
348
|
-
return;
|
|
349
224
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
225
|
+
handlePaletteKey(key) {
|
|
226
|
+
const palette = this.app.state.palette;
|
|
227
|
+
if (!palette)
|
|
228
|
+
return;
|
|
229
|
+
if ((key.name === "space" && (key.meta || key.option)) || (key.name === "p" && key.ctrl)) {
|
|
230
|
+
key.preventDefault();
|
|
231
|
+
this.app.closePalette();
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
if (key.name === "escape") {
|
|
235
|
+
key.preventDefault();
|
|
236
|
+
if (palette.mode === "confirm")
|
|
237
|
+
this.app.cancelConfirm();
|
|
238
|
+
else if (palette.mode === "detail")
|
|
239
|
+
this.app.backFromDetail();
|
|
240
|
+
else
|
|
241
|
+
this.app.closePalette();
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
if (palette.mode === "confirm") {
|
|
245
|
+
if (key.name === "return" || key.sequence === "y") {
|
|
246
|
+
key.preventDefault();
|
|
247
|
+
void this.app.runConfirm();
|
|
248
|
+
}
|
|
249
|
+
else if (key.sequence === "n") {
|
|
250
|
+
key.preventDefault();
|
|
251
|
+
this.app.cancelConfirm();
|
|
252
|
+
}
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
if (palette.mode === "detail") {
|
|
256
|
+
if (key.name === "up" || key.name === "pageup") {
|
|
257
|
+
key.preventDefault();
|
|
258
|
+
this.paletteDetailScroll.scrollBy(-0.5, "viewport");
|
|
259
|
+
this.renderer.requestRender();
|
|
260
|
+
}
|
|
261
|
+
else if (key.name === "down" || key.name === "pagedown") {
|
|
262
|
+
key.preventDefault();
|
|
263
|
+
this.paletteDetailScroll.scrollBy(0.5, "viewport");
|
|
264
|
+
this.renderer.requestRender();
|
|
265
|
+
}
|
|
266
|
+
else if (key.sequence === "d" && palette.kind === "announcements") {
|
|
267
|
+
key.preventDefault();
|
|
268
|
+
this.app.askDeleteAnnouncement(palette.detail?.title);
|
|
269
|
+
}
|
|
270
|
+
else if (key.sequence === "e" && palette.kind === "settings") {
|
|
271
|
+
key.preventDefault();
|
|
272
|
+
this.app.openSettingsEditor();
|
|
273
|
+
}
|
|
274
|
+
else if (palette.kind === "room-settings") {
|
|
275
|
+
if (key.sequence === "r") {
|
|
276
|
+
key.preventDefault();
|
|
277
|
+
this.app.startRoomRename();
|
|
278
|
+
}
|
|
279
|
+
else if (key.sequence === "d") {
|
|
280
|
+
key.preventDefault();
|
|
281
|
+
this.app.startRoomDescription();
|
|
282
|
+
}
|
|
283
|
+
else if (key.sequence === "j") {
|
|
284
|
+
key.preventDefault();
|
|
285
|
+
this.app.askRoomJoinPolicy();
|
|
286
|
+
}
|
|
287
|
+
else if (key.sequence === "x") {
|
|
288
|
+
key.preventDefault();
|
|
289
|
+
this.app.askDeleteRoom();
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
else if (key.name === "return") {
|
|
293
|
+
key.preventDefault();
|
|
294
|
+
}
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
if (palette.mode === "info") {
|
|
298
|
+
if (key.name === "up" || key.name === "down") {
|
|
299
|
+
key.preventDefault();
|
|
300
|
+
this.app.movePalette(key.name === "up" ? -1 : 1);
|
|
301
|
+
}
|
|
302
|
+
else if (key.name === "pageup" || key.name === "pagedown") {
|
|
303
|
+
key.preventDefault();
|
|
304
|
+
this.app.movePalette(key.name === "pageup" ? -5 : 5);
|
|
305
|
+
}
|
|
306
|
+
else if (key.name === "return") {
|
|
307
|
+
key.preventDefault();
|
|
308
|
+
void this.app.runPaletteSelection();
|
|
309
|
+
}
|
|
310
|
+
else if (key.sequence === "n" && palette.kind === "announcements") {
|
|
311
|
+
key.preventDefault();
|
|
312
|
+
this.app.startAnnouncementCreate();
|
|
313
|
+
}
|
|
314
|
+
else if (key.sequence === "d" && palette.kind === "announcements") {
|
|
315
|
+
key.preventDefault();
|
|
316
|
+
this.app.askDeleteAnnouncement();
|
|
317
|
+
}
|
|
318
|
+
else if (key.sequence === "u" && palette.kind === "files") {
|
|
319
|
+
key.preventDefault();
|
|
320
|
+
this.app.startFileUpload();
|
|
321
|
+
}
|
|
322
|
+
else if (key.sequence === "d" && palette.kind === "files") {
|
|
323
|
+
key.preventDefault();
|
|
324
|
+
this.app.askDeleteFile();
|
|
325
|
+
}
|
|
326
|
+
else if (key.sequence === "d" && palette.kind === "join-requests") {
|
|
327
|
+
key.preventDefault();
|
|
328
|
+
this.app.askJoinDecision("deny");
|
|
329
|
+
}
|
|
330
|
+
else if (palette.kind === "reminders") {
|
|
331
|
+
if (key.sequence === "n") {
|
|
332
|
+
key.preventDefault();
|
|
333
|
+
this.app.startReminderCreate();
|
|
334
|
+
}
|
|
335
|
+
else if (key.sequence === "p") {
|
|
336
|
+
key.preventDefault();
|
|
337
|
+
void this.app.toggleReminder();
|
|
338
|
+
}
|
|
339
|
+
else if (key.sequence === "e") {
|
|
340
|
+
key.preventDefault();
|
|
341
|
+
this.app.startReminderEdit();
|
|
342
|
+
}
|
|
343
|
+
else if (key.sequence === "d") {
|
|
344
|
+
key.preventDefault();
|
|
345
|
+
this.app.askDeleteReminder();
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
if (key.name === "tab") {
|
|
351
|
+
key.preventDefault();
|
|
352
|
+
this.app.togglePaletteScope();
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
if (key.name === "up" || key.name === "down") {
|
|
356
|
+
key.preventDefault();
|
|
357
|
+
this.app.movePalette(key.name === "up" ? -1 : 1);
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
if (key.name === "pageup" || key.name === "pagedown") {
|
|
361
|
+
key.preventDefault();
|
|
362
|
+
this.app.movePalette(key.name === "pageup" ? -5 : 5);
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
if (key.name === "return") {
|
|
366
|
+
key.preventDefault();
|
|
367
|
+
void this.app.runPaletteSelection();
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
// Typing and backspace belong to the focused palette input.
|
|
354
371
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
372
|
+
sync() {
|
|
373
|
+
const state = this.app.state;
|
|
374
|
+
setLanguage(state.language);
|
|
375
|
+
if (state.theme !== this.themeState.mode && this.themeState.set(state.theme)) {
|
|
376
|
+
this.roomSignature = "";
|
|
377
|
+
this.messageSignature = "";
|
|
378
|
+
this.helpSignature = "";
|
|
379
|
+
this.detailSignature = "";
|
|
380
|
+
}
|
|
381
|
+
syncLayout(this);
|
|
382
|
+
syncHeader(this, state);
|
|
383
|
+
syncRooms(this, state);
|
|
384
|
+
syncMessages(this, state);
|
|
385
|
+
syncComposer(this, state);
|
|
386
|
+
syncStatus(this, state);
|
|
387
|
+
this.overlayBackdrop.visible = Boolean(state.palette || state.help);
|
|
388
|
+
syncPalette(this, state);
|
|
389
|
+
syncHelp(this, state);
|
|
390
|
+
syncFocus(this, state);
|
|
391
|
+
syncSuggest(this, state);
|
|
392
|
+
this.renderer.requestRender();
|
|
366
393
|
}
|
|
367
|
-
syncLayout(this);
|
|
368
|
-
syncHeader(this, state);
|
|
369
|
-
syncRooms(this, state);
|
|
370
|
-
syncMessages(this, state);
|
|
371
|
-
syncComposer(this, state);
|
|
372
|
-
syncStatus(this, state);
|
|
373
|
-
this.overlayBackdrop.visible = Boolean(state.palette || state.help);
|
|
374
|
-
syncPalette(this, state);
|
|
375
|
-
syncHelp(this, state);
|
|
376
|
-
syncFocus(this, state);
|
|
377
|
-
syncSuggest(this, state);
|
|
378
|
-
this.renderer.requestRender();
|
|
379
|
-
}
|
|
380
394
|
}
|
|
381
|
-
|
|
382
395
|
export function createTui(renderer, app) {
|
|
383
|
-
|
|
384
|
-
}
|
|
396
|
+
return new Tui(renderer, app);
|
|
397
|
+
}
|