@desplega.ai/slack-mock 0.1.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.
- package/README.md +113 -0
- package/dist/body.d.ts +6 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +94 -0
- package/dist/events.d.ts +36 -0
- package/dist/ids.d.ts +8 -0
- package/dist/index-thgwpw70.js +3693 -0
- package/dist/index-v7mbr1cx.js +48 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +17 -0
- package/dist/render/blocks.d.ts +7 -0
- package/dist/render/index.d.ts +25 -0
- package/dist/render/mrkdwn.d.ts +16 -0
- package/dist/screenshot.d.ts +13 -0
- package/dist/screenshot.js +9 -0
- package/dist/server.d.ts +240 -0
- package/dist/socket-mode.d.ts +73 -0
- package/dist/store.d.ts +150 -0
- package/dist/types.d.ts +211 -0
- package/dist/web-api.d.ts +26 -0
- package/package.json +60 -0
- package/src/body.ts +84 -0
- package/src/cli.ts +89 -0
- package/src/events.ts +281 -0
- package/src/ids.ts +29 -0
- package/src/index.ts +13 -0
- package/src/render/blocks.ts +392 -0
- package/src/render/index.ts +846 -0
- package/src/render/mrkdwn.ts +321 -0
- package/src/screenshot.ts +59 -0
- package/src/server.ts +1198 -0
- package/src/socket-mode.ts +261 -0
- package/src/store.ts +654 -0
- package/src/types.ts +159 -0
- package/src/web-api.ts +694 -0
|
@@ -0,0 +1,846 @@
|
|
|
1
|
+
// Server-rendered, Slack-looking HTML for the mock workspace. No client-side
|
|
2
|
+
// JavaScript and no external assets, so a page can be screenshotted by headless
|
|
3
|
+
// Chrome or opened directly in a browser while debugging a test.
|
|
4
|
+
|
|
5
|
+
import type { Store } from "../store.ts";
|
|
6
|
+
import type { SlackChannel, SlackFile, SlackMessage, SlackUser } from "../types.ts";
|
|
7
|
+
import { renderAttachments, renderBlocks } from "./blocks.ts";
|
|
8
|
+
import {
|
|
9
|
+
displayName,
|
|
10
|
+
emojiChar,
|
|
11
|
+
escapeHtml,
|
|
12
|
+
mrkdwnToHtml,
|
|
13
|
+
plainTextToHtml,
|
|
14
|
+
type RenderContext,
|
|
15
|
+
} from "./mrkdwn.ts";
|
|
16
|
+
|
|
17
|
+
export { escapeHtml } from "./mrkdwn.ts";
|
|
18
|
+
|
|
19
|
+
export type View =
|
|
20
|
+
| { kind: "index" }
|
|
21
|
+
| { kind: "channel"; channel: string }
|
|
22
|
+
| { kind: "thread"; channel: string; ts: string };
|
|
23
|
+
|
|
24
|
+
export interface RenderOptions {
|
|
25
|
+
/** Screenshot mode: no navigation chrome, fixed width, no auto-refresh. */
|
|
26
|
+
screenshot?: boolean;
|
|
27
|
+
/** Number of live Socket Mode connections (shown on the index page). */
|
|
28
|
+
connections?: number;
|
|
29
|
+
/** Auto-refresh interval in seconds (omit for none). */
|
|
30
|
+
refreshSec?: number;
|
|
31
|
+
/** CSS width of the thread side panel. Default "50%", never below 360px. */
|
|
32
|
+
panelWidth?: string;
|
|
33
|
+
/** "panel" (default) shows the thread beside the channel, "full" shows it alone. */
|
|
34
|
+
threadView?: "panel" | "full";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const DEFAULT_PANEL_WIDTH = "50%";
|
|
38
|
+
|
|
39
|
+
const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
40
|
+
|
|
41
|
+
const AVATAR_COLORS = [
|
|
42
|
+
"#4a154b",
|
|
43
|
+
"#1264a3",
|
|
44
|
+
"#2eb67d",
|
|
45
|
+
"#e01e5a",
|
|
46
|
+
"#e8912d",
|
|
47
|
+
"#007a5a",
|
|
48
|
+
"#7c3aed",
|
|
49
|
+
"#00a2ac",
|
|
50
|
+
"#df10a5",
|
|
51
|
+
"#3d5afe",
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
const CSS = `
|
|
55
|
+
*{box-sizing:border-box}
|
|
56
|
+
html,body{margin:0;padding:0;height:100%}
|
|
57
|
+
body{font-family:Lato,-apple-system,BlinkMacSystemFont,"Segoe UI",system-ui,Helvetica,Arial,sans-serif;font-size:15px;line-height:1.46668;color:#1d1c1d;background:#fff;-webkit-font-smoothing:antialiased}
|
|
58
|
+
a{color:#1264a3;text-decoration:none}
|
|
59
|
+
a:hover{text-decoration:underline}
|
|
60
|
+
.sm-app{display:flex;height:100vh;overflow:hidden}
|
|
61
|
+
.sm-side{width:230px;flex:none;background:#3f0e40;color:#d9d0d9;padding:16px 0;overflow-y:auto}
|
|
62
|
+
.sm-side-title{color:#fff;font-weight:900;font-size:17px;padding:0 16px 12px;border-bottom:1px solid #522653;margin-bottom:10px}
|
|
63
|
+
.sm-side-team{display:block;font-weight:400;font-size:12px;color:#bda9bd}
|
|
64
|
+
.sm-side-h{font-size:13px;color:#bda9bd;padding:10px 16px 4px}
|
|
65
|
+
.sm-side a{display:block;color:#d9d0d9;padding:3px 16px;font-size:15px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
66
|
+
.sm-side a:hover{background:#522653;color:#fff;text-decoration:none}
|
|
67
|
+
.sm-side a.sm-active,.sm-side a.sm-active:hover{background:#1164a3;color:#fff}
|
|
68
|
+
.sm-side-title a:hover{background:none;text-decoration:underline}
|
|
69
|
+
.sm-main{flex:1;min-width:280px;display:flex;flex-direction:column;overflow:hidden}
|
|
70
|
+
.sm-shot{width:760px;padding:16px;background:#fff}
|
|
71
|
+
.sm-top{border-bottom:1px solid #e8e8e8;padding:12px 20px;display:flex;align-items:baseline;gap:12px;flex:none}
|
|
72
|
+
.sm-top h1{font-size:18px;font-weight:900;margin:0}
|
|
73
|
+
.sm-top .sm-sub{font-size:13px;color:#616061;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
74
|
+
.sm-back{font-size:13px;font-weight:700;color:#616061;flex:none}
|
|
75
|
+
.sm-back:hover{color:#1264a3}
|
|
76
|
+
.sm-page{padding:12px 20px 32px}
|
|
77
|
+
.sm-main .sm-page{flex:1;overflow-y:auto}
|
|
78
|
+
.sm-shot .sm-page{padding:0}
|
|
79
|
+
.sm-shot .sm-top{padding:0 0 10px;margin-bottom:8px}
|
|
80
|
+
|
|
81
|
+
.sm-panel{width:var(--sm-panel-w,50%);min-width:360px;flex:0 1 auto;display:flex;flex-direction:column;border-left:1px solid #e8e8e8;background:#fff;overflow:hidden}
|
|
82
|
+
.sm-panel-top{display:flex;align-items:flex-start;gap:10px;padding:12px 16px;border-bottom:1px solid #e8e8e8;flex:none}
|
|
83
|
+
.sm-panel-heading{flex:1;min-width:0}
|
|
84
|
+
.sm-panel-title{font-size:18px;font-weight:900;margin:0;line-height:22px}
|
|
85
|
+
.sm-panel-sub{font-size:13px;color:#616061}
|
|
86
|
+
.sm-panel-close,.sm-panel-expand{font-size:16px;line-height:22px;color:#616061;padding:0 6px;border-radius:4px;flex:none}
|
|
87
|
+
.sm-panel-close{font-size:20px}
|
|
88
|
+
.sm-panel-close:hover,.sm-panel-expand:hover{background:#f0f0f0;color:#1d1c1d;text-decoration:none}
|
|
89
|
+
.sm-panel-back{display:none;padding:8px 16px;font-size:13px;font-weight:700;border-bottom:1px solid #e8e8e8;flex:none}
|
|
90
|
+
.sm-panel-body{flex:1;overflow-y:auto;padding:12px 16px 32px}
|
|
91
|
+
.sm-resize{width:6px;flex:none;cursor:col-resize;background:#f2f2f2;border-left:1px solid #e8e8e8}
|
|
92
|
+
.sm-resize:hover,.sm-resize.sm-dragging{background:#1264a3;border-left-color:#1264a3}
|
|
93
|
+
.sm-icon-btn{display:inline-block;font-size:16px;line-height:22px;color:#616061;padding:0 6px;border-radius:4px;cursor:pointer}
|
|
94
|
+
.sm-icon-btn:hover{background:#f0f0f0;color:#1d1c1d;text-decoration:none}
|
|
95
|
+
.sm-composer{position:relative;flex:none;border-top:1px solid #e8e8e8;padding:10px 20px 12px;background:#fff}
|
|
96
|
+
.sm-panel .sm-composer{padding:10px 16px 12px}
|
|
97
|
+
.sm-composer-box{border:1px solid #bbb;border-radius:8px;padding:8px 10px;background:#fff}
|
|
98
|
+
.sm-composer-box:focus-within{border-color:#1264a3;box-shadow:0 0 0 1px #1264a3}
|
|
99
|
+
.sm-composer-row{display:flex;align-items:center;gap:8px;margin-top:6px}
|
|
100
|
+
.sm-composer-user{flex:0 1 auto;min-width:0;max-width:170px;border:0;border-radius:4px;background:#f0f0f0;color:#1d1c1d;font-family:inherit;font-size:12px;padding:4px 6px}
|
|
101
|
+
.sm-composer-user:hover{background:#e8e8e8}
|
|
102
|
+
.sm-composer-text{display:block;width:100%;border:0;outline:none;resize:vertical;font-family:inherit;font-size:15px;line-height:20px;color:#1d1c1d;padding:0;background:none}
|
|
103
|
+
.sm-composer-send{flex:none;margin-left:auto;border:0;border-radius:4px;background:#007a5a;color:#fff;font-family:inherit;font-weight:700;font-size:13px;padding:6px 14px;cursor:pointer}
|
|
104
|
+
.sm-composer-send:hover{background:#148567;color:#fff}
|
|
105
|
+
.sm-composer-hint{font-size:11px;color:#616061;margin-top:4px}
|
|
106
|
+
.sm-mentions{display:none;position:absolute;left:20px;right:20px;bottom:100%;margin-bottom:6px;max-height:260px;overflow-y:auto;background:#fff;border:1px solid #ddd;border-radius:8px;box-shadow:0 4px 16px rgba(0,0,0,.16);z-index:5}
|
|
107
|
+
.sm-panel .sm-mentions{left:16px;right:16px}
|
|
108
|
+
.sm-mention{display:flex;align-items:center;gap:8px;padding:6px 10px;font-size:14px;cursor:pointer;color:#1d1c1d}
|
|
109
|
+
.sm-mention-on{background:#1264a3;color:#fff}
|
|
110
|
+
.sm-mention-on .sm-mention-real{color:#dbe9f5}
|
|
111
|
+
.sm-mention-av{width:20px;height:20px;border-radius:3px;flex:none;display:inline-flex;align-items:center;justify-content:center;color:#fff;font-size:10px;font-weight:700}
|
|
112
|
+
.sm-mention-name{font-weight:700}
|
|
113
|
+
.sm-mention-real{color:#616061;font-size:13px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
114
|
+
|
|
115
|
+
.sm-side a,.sm-btn,.sm-select,.sm-reaction,.sm-file-card,.sm-prompt,.sm-replies,.sm-back,.sm-panel-close,.sm-panel-expand,.sm-composer-send,.sm-composer-user,.sm-top-actions a{cursor:pointer}
|
|
116
|
+
.sm-composer-text{cursor:text}
|
|
117
|
+
.sm-badge,.sm-time,.sm-daydiv,.sm-pill,.sm-emoji-name,.sm-avatar,.sm-name,.sm-composer-hint,.sm-unsupported,.sm-tag,.sm-card{cursor:default}
|
|
118
|
+
.sm-top-actions{margin-left:auto;display:flex;gap:12px;align-items:baseline;flex:none}
|
|
119
|
+
.sm-top-actions a{font-size:13px;font-weight:700;color:#616061}
|
|
120
|
+
.sm-top-actions a:hover{color:#1264a3}
|
|
121
|
+
@media (max-width:900px){
|
|
122
|
+
.sm-side{display:none}
|
|
123
|
+
.sm-app-thread .sm-main{display:none}
|
|
124
|
+
.sm-panel{width:100%;min-width:0;border-left:0}
|
|
125
|
+
.sm-panel-back{display:block}
|
|
126
|
+
.sm-panel-expand,.sm-resize{display:none}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.sm-daydiv{display:flex;align-items:center;gap:10px;margin:14px 0 8px}
|
|
130
|
+
.sm-daydiv:before,.sm-daydiv:after{content:"";flex:1;height:1px;background:#e8e8e8}
|
|
131
|
+
.sm-daydiv span{border:1px solid #e8e8e8;border-radius:12px;padding:2px 12px;font-size:13px;font-weight:700;color:#454245;background:#fff}
|
|
132
|
+
|
|
133
|
+
.sm-msg{display:flex;gap:12px;padding:8px 8px;border-radius:6px}
|
|
134
|
+
.sm-msg:hover{background:#f8f8f8}
|
|
135
|
+
.sm-msg-eph{background:#fffbe6}
|
|
136
|
+
.sm-msg-eph:hover{background:#fff7d1}
|
|
137
|
+
.sm-msg-open,.sm-msg-open:hover{background:#fff8e2;box-shadow:inset 3px 0 0 #ecb22e}
|
|
138
|
+
.sm-avatar{width:36px;height:36px;flex:none;border-radius:4px;display:flex;align-items:center;justify-content:center;color:#fff;font-weight:700;font-size:14px;overflow:hidden}
|
|
139
|
+
.sm-avatar img{width:36px;height:36px;object-fit:cover}
|
|
140
|
+
.sm-avatar-emoji{font-size:20px;background:#f0f0f0}
|
|
141
|
+
.sm-msg-body{min-width:0;flex:1}
|
|
142
|
+
.sm-msg-head{display:flex;align-items:baseline;gap:8px;flex-wrap:wrap;margin-bottom:1px}
|
|
143
|
+
.sm-name{font-weight:700;font-size:15px;color:#1d1c1d}
|
|
144
|
+
.sm-badge{background:#e8e8e8;color:#616061;font-size:10px;font-weight:700;border-radius:2px;padding:1px 4px;letter-spacing:.4px;text-transform:uppercase}
|
|
145
|
+
.sm-time{font-size:12px;color:#616061}
|
|
146
|
+
.sm-text{font-size:15px;line-height:22px;word-wrap:break-word;overflow-wrap:anywhere}
|
|
147
|
+
.sm-edited{font-size:12px;color:#616061}
|
|
148
|
+
.sm-eph-note{font-size:12px;color:#8a6d1a;margin-top:4px}
|
|
149
|
+
.sm-stream{display:inline-block;margin-left:4px;color:#616061;font-weight:700;animation:sm-pulse 1s ease-in-out infinite}
|
|
150
|
+
@keyframes sm-pulse{0%,100%{opacity:.25}50%{opacity:1}}
|
|
151
|
+
|
|
152
|
+
.sm-pill{background:#e8f5fa;color:#1264a3;border-radius:3px;padding:0 2px}
|
|
153
|
+
.sm-link{color:#1264a3}
|
|
154
|
+
.sm-emoji-name{color:#616061}
|
|
155
|
+
.sm-code{font-family:Monaco,Menlo,Consolas,"Courier New",monospace;font-size:12px;background:#f8f8f8;border:1px solid #ddd;border-radius:3px;padding:1px 3px;color:#e01e5a}
|
|
156
|
+
.sm-pre{font-family:Monaco,Menlo,Consolas,"Courier New",monospace;font-size:12px;line-height:18px;background:#f8f8f8;border:1px solid #ddd;border-radius:4px;padding:8px;margin:4px 0;white-space:pre-wrap;word-break:break-word;color:#1d1c1d}
|
|
157
|
+
.sm-quote{border-left:4px solid #ddd;margin:4px 0;padding:0 0 0 12px;color:#1d1c1d}
|
|
158
|
+
.sm-list{margin:2px 0;padding-left:22px}
|
|
159
|
+
.sm-list li{margin:1px 0}
|
|
160
|
+
|
|
161
|
+
.sm-blocks{margin:2px 0}
|
|
162
|
+
.sm-block{margin:6px 0}
|
|
163
|
+
.sm-header-block{font-size:18px;font-weight:900;line-height:24px}
|
|
164
|
+
.sm-section-split{display:flex;gap:12px;align-items:flex-start}
|
|
165
|
+
.sm-section-main{flex:1;min-width:0}
|
|
166
|
+
.sm-section-acc{flex:none}
|
|
167
|
+
.sm-fields{display:flex;flex-wrap:wrap;gap:8px 16px;margin-top:6px}
|
|
168
|
+
.sm-field{flex:1 1 40%;min-width:0;font-size:14px;line-height:20px}
|
|
169
|
+
.sm-field-wide{flex-basis:100%}
|
|
170
|
+
.sm-field-title{font-weight:700}
|
|
171
|
+
.sm-context{display:flex;flex-wrap:wrap;align-items:center;gap:8px;font-size:13px;line-height:18px;color:#616061}
|
|
172
|
+
.sm-context .sm-pre,.sm-context .sm-code{font-size:11px}
|
|
173
|
+
.sm-context-img{width:16px;height:16px;border-radius:2px;object-fit:cover}
|
|
174
|
+
.sm-hr{border:0;border-top:1px solid #ddd;margin:10px 0}
|
|
175
|
+
.sm-actions{display:flex;flex-wrap:wrap;gap:8px;align-items:center}
|
|
176
|
+
.sm-btn{display:inline-block;border:1px solid #bbb;border-radius:4px;padding:6px 12px;font-size:14px;font-weight:700;color:#1d1c1d;background:#fff;line-height:16px}
|
|
177
|
+
.sm-btn:hover{text-decoration:none;background:#f8f8f8;color:#1d1c1d}
|
|
178
|
+
.sm-btn-primary{background:#007a5a;border-color:#007a5a;color:#fff}
|
|
179
|
+
.sm-btn-primary:hover{background:#148567;border-color:#148567;color:#fff}
|
|
180
|
+
.sm-btn-danger{background:#e01e5a;border-color:#e01e5a;color:#fff}
|
|
181
|
+
.sm-btn-danger:hover{background:#c31f4c;border-color:#c31f4c;color:#fff}
|
|
182
|
+
.sm-btn-confirm{margin-left:6px;opacity:.7;font-weight:400}
|
|
183
|
+
.sm-select{display:inline-flex;align-items:center;gap:6px;border:1px solid #bbb;border-radius:4px;padding:6px 10px;font-size:14px;color:#1d1c1d;background:#fff;line-height:16px}
|
|
184
|
+
.sm-select-caret{color:#616061;font-size:12px}
|
|
185
|
+
.sm-options{display:flex;flex-direction:column;gap:4px;font-size:14px}
|
|
186
|
+
.sm-acc-img{max-width:88px;max-height:88px;border-radius:4px;display:block}
|
|
187
|
+
.sm-img{max-width:100%;border-radius:6px;display:block;margin-top:4px}
|
|
188
|
+
.sm-img-title{font-size:13px;font-weight:700;color:#454245}
|
|
189
|
+
.sm-label{font-weight:700;font-size:14px;margin-bottom:4px}
|
|
190
|
+
.sm-hint{font-size:12px;color:#616061;margin-top:4px}
|
|
191
|
+
.sm-input{border:1px solid #bbb;border-radius:4px;padding:8px 10px;font-size:14px;min-height:36px;background:#fff}
|
|
192
|
+
.sm-input-multi{min-height:76px}
|
|
193
|
+
.sm-input-ph{color:#8d8d8e}
|
|
194
|
+
.sm-file-block{font-size:14px;color:#454245}
|
|
195
|
+
.sm-video-thumb{max-width:320px;border-radius:6px;display:block}
|
|
196
|
+
.sm-video-title{font-size:14px;font-weight:700;margin-top:4px}
|
|
197
|
+
.sm-unsupported{display:inline-block;background:#f4f4f4;border:1px solid #ddd;border-radius:4px;padding:4px 8px;font-size:12px;color:#616061;font-family:Monaco,Menlo,monospace}
|
|
198
|
+
.sm-rt-section{margin:2px 0}
|
|
199
|
+
|
|
200
|
+
.sm-atts{margin-top:4px}
|
|
201
|
+
.sm-att{border-left:4px solid #ddd;border-radius:2px;padding:2px 0 2px 12px;margin:6px 0;max-width:600px}
|
|
202
|
+
.sm-att-pretext{font-size:15px;line-height:22px;margin-top:4px}
|
|
203
|
+
.sm-att-author{display:flex;align-items:center;gap:6px;font-size:13px;font-weight:700;color:#454245}
|
|
204
|
+
.sm-att-author-icon{width:16px;height:16px;border-radius:2px}
|
|
205
|
+
.sm-att-title{font-size:15px;font-weight:700;margin:2px 0}
|
|
206
|
+
.sm-att-text{font-size:15px;line-height:21px}
|
|
207
|
+
.sm-att-img{max-width:360px;border-radius:6px;display:block;margin-top:6px}
|
|
208
|
+
.sm-att-thumb{max-width:80px;border-radius:4px;display:block;margin-top:6px}
|
|
209
|
+
.sm-att-footer{display:flex;align-items:center;gap:6px;font-size:12px;color:#616061;margin-top:6px}
|
|
210
|
+
.sm-att-footer-icon{width:14px;height:14px;border-radius:2px}
|
|
211
|
+
|
|
212
|
+
.sm-files{margin-top:6px;display:flex;flex-direction:column;gap:6px;align-items:flex-start}
|
|
213
|
+
.sm-file-img{max-width:480px;max-height:420px;border-radius:8px;border:1px solid #e8e8e8;display:block}
|
|
214
|
+
.sm-file-card{display:flex;gap:10px;align-items:center;border:1px solid #ddd;border-radius:8px;padding:8px 12px;max-width:420px}
|
|
215
|
+
.sm-file-icon{font-size:20px}
|
|
216
|
+
.sm-file-name{font-weight:700;font-size:14px}
|
|
217
|
+
.sm-file-meta{font-size:12px;color:#616061}
|
|
218
|
+
|
|
219
|
+
.sm-reactions{display:flex;flex-wrap:wrap;gap:6px;margin-top:6px}
|
|
220
|
+
.sm-reaction{display:inline-flex;align-items:center;gap:5px;background:#f0f0f0;border:1px solid #f0f0f0;border-radius:12px;padding:1px 8px;font-size:12px;line-height:18px;color:#454245}
|
|
221
|
+
.sm-reaction:hover{background:#e8f5fa;border-color:#1264a3;color:#1d1c1d}
|
|
222
|
+
.sm-reaction-count{font-weight:700;font-size:12px}
|
|
223
|
+
.sm-file-card:hover{background:#f8f8f8}
|
|
224
|
+
|
|
225
|
+
.sm-replies{display:inline-flex;align-items:center;gap:8px;margin-top:4px;font-size:13px;font-weight:700;color:#1264a3}
|
|
226
|
+
.sm-replies:hover{color:#0b4c81}
|
|
227
|
+
.sm-replies-time{font-weight:400;color:#616061}
|
|
228
|
+
.sm-empty{color:#616061;font-size:14px;padding:16px 0}
|
|
229
|
+
|
|
230
|
+
.sm-assist{border:1px solid #e8e8e8;border-radius:8px;padding:10px 12px;margin-bottom:10px;background:#fafafa}
|
|
231
|
+
.sm-assist-title{font-weight:700;font-size:14px}
|
|
232
|
+
.sm-assist-status{font-size:13px;color:#616061;margin-top:2px}
|
|
233
|
+
.sm-assist-status .sm-stream{margin-left:2px}
|
|
234
|
+
.sm-prompts{display:flex;flex-wrap:wrap;gap:8px;margin-top:8px}
|
|
235
|
+
.sm-prompt{border:1px solid #ddd;border-radius:16px;padding:5px 12px;font-size:13px;background:#fff}
|
|
236
|
+
|
|
237
|
+
.sm-cards{display:flex;flex-wrap:wrap;gap:12px;margin-bottom:16px}
|
|
238
|
+
.sm-card{border:1px solid #e8e8e8;border-radius:8px;padding:10px 14px;min-width:150px}
|
|
239
|
+
.sm-card-k{font-size:12px;color:#616061;text-transform:uppercase;letter-spacing:.4px}
|
|
240
|
+
.sm-card-v{font-size:16px;font-weight:700;margin-top:2px}
|
|
241
|
+
.sm-h2{font-size:15px;font-weight:900;margin:18px 0 6px}
|
|
242
|
+
.sm-table{border-collapse:collapse;width:100%;max-width:900px;font-size:14px}
|
|
243
|
+
.sm-table th{text-align:left;font-size:12px;color:#616061;font-weight:700;text-transform:uppercase;letter-spacing:.4px;padding:4px 10px 4px 0;border-bottom:1px solid #e8e8e8}
|
|
244
|
+
.sm-table td{padding:6px 10px 6px 0;border-bottom:1px solid #f2f2f2;vertical-align:top}
|
|
245
|
+
.sm-tag{display:inline-block;background:#f0f0f0;color:#454245;border-radius:10px;padding:0 8px;font-size:11px;font-weight:700}
|
|
246
|
+
.sm-muted{color:#616061}
|
|
247
|
+
`;
|
|
248
|
+
|
|
249
|
+
function ctxOf(store: Store): RenderContext {
|
|
250
|
+
return { users: store.users, channels: store.channels, botUserId: store.bot.userId };
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/** A CSS width the page can trust, or the default. */
|
|
254
|
+
function panelWidth(opts: RenderOptions): string {
|
|
255
|
+
const raw = (opts.panelWidth ?? "").trim();
|
|
256
|
+
return /^\d{1,4}(%|px|vw|rem)$/.test(raw) ? raw : DEFAULT_PANEL_WIDTH;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** The `?panel=` form of a width: "60%" -> "60", "640px" -> "640px". */
|
|
260
|
+
function panelParam(opts: RenderOptions): string {
|
|
261
|
+
const width = (opts.panelWidth ?? "").trim();
|
|
262
|
+
if (!/^\d{1,4}(%|px|vw|rem)$/.test(width) || width === DEFAULT_PANEL_WIDTH) return "";
|
|
263
|
+
return width.endsWith("%") ? width.slice(0, -1) : width;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** Query string for links, carrying screenshot / refresh / panel / full. */
|
|
267
|
+
function query(opts: RenderOptions, over: { full?: boolean } = {}): string {
|
|
268
|
+
if (opts.screenshot) return "?screenshot";
|
|
269
|
+
const parts: string[] = [];
|
|
270
|
+
if (opts.refreshSec) parts.push(`refresh=${opts.refreshSec}`);
|
|
271
|
+
const panel = panelParam(opts);
|
|
272
|
+
if (panel) parts.push(`panel=${panel}`);
|
|
273
|
+
if (over.full ?? opts.threadView === "full") parts.push("full");
|
|
274
|
+
return parts.length ? `?${parts.join("&")}` : "";
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/** Channel pages have no thread, so they never carry `full`. */
|
|
278
|
+
function channelHref(channelId: string, opts: RenderOptions): string {
|
|
279
|
+
return `/c/${encodeURIComponent(channelId)}${query(opts, { full: false })}`;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function homeHref(opts: RenderOptions): string {
|
|
283
|
+
return `/${query(opts, { full: false })}`;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function threadHref(
|
|
287
|
+
channelId: string,
|
|
288
|
+
ts: string,
|
|
289
|
+
opts: RenderOptions,
|
|
290
|
+
over: { full?: boolean } = {},
|
|
291
|
+
): string {
|
|
292
|
+
return `/c/${encodeURIComponent(channelId)}/t/${encodeURIComponent(ts)}${query(opts, over)}`;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function pad(n: number): string {
|
|
296
|
+
return String(n).padStart(2, "0");
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function timeOf(ts: string): string {
|
|
300
|
+
const d = new Date(Number(ts) * 1000);
|
|
301
|
+
if (Number.isNaN(d.getTime())) return "";
|
|
302
|
+
return `${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function dayKey(d: Date): string {
|
|
306
|
+
return `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}`;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function dayLabel(ts: string): string {
|
|
310
|
+
const d = new Date(Number(ts) * 1000);
|
|
311
|
+
if (Number.isNaN(d.getTime())) return "";
|
|
312
|
+
const now = new Date();
|
|
313
|
+
if (dayKey(d) === dayKey(now)) return "Today";
|
|
314
|
+
const yesterday = new Date(now.getTime() - 86_400_000);
|
|
315
|
+
if (dayKey(d) === dayKey(yesterday)) return "Yesterday";
|
|
316
|
+
return `${MONTHS[d.getMonth()]} ${d.getDate()}, ${d.getFullYear()}`;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function fileSize(bytes: number): string {
|
|
320
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
321
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
322
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function hashIndex(s: string, buckets: number): number {
|
|
326
|
+
let h = 0;
|
|
327
|
+
for (let i = 0; i < s.length; i++) h = (h * 31 + s.charCodeAt(i)) >>> 0;
|
|
328
|
+
return h % buckets;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function initials(name: string): string {
|
|
332
|
+
const words = name
|
|
333
|
+
.replace(/[^\p{L}\p{N} ]/gu, " ")
|
|
334
|
+
.trim()
|
|
335
|
+
.split(/\s+/);
|
|
336
|
+
const letters = words
|
|
337
|
+
.slice(0, 2)
|
|
338
|
+
.map((w) => w[0] ?? "")
|
|
339
|
+
.join("");
|
|
340
|
+
return (letters || name.slice(0, 2) || "?").toUpperCase();
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function channelLabel(store: Store, c: SlackChannel): string {
|
|
344
|
+
if (!c.is_im) return `#${c.name}`;
|
|
345
|
+
const peer = c.user ? store.users.get(c.user) : undefined;
|
|
346
|
+
return peer ? displayName(peer) : c.name;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function channelIcon(c: SlackChannel): string {
|
|
350
|
+
if (c.is_im) return "@";
|
|
351
|
+
if (c.is_private) return "🔒";
|
|
352
|
+
return "#";
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function channelKind(c: SlackChannel): string {
|
|
356
|
+
if (c.is_im) return "DM";
|
|
357
|
+
if (c.is_private) return "private";
|
|
358
|
+
return "public";
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// ------------------------------------------------------------------ message
|
|
362
|
+
|
|
363
|
+
function authorName(store: Store, m: SlackMessage): string {
|
|
364
|
+
if (m.username) return m.username;
|
|
365
|
+
const user = m.user ? store.users.get(m.user) : undefined;
|
|
366
|
+
if (user) return user.real_name || user.name;
|
|
367
|
+
return m.bot_profile?.name ?? m.user ?? "unknown";
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
function avatarHtml(m: SlackMessage, name: string): string {
|
|
371
|
+
const emojiName = m.icons?.emoji;
|
|
372
|
+
if (emojiName) {
|
|
373
|
+
const char = emojiChar(emojiName) ?? emojiName.replace(/:/g, "");
|
|
374
|
+
return `<div class="sm-avatar sm-avatar-emoji">${escapeHtml(char)}</div>`;
|
|
375
|
+
}
|
|
376
|
+
const imageUrl = m.icons?.image_72 ?? m.icons?.image_48 ?? m.icons?.image_64;
|
|
377
|
+
if (imageUrl && /^(https?:\/\/|\/)/.test(imageUrl)) {
|
|
378
|
+
return `<div class="sm-avatar"><img src="${escapeHtml(imageUrl)}" alt=""></div>`;
|
|
379
|
+
}
|
|
380
|
+
const seed = m.user ?? m.bot_id ?? name;
|
|
381
|
+
const color = AVATAR_COLORS[hashIndex(seed, AVATAR_COLORS.length)];
|
|
382
|
+
return `<div class="sm-avatar" style="background:${color}">${escapeHtml(initials(name))}</div>`;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
function reactionsHtml(store: Store, m: SlackMessage): string {
|
|
386
|
+
if (!m.reactions?.length) return "";
|
|
387
|
+
const chips = m.reactions.map((r) => {
|
|
388
|
+
const who = r.users
|
|
389
|
+
.map((id) => {
|
|
390
|
+
const user = store.users.get(id);
|
|
391
|
+
return user ? displayName(user) : id;
|
|
392
|
+
})
|
|
393
|
+
.join(", ");
|
|
394
|
+
const char = emojiChar(r.name) ?? `:${r.name}:`;
|
|
395
|
+
return `<span class="sm-reaction" title="${escapeHtml(who)}">${escapeHtml(char)}<span class="sm-reaction-count">${r.count}</span></span>`;
|
|
396
|
+
});
|
|
397
|
+
return `<div class="sm-reactions">${chips.join("")}</div>`;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/** The mock serves url_private behind a token, so browser requests carry it in the query. */
|
|
401
|
+
function fileUrl(f: SlackFile, token: string): string {
|
|
402
|
+
if (!f.url_private) return "";
|
|
403
|
+
return escapeHtml(`${f.url_private}${f.url_private.includes("?") ? "&" : "?"}t=${token}`);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function filesHtml(files: SlackFile[] | undefined, token: string): string {
|
|
407
|
+
if (!files?.length) return "";
|
|
408
|
+
const cards = files.map((f) => {
|
|
409
|
+
if (f.mimetype?.startsWith("image/") && f.url_private) {
|
|
410
|
+
return `<img class="sm-file-img" src="${fileUrl(f, token)}" alt="${escapeHtml(f.title || f.name)}">`;
|
|
411
|
+
}
|
|
412
|
+
const href = fileUrl(f, token);
|
|
413
|
+
const name = escapeHtml(f.title || f.name);
|
|
414
|
+
const meta = `${escapeHtml(f.pretty_type || f.filetype || "File")} · ${fileSize(f.size ?? 0)}`;
|
|
415
|
+
const label = href ? `<a href="${href}">${name}</a>` : name;
|
|
416
|
+
return `<div class="sm-file-card"><div class="sm-file-icon">📄</div><div><div class="sm-file-name">${label}</div><div class="sm-file-meta">${meta}</div></div></div>`;
|
|
417
|
+
});
|
|
418
|
+
return `<div class="sm-files">${cards.join("")}</div>`;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
interface MessageFlags {
|
|
422
|
+
ephemeral?: boolean;
|
|
423
|
+
threadLink?: boolean;
|
|
424
|
+
/** Date dividers between days (channel view only, like Slack). */
|
|
425
|
+
dividers?: boolean;
|
|
426
|
+
/** ts of the message whose thread is open in the side panel. */
|
|
427
|
+
openTs?: string;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
function renderMessage(
|
|
431
|
+
store: Store,
|
|
432
|
+
ctx: RenderContext,
|
|
433
|
+
m: SlackMessage,
|
|
434
|
+
opts: RenderOptions,
|
|
435
|
+
flags: MessageFlags = {},
|
|
436
|
+
): string {
|
|
437
|
+
const name = authorName(store, m);
|
|
438
|
+
const isApp = Boolean(m.bot_id);
|
|
439
|
+
const blocks = Array.isArray(m.blocks) && m.blocks.length ? m.blocks : undefined;
|
|
440
|
+
const body: string[] = [];
|
|
441
|
+
if (blocks) body.push(renderBlocks(blocks, ctx));
|
|
442
|
+
else if (m.text) body.push(`<div class="sm-text">${mrkdwnToHtml(m.text, ctx)}</div>`);
|
|
443
|
+
if (m.edited) body.push(`<div class="sm-edited">(edited)</div>`);
|
|
444
|
+
if (m.attachments?.length) body.push(renderAttachments(m.attachments, ctx));
|
|
445
|
+
body.push(filesHtml(m.files, store.bot.token));
|
|
446
|
+
body.push(reactionsHtml(store, m));
|
|
447
|
+
if (flags.ephemeral) body.push(`<div class="sm-eph-note">Only visible to you</div>`);
|
|
448
|
+
if (flags.threadLink && m.reply_count) {
|
|
449
|
+
const count = `${m.reply_count} ${m.reply_count === 1 ? "reply" : "replies"}`;
|
|
450
|
+
const last = m.latest_reply
|
|
451
|
+
? `<span class="sm-replies-time">Last reply ${timeOf(m.latest_reply)}</span>`
|
|
452
|
+
: "";
|
|
453
|
+
body.push(
|
|
454
|
+
`<a class="sm-replies" href="${threadHref(m.channel, m.thread_ts ?? m.ts, opts)}">${count}${last}</a>`,
|
|
455
|
+
);
|
|
456
|
+
}
|
|
457
|
+
const streaming =
|
|
458
|
+
m.streaming_state === "in_progress"
|
|
459
|
+
? `<span class="sm-stream" title="streaming">•••</span>`
|
|
460
|
+
: "";
|
|
461
|
+
const open = flags.openTs && flags.openTs === m.ts ? " sm-msg-open" : "";
|
|
462
|
+
return `<div class="sm-msg${flags.ephemeral ? " sm-msg-eph" : ""}${open}">${avatarHtml(m, name)}<div class="sm-msg-body"><div class="sm-msg-head"><span class="sm-name">${escapeHtml(name)}</span>${isApp ? `<span class="sm-badge">APP</span>` : ""}<span class="sm-time">${timeOf(m.ts)}</span>${streaming}</div>${body.join("")}</div></div>`;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
function renderMessageList(
|
|
466
|
+
store: Store,
|
|
467
|
+
ctx: RenderContext,
|
|
468
|
+
messages: Array<SlackMessage & { _ephemeral?: boolean }>,
|
|
469
|
+
opts: RenderOptions,
|
|
470
|
+
flags: MessageFlags = {},
|
|
471
|
+
): string {
|
|
472
|
+
const out: string[] = [];
|
|
473
|
+
let day = "";
|
|
474
|
+
for (const m of messages) {
|
|
475
|
+
const label = flags.dividers === false ? "" : dayLabel(m.ts);
|
|
476
|
+
if (label && label !== day) {
|
|
477
|
+
day = label;
|
|
478
|
+
out.push(`<div class="sm-daydiv"><span>${escapeHtml(label)}</span></div>`);
|
|
479
|
+
}
|
|
480
|
+
out.push(renderMessage(store, ctx, m, opts, { ...flags, ephemeral: m._ephemeral === true }));
|
|
481
|
+
}
|
|
482
|
+
return out.join("");
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
// -------------------------------------------------------------------- shell
|
|
486
|
+
|
|
487
|
+
function sidebar(store: Store, opts: RenderOptions, active?: string): string {
|
|
488
|
+
const channels = [...store.channels.values()].sort((a, b) =>
|
|
489
|
+
channelLabel(store, a).localeCompare(channelLabel(store, b)),
|
|
490
|
+
);
|
|
491
|
+
const links = channels
|
|
492
|
+
.map(
|
|
493
|
+
(c) =>
|
|
494
|
+
`<a class="${c.id === active ? "sm-active" : ""}" href="${channelHref(c.id, opts)}">${escapeHtml(channelIcon(c))} ${escapeHtml(c.is_im ? channelLabel(store, c) : c.name)}</a>`,
|
|
495
|
+
)
|
|
496
|
+
.join("");
|
|
497
|
+
return `<nav class="sm-side"><div class="sm-side-title"><a href="${homeHref(opts)}" style="color:#fff">${escapeHtml(store.team.name)}</a><span class="sm-side-team">${escapeHtml(store.team.id)} · slack-mock</span></div><div class="sm-side-h">Channels</div>${links}</nav>`;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
interface ShellParts {
|
|
501
|
+
title: string;
|
|
502
|
+
header: string;
|
|
503
|
+
main: string;
|
|
504
|
+
/** Channel id to highlight in the sidebar. */
|
|
505
|
+
active?: string;
|
|
506
|
+
/** Thread side panel markup. */
|
|
507
|
+
panel?: string;
|
|
508
|
+
/** Composer pinned under the channel column. */
|
|
509
|
+
footer?: string;
|
|
510
|
+
/** Inline script appended to the body (never in screenshot mode). */
|
|
511
|
+
script?: string;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
function shell(store: Store, opts: RenderOptions, parts: ShellParts): string {
|
|
515
|
+
const refresh =
|
|
516
|
+
opts.refreshSec && !opts.screenshot
|
|
517
|
+
? `<meta http-equiv="refresh" content="${Math.max(1, Math.floor(opts.refreshSec))}">`
|
|
518
|
+
: "";
|
|
519
|
+
const style = opts.screenshot ? "" : ` style="--sm-panel-w:${panelWidth(opts)}"`;
|
|
520
|
+
const head = `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>${escapeHtml(parts.title)}</title>${refresh}<style>${CSS}</style></head>`;
|
|
521
|
+
if (opts.screenshot) {
|
|
522
|
+
return `${head}<body><div class="sm-shot">${parts.header}<div class="sm-page">${parts.main}</div></div></body></html>`;
|
|
523
|
+
}
|
|
524
|
+
const app = `sm-app${parts.panel ? " sm-app-thread" : ""}`;
|
|
525
|
+
const handle = parts.panel
|
|
526
|
+
? `<div class="sm-resize" title="Drag to resize, double-click to reset"></div>`
|
|
527
|
+
: "";
|
|
528
|
+
return `${head}<body${style}><div class="${app}">${sidebar(store, opts, parts.active)}<div class="sm-main">${parts.header}<div class="sm-page sm-scroll">${parts.main}</div>${parts.footer ?? ""}</div>${handle}${parts.panel ?? ""}</div>${parts.script ?? ""}</body></html>`;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
interface BackLink {
|
|
532
|
+
href: string;
|
|
533
|
+
label: string;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
function topbar(title: string, sub: string, back?: BackLink, actions?: string): string {
|
|
537
|
+
const backLink = back
|
|
538
|
+
? `<a class="sm-back" href="${back.href}">${escapeHtml(back.label)}</a>`
|
|
539
|
+
: "";
|
|
540
|
+
const right = actions ? `<div class="sm-top-actions">${actions}</div>` : "";
|
|
541
|
+
return `<div class="sm-top">${backLink}<h1>${title}</h1>${sub ? `<div class="sm-sub">${sub}</div>` : ""}${right}</div>`;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
// -------------------------------------------------------------------- views
|
|
545
|
+
|
|
546
|
+
function indexView(store: Store, opts: RenderOptions): string {
|
|
547
|
+
const cards = [
|
|
548
|
+
["Workspace", escapeHtml(store.team.name)],
|
|
549
|
+
["Team id", escapeHtml(store.team.id)],
|
|
550
|
+
["Bot user", escapeHtml(`${store.app.name} (${store.bot.userId})`)],
|
|
551
|
+
["Connections", String(opts.connections ?? 0)],
|
|
552
|
+
]
|
|
553
|
+
.map(
|
|
554
|
+
([k, v]) =>
|
|
555
|
+
`<div class="sm-card"><div class="sm-card-k">${k}</div><div class="sm-card-v">${v}</div></div>`,
|
|
556
|
+
)
|
|
557
|
+
.join("");
|
|
558
|
+
|
|
559
|
+
const channels = [...store.channels.values()];
|
|
560
|
+
const channelRows = channels
|
|
561
|
+
.map((c) => {
|
|
562
|
+
const count = store.messages.get(c.id)?.length ?? 0;
|
|
563
|
+
return `<tr><td><a href="${channelHref(c.id, opts)}">${escapeHtml(channelIcon(c))} ${escapeHtml(c.is_im ? channelLabel(store, c) : c.name)}</a></td><td><span class="sm-tag">${channelKind(c)}</span></td><td class="sm-muted">${c.id}</td><td>${count}</td></tr>`;
|
|
564
|
+
})
|
|
565
|
+
.join("");
|
|
566
|
+
|
|
567
|
+
const userRows = [...store.users.values()]
|
|
568
|
+
.map(
|
|
569
|
+
(u) =>
|
|
570
|
+
`<tr><td>${escapeHtml(u.name)}</td><td>${escapeHtml(u.real_name)}</td><td class="sm-muted">${escapeHtml(u.profile.email ?? "")}</td><td class="sm-muted">${u.id}</td><td>${u.is_bot ? `<span class="sm-tag">bot</span>` : ""}</td></tr>`,
|
|
571
|
+
)
|
|
572
|
+
.join("");
|
|
573
|
+
|
|
574
|
+
const main = `<div class="sm-cards">${cards}</div>
|
|
575
|
+
<div class="sm-h2">Channels</div>
|
|
576
|
+
${
|
|
577
|
+
channels.length
|
|
578
|
+
? `<table class="sm-table"><tr><th>Name</th><th>Type</th><th>Id</th><th>Messages</th></tr>${channelRows}</table>`
|
|
579
|
+
: `<div class="sm-empty">No channels yet</div>`
|
|
580
|
+
}
|
|
581
|
+
<div class="sm-h2">Users</div>
|
|
582
|
+
<table class="sm-table"><tr><th>Name</th><th>Real name</th><th>Email</th><th>Id</th><th></th></tr>${userRows}</table>`;
|
|
583
|
+
|
|
584
|
+
return shell(store, opts, {
|
|
585
|
+
title: `${store.team.name} · slack-mock`,
|
|
586
|
+
header: topbar(escapeHtml(store.team.name), "slack-mock workspace"),
|
|
587
|
+
main,
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
/** Top-level messages plus this channel's ephemerals, in ts order. */
|
|
592
|
+
function channelMessages(store: Store, channel: SlackChannel) {
|
|
593
|
+
const history = store.history(channel.id, { limit: 1000 }).items;
|
|
594
|
+
const ephemerals = store.ephemerals
|
|
595
|
+
.filter((e) => e.channel === channel.id)
|
|
596
|
+
.map((e) => ({ ...e, _ephemeral: true }));
|
|
597
|
+
return [...history, ...ephemerals].sort((a, b) => Number(a.ts) - Number(b.ts));
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
function channelColumn(
|
|
601
|
+
store: Store,
|
|
602
|
+
ctx: RenderContext,
|
|
603
|
+
opts: RenderOptions,
|
|
604
|
+
channel: SlackChannel,
|
|
605
|
+
openTs?: string,
|
|
606
|
+
): string {
|
|
607
|
+
const messages = channelMessages(store, channel);
|
|
608
|
+
if (!messages.length) return `<div class="sm-empty">No messages yet</div>`;
|
|
609
|
+
return renderMessageList(store, ctx, messages, opts, {
|
|
610
|
+
threadLink: true,
|
|
611
|
+
dividers: true,
|
|
612
|
+
openTs,
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
function channelHeader(store: Store, opts: RenderOptions, channel: SlackChannel): string {
|
|
617
|
+
const sub = [channel.topic.value, channel.purpose.value].filter(Boolean).join(" · ");
|
|
618
|
+
const back = opts.screenshot ? undefined : { href: homeHref(opts), label: "← Workspace" };
|
|
619
|
+
return topbar(escapeHtml(channelLabel(store, channel)), escapeHtml(sub), back);
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
// ---------------------------------------------------------------- composer
|
|
623
|
+
|
|
624
|
+
/** Human users, bots excluded: the composer posts as one of them. */
|
|
625
|
+
function humanUsers(store: Store): SlackUser[] {
|
|
626
|
+
return [...store.users.values()].filter((u) => !u.is_bot && !u.deleted);
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
function composer(
|
|
630
|
+
store: Store,
|
|
631
|
+
opts: RenderOptions,
|
|
632
|
+
channel: SlackChannel,
|
|
633
|
+
threadTs?: string,
|
|
634
|
+
): string {
|
|
635
|
+
if (opts.screenshot) return "";
|
|
636
|
+
const users = humanUsers(store);
|
|
637
|
+
if (!users.length) return "";
|
|
638
|
+
const options = users
|
|
639
|
+
.map(
|
|
640
|
+
(u, i) =>
|
|
641
|
+
`<option value="${escapeHtml(u.id)}"${i === 0 ? " selected" : ""}>${escapeHtml(u.real_name || u.name)}</option>`,
|
|
642
|
+
)
|
|
643
|
+
.join("");
|
|
644
|
+
const placeholder = threadTs ? "Reply in thread" : `Message ${channelLabel(store, channel)}`;
|
|
645
|
+
const thread = threadTs ? ` data-thread="${escapeHtml(threadTs)}"` : "";
|
|
646
|
+
return `<div class="sm-composer" data-channel="${escapeHtml(channel.id)}"${thread}><div class="sm-mentions"></div><div class="sm-composer-box"><textarea class="sm-composer-text" rows="2" placeholder="${escapeHtml(placeholder)}"></textarea><div class="sm-composer-row"><select class="sm-composer-user" aria-label="Post as">${options}</select><button type="button" class="sm-composer-send">Send</button></div></div><div class="sm-composer-hint">Enter to send, Shift+Enter for a new line, @name to mention</div></div>`;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
/** Mention targets for the composer autocomplete: every user, bots included. */
|
|
650
|
+
function mentionData(store: Store): string {
|
|
651
|
+
const users = [...store.users.values()]
|
|
652
|
+
.filter((u) => !u.deleted)
|
|
653
|
+
.map((u) => ({
|
|
654
|
+
name: u.name,
|
|
655
|
+
real: u.real_name || u.name,
|
|
656
|
+
initials: initials(u.real_name || u.name),
|
|
657
|
+
color: AVATAR_COLORS[hashIndex(u.id, AVATAR_COLORS.length)],
|
|
658
|
+
}));
|
|
659
|
+
const json = JSON.stringify(users).replace(/</g, "\\u003c");
|
|
660
|
+
return `<script type="application/json" id="sm-users">${json}</script>`;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* The whole client side: scroll to the newest message, drag the panel edge,
|
|
665
|
+
* send from the composers, mention autocomplete and Escape to close a thread.
|
|
666
|
+
*/
|
|
667
|
+
function uiScript(store: Store, opts: RenderOptions, closeUrl?: string): string {
|
|
668
|
+
const esc = closeUrl
|
|
669
|
+
? `document.addEventListener("keydown",function(e){if(e.key==="Escape"&&!/^(TEXTAREA|INPUT|SELECT)$/.test(document.activeElement&&document.activeElement.tagName||""))location.href=${JSON.stringify(closeUrl)}});`
|
|
670
|
+
: "";
|
|
671
|
+
const body = `(function(){
|
|
672
|
+
var W="sm-panel-w",DEF=${JSON.stringify(panelWidth(opts))},FIXED=${opts.panelWidth ? "true" : "false"};
|
|
673
|
+
function scroll(){document.querySelectorAll(".sm-scroll").forEach(function(el){el.scrollTop=el.scrollHeight})}
|
|
674
|
+
scroll();addEventListener("load",scroll);
|
|
675
|
+
var handle=document.querySelector(".sm-resize");
|
|
676
|
+
if(handle){
|
|
677
|
+
var saved=null;try{saved=localStorage.getItem(W)}catch(e){}
|
|
678
|
+
if(!FIXED&&saved)document.body.style.setProperty("--sm-panel-w",saved);
|
|
679
|
+
var dragging=false;
|
|
680
|
+
handle.addEventListener("mousedown",function(e){dragging=true;handle.classList.add("sm-dragging");e.preventDefault()});
|
|
681
|
+
document.addEventListener("mousemove",function(e){if(!dragging)return;var w=Math.round(Math.min(Math.max(innerWidth-e.clientX,360),Math.max(innerWidth-320,360)));document.body.style.setProperty("--sm-panel-w",w+"px")});
|
|
682
|
+
document.addEventListener("mouseup",function(){if(!dragging)return;dragging=false;handle.classList.remove("sm-dragging");try{localStorage.setItem(W,document.body.style.getPropertyValue("--sm-panel-w"))}catch(e){}});
|
|
683
|
+
handle.addEventListener("dblclick",function(){try{localStorage.removeItem(W)}catch(e){}document.body.style.setProperty("--sm-panel-w",DEF)});
|
|
684
|
+
}
|
|
685
|
+
var raw=document.getElementById("sm-users");
|
|
686
|
+
var PEOPLE=(raw?JSON.parse(raw.textContent||"[]"):[]).concat([{name:"here",real:"Notify everyone online",initials:"@",color:"#616061"},{name:"channel",real:"Notify everyone in the channel",initials:"@",color:"#616061"}]);
|
|
687
|
+
function esc(s){return String(s).replace(/[&<>"]/g,function(c){return c==="&"?"&":c==="<"?"<":c===">"?">":"""})}
|
|
688
|
+
function send(box){var t=box.querySelector(".sm-composer-text"),text=t.value.trim();if(!text)return;var body={channel:box.dataset.channel,user:box.querySelector(".sm-composer-user").value,text:text};if(box.dataset.thread)body.thread_ts=box.dataset.thread;t.disabled=true;fetch("/mock/messages",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(body)}).then(function(){location.reload()}).catch(function(){t.disabled=false})}
|
|
689
|
+
document.querySelectorAll(".sm-composer").forEach(function(box){
|
|
690
|
+
var ta=box.querySelector(".sm-composer-text"),menu=box.querySelector(".sm-mentions"),items=[],active=0;
|
|
691
|
+
function close(){items=[];menu.style.display="none"}
|
|
692
|
+
function prefix(){var m=/(?:^|\\s)@(\\w*)$/.exec(ta.value.slice(0,ta.selectionStart));return m?m[1]:null}
|
|
693
|
+
function paint(){menu.querySelectorAll(".sm-mention").forEach(function(el,i){el.className="sm-mention"+(i===active?" sm-mention-on":"")})}
|
|
694
|
+
function show(){
|
|
695
|
+
var q=prefix();if(q===null)return close();
|
|
696
|
+
var low=q.toLowerCase();
|
|
697
|
+
var list=PEOPLE.filter(function(u){return !low||u.name.toLowerCase().indexOf(low)===0||u.real.toLowerCase().indexOf(low)===0}).slice(0,8);
|
|
698
|
+
if(!list.length)return close();
|
|
699
|
+
items=list;active=0;
|
|
700
|
+
menu.innerHTML=list.map(function(u,i){return '<div class="sm-mention'+(i?"":" sm-mention-on")+'" data-i="'+i+'"><span class="sm-mention-av" style="background:'+esc(u.color)+'">'+esc(u.initials)+'</span><span class="sm-mention-name">@'+esc(u.name)+'</span><span class="sm-mention-real">'+esc(u.real)+'</span></div>'}).join("");
|
|
701
|
+
menu.style.display="block";
|
|
702
|
+
}
|
|
703
|
+
function pick(i){var u=items[i];if(!u)return;var pos=ta.selectionStart,before=ta.value.slice(0,pos).replace(/@\\w*$/,"@"+u.name+" "),after=ta.value.slice(pos);ta.value=before+after;ta.selectionStart=ta.selectionEnd=before.length;close();ta.focus()}
|
|
704
|
+
ta.addEventListener("input",show);
|
|
705
|
+
ta.addEventListener("blur",function(){setTimeout(close,150)});
|
|
706
|
+
menu.addEventListener("mousedown",function(e){var el=e.target.closest(".sm-mention");if(el){e.preventDefault();pick(Number(el.dataset.i))}});
|
|
707
|
+
ta.addEventListener("keydown",function(e){
|
|
708
|
+
if(items.length){
|
|
709
|
+
if(e.key==="ArrowDown"){e.preventDefault();active=(active+1)%items.length;paint();return}
|
|
710
|
+
if(e.key==="ArrowUp"){e.preventDefault();active=(active-1+items.length)%items.length;paint();return}
|
|
711
|
+
if(e.key==="Enter"||e.key==="Tab"){e.preventDefault();pick(active);return}
|
|
712
|
+
if(e.key==="Escape"){e.preventDefault();e.stopPropagation();close();return}
|
|
713
|
+
}
|
|
714
|
+
if(e.key==="Enter"&&!e.shiftKey){e.preventDefault();send(box)}
|
|
715
|
+
});
|
|
716
|
+
box.querySelector(".sm-composer-send").addEventListener("click",function(){send(box)});
|
|
717
|
+
});
|
|
718
|
+
})();`;
|
|
719
|
+
return `${mentionData(store)}<script>${body}${esc}</script>`;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
function channelView(store: Store, opts: RenderOptions, channelId: string): string {
|
|
723
|
+
const channel = store.channels.get(channelId);
|
|
724
|
+
const ctx = ctxOf(store);
|
|
725
|
+
if (!channel) return notFound(store, opts, "Channel not found");
|
|
726
|
+
const label = channelLabel(store, channel);
|
|
727
|
+
return shell(store, opts, {
|
|
728
|
+
title: `${label} · slack-mock`,
|
|
729
|
+
header: channelHeader(store, opts, channel),
|
|
730
|
+
main: channelColumn(store, ctx, opts, channel),
|
|
731
|
+
active: channel.id,
|
|
732
|
+
footer: composer(store, opts, channel),
|
|
733
|
+
script: opts.screenshot ? "" : uiScript(store, opts),
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
function assistantPanel(store: Store, channelId: string, ts: string): string {
|
|
738
|
+
const thread = store.assistantThreads.get(`${channelId}:${ts}`);
|
|
739
|
+
if (!thread) return "";
|
|
740
|
+
const parts: string[] = [];
|
|
741
|
+
if (thread.title)
|
|
742
|
+
parts.push(`<div class="sm-assist-title">${plainTextToHtml(thread.title)}</div>`);
|
|
743
|
+
if (thread.status)
|
|
744
|
+
parts.push(
|
|
745
|
+
`<div class="sm-assist-status">${plainTextToHtml(thread.status)}<span class="sm-stream">•••</span></div>`,
|
|
746
|
+
);
|
|
747
|
+
const prompts = Array.isArray(thread.prompts) ? thread.prompts : [];
|
|
748
|
+
if (prompts.length) {
|
|
749
|
+
const chips = prompts
|
|
750
|
+
.map((p) => {
|
|
751
|
+
const prompt = typeof p === "object" && p !== null ? (p as Record<string, unknown>) : {};
|
|
752
|
+
const title = typeof prompt.title === "string" ? prompt.title : "";
|
|
753
|
+
const message = typeof prompt.message === "string" ? prompt.message : "";
|
|
754
|
+
return `<span class="sm-prompt" title="${escapeHtml(message)}">${plainTextToHtml(title || message)}</span>`;
|
|
755
|
+
})
|
|
756
|
+
.join("");
|
|
757
|
+
const heading = thread.promptsTitle
|
|
758
|
+
? `<div class="sm-assist-status">${plainTextToHtml(thread.promptsTitle)}</div>`
|
|
759
|
+
: "";
|
|
760
|
+
parts.push(`${heading}<div class="sm-prompts">${chips}</div>`);
|
|
761
|
+
}
|
|
762
|
+
if (!parts.length) return "";
|
|
763
|
+
return `<div class="sm-assist">${parts.join("")}</div>`;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
function threadView(store: Store, opts: RenderOptions, channelId: string, ts: string): string {
|
|
767
|
+
const channel = store.channels.get(channelId);
|
|
768
|
+
const ctx = ctxOf(store);
|
|
769
|
+
if (!channel) return notFound(store, opts, "Channel not found");
|
|
770
|
+
const parent = store.findMessage(channel.id, ts);
|
|
771
|
+
if (!parent) return notFound(store, opts, "Message not found");
|
|
772
|
+
|
|
773
|
+
const items = store.replies(channel.id, ts, { limit: 1000 }).items;
|
|
774
|
+
const replies = items.slice(1);
|
|
775
|
+
const label = channelLabel(store, channel);
|
|
776
|
+
const repliesBar = replies.length
|
|
777
|
+
? `<div class="sm-daydiv"><span>${replies.length} ${replies.length === 1 ? "reply" : "replies"}</span></div>`
|
|
778
|
+
: `<div class="sm-empty">No replies yet</div>`;
|
|
779
|
+
|
|
780
|
+
const body = `${assistantPanel(store, channel.id, ts)}${renderMessage(store, ctx, parent, opts)}${repliesBar}${renderMessageList(store, ctx, replies, opts, { dividers: false })}`;
|
|
781
|
+
|
|
782
|
+
// Screenshot mode stays thread-only so captures have no surrounding chrome.
|
|
783
|
+
if (opts.screenshot) {
|
|
784
|
+
const header = topbar(
|
|
785
|
+
`Thread <span class="sm-muted">·</span> <a href="${channelHref(channel.id, opts)}">${escapeHtml(label)}</a>`,
|
|
786
|
+
"",
|
|
787
|
+
);
|
|
788
|
+
return shell(store, opts, {
|
|
789
|
+
title: `Thread · ${label}`,
|
|
790
|
+
header,
|
|
791
|
+
main: body,
|
|
792
|
+
active: channel.id,
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
const close = channelHref(channel.id, opts);
|
|
797
|
+
const title = `Thread · ${label}`;
|
|
798
|
+
|
|
799
|
+
if (opts.threadView === "full") {
|
|
800
|
+
const header = topbar(
|
|
801
|
+
`Thread <span class="sm-muted">·</span> ${escapeHtml(label)}`,
|
|
802
|
+
"",
|
|
803
|
+
{ href: close, label: `← ${label}` },
|
|
804
|
+
`<a class="sm-icon-btn" href="${threadHref(channel.id, ts, opts, { full: false })}" title="Collapse to panel" aria-label="Collapse to panel">⤡</a>`,
|
|
805
|
+
);
|
|
806
|
+
return shell(store, opts, {
|
|
807
|
+
title,
|
|
808
|
+
header,
|
|
809
|
+
main: body,
|
|
810
|
+
active: channel.id,
|
|
811
|
+
footer: composer(store, opts, channel, ts),
|
|
812
|
+
script: uiScript(store, opts, close),
|
|
813
|
+
});
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
const expand = threadHref(channel.id, ts, opts, { full: true });
|
|
817
|
+
const panel = `<aside class="sm-panel"><div class="sm-panel-top"><div class="sm-panel-heading"><h2 class="sm-panel-title">Thread</h2><div class="sm-panel-sub">${escapeHtml(label)}</div></div><a class="sm-panel-expand" href="${expand}" title="Expand thread">⤢</a><a class="sm-panel-close" href="${close}" title="Close thread">×</a></div><a class="sm-panel-back" href="${close}">← ${escapeHtml(label)}</a><div class="sm-panel-body sm-scroll">${body}</div>${composer(store, opts, channel, ts)}</aside>`;
|
|
818
|
+
return shell(store, opts, {
|
|
819
|
+
title,
|
|
820
|
+
header: channelHeader(store, opts, channel),
|
|
821
|
+
main: channelColumn(store, ctx, opts, channel, ts),
|
|
822
|
+
active: channel.id,
|
|
823
|
+
panel,
|
|
824
|
+
footer: composer(store, opts, channel),
|
|
825
|
+
script: uiScript(store, opts, close),
|
|
826
|
+
});
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
function notFound(store: Store, opts: RenderOptions, message: string): string {
|
|
830
|
+
return shell(store, opts, {
|
|
831
|
+
title: message,
|
|
832
|
+
header: topbar(escapeHtml(message), ""),
|
|
833
|
+
main: `<div class="sm-empty">${escapeHtml(message)}</div>`,
|
|
834
|
+
});
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
export function renderPage(store: Store, view: View, opts: RenderOptions = {}): string {
|
|
838
|
+
switch (view.kind) {
|
|
839
|
+
case "channel":
|
|
840
|
+
return channelView(store, opts, view.channel);
|
|
841
|
+
case "thread":
|
|
842
|
+
return threadView(store, opts, view.channel, view.ts);
|
|
843
|
+
default:
|
|
844
|
+
return indexView(store, opts);
|
|
845
|
+
}
|
|
846
|
+
}
|